Skip to content

LessVM Codebase (Run ID: openSVM_lessvm_issue_2_cd25dcd3) #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 10, 2025

Conversation

agentfarmx[bot]
Copy link
Contributor

@agentfarmx agentfarmx bot commented Mar 10, 2025

agent_instance: openSVM_lessvm_issue_2_cd25dcd3 Tries to fix: #2

πŸ› οΈ Fixed SIMD Vector Addition and Enhanced Dynamic Memory Allocation

  • Fixed: Corrected the vector_add implementation to properly add two distinct vectors instead of adding a vector to itself
  • Enhanced: Replaced fixed-size arrays with dynamic Vecs for memory and data structures to support more complex applications
  • Implemented: Added missing opcodes (Mload8/Mstore8, Mod/Exp, SignExtend) and all bitwise operations

The changes improve scalability through dynamic memory management and bring the VM implementation in line with the opcodes specification. Please review these improvements, particularly the SIMD implementation which resolves issue #2.

Summary by Sourcery

Improves the VM implementation by fixing a bug in the SIMD vector addition, enhancing memory management with dynamic Vecs, and adding missing opcodes and bitwise operations.

New Features:

  • Adds missing opcodes (Mload8/Mstore8, Mod/Exp, SignExtend) and all bitwise operations (And, Or, Xor, Not, Byte, Shl, Shr, Sar).

Bug Fixes:

  • Fixes a bug in the vector_add implementation to correctly add two distinct vectors.

Enhancements:

  • Replaces fixed-size arrays with dynamic Vecs for memory and data structures, improving scalability and supporting more complex applications.

Fix VM initialization by introducing DataStructureStore::new() and add various
arithmetic and bitwise operations like Mod, Exp, And, Or, Xor, Not, Shl, Shr
and Sar. Improve SIMD vector handling and implement dynamic memory allocation.
@agentfarmx agentfarmx bot mentioned this pull request Mar 10, 2025
Copy link

sourcery-ai bot commented Mar 10, 2025

Reviewer's Guide by Sourcery

This pull request fixes the SIMD vector addition, enhances memory management by using dynamic Vecs, and implements missing opcodes and bitwise operations. The changes improve the VM's functionality and scalability.

Sequence diagram for SIMD Vector Addition

sequenceDiagram
  participant VM
  VM->VM: Load values1 from stack
  VM->VM: Pop 4 values from stack
  VM->VM: Load values2 from stack
  VM->VM: Add values1 and values2
  VM->VM: Store result back to stack
Loading

Updated class diagram for Memory

classDiagram
  class Memory {
    -Vec~u8~ data
    -usize size
    +new() Memory
    +with_capacity(capacity: usize) Memory
    +ensure_capacity(required_size: usize) void
    +get_byte(offset: usize) Option~u8~
    +load(offset: usize, len: usize) Result~Vec~u8~, VMError~
    +store(offset: usize, value: []u8) Result~void, VMError~
    +store8(offset: usize, value: u8) Result~void, VMError~
    +load8(offset: usize) Result~u8, VMError~
    +size() usize
    +clear() void
    +copy(dest: usize, src: usize, len: usize) Result~void, VMError~
    +cost(new_size: usize) u64
  }
  note for Memory "Replaced fixed-size array with dynamic Vec"
Loading

Updated class diagram for DataStructureStore

classDiagram
  class DataStructureStore {
    -Vec~Option~BTreeMapDS~~ btrees
    -Vec~Option~TrieDS~~ tries
    -Vec~Option~GraphDS~~ graphs
    -Vec~Option~OHLCVDS~~ ohlcvs
    -Vec~Option~HypergraphDS~~ hypergraphs
    +new() DataStructureStore
    +ensure_capacity(data_type: DataStructureType, id: usize) void
  }
  note for DataStructureStore "Replaced fixed-size arrays with dynamic Vecs"
Loading

File-Level Changes

Change Details Files
Corrected the SIMD vector addition implementation to properly add two distinct vectors instead of adding a vector to itself.
  • Load the first vector from the stack.
  • Pop the first vector from the stack.
  • Load the second vector from the stack.
  • Add the two vectors.
  • Store the result back to the stack.
lessvm-solana/src/vm/core.rs
Replaced fixed-size arrays with dynamic Vecs for memory and data structures to support more complex applications.
  • Replaced the fixed-size data array in the Memory struct with a dynamic Vec<u8>.
  • Added with_capacity and ensure_capacity methods to the Memory struct to handle dynamic resizing.
  • Modified the store and store8 methods to use ensure_capacity to ensure enough memory is allocated before writing.
  • Modified the clear method to reset the memory by iterating through the Vec and setting each byte to 0.
  • Modified the copy method to use ensure_capacity to ensure enough memory is allocated before copying.
  • Replaced fixed-size arrays in DataStructureStore with dynamic Vecs.
  • Added ensure_capacity method to DataStructureStore to handle dynamic resizing of data structures.
  • Removed max size constants for graph nodes, trie nodes, btree nodes and ohlcv entries.
lessvm-solana/src/vm/core.rs
lessvm-solana/src/vm/memory.rs
lessvm-solana/src/vm/data_structures.rs
Implemented missing opcodes (Mload8/Mstore8, Mod/Exp, SignExtend) and all bitwise operations.
  • Implemented Mload8 and Mstore8 opcodes for loading and storing single bytes in memory.
  • Implemented the Mod opcode for calculating the modulo of two numbers.
  • Implemented the Exp opcode for calculating the exponent of two numbers, including overflow checks.
  • Implemented the SignExtend opcode for sign-extending a value.
  • Implemented bitwise operations: And, Or, Xor, Not, Byte, Shl, Shr, and Sar.
lessvm-solana/src/vm/core.rs

Possibly linked issues

  • LessVM CodebaseΒ #2: The PR fixes the SIMD implementation, replaces fixed-size arrays with dynamic Vecs for memory and data structures, and adds missing opcodes, directly addressing the issue.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have skipped reviewing this pull request. It seems to have been created by a bot (hey, agentfarmx[bot]!). We assume it knows what it's doing!

Copy link

netlify bot commented Mar 10, 2025

βœ… Deploy Preview for lessvm ready!

Name Link
πŸ”¨ Latest commit 4ac68b8
πŸ” Latest deploy log https://app.netlify.com/sites/lessvm/deploys/67ce9fb8542a660008c37403
😎 Deploy Preview https://deploy-preview-3--lessvm.netlify.app
πŸ“± Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@0xrinegade 0xrinegade merged commit 1fc3353 into main Mar 10, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LessVM Codebase
1 participant