Skip to content

feat: Implement WasmCache for Contract Bytecode (#405) - #418

Open
GiftedGiftB wants to merge 1 commit into
Toolbox-Lab:mainfrom
GiftedGiftB:Implement-WasmCache-for-Contract-Bytecode
Open

feat: Implement WasmCache for Contract Bytecode (#405)#418
GiftedGiftB wants to merge 1 commit into
Toolbox-Lab:mainfrom
GiftedGiftB:Implement-WasmCache-for-Contract-Bytecode

Conversation

@GiftedGiftB

Copy link
Copy Markdown

Closed #405

Description

This PR implements the WasmCache to specialize in storing and retrieving compiled WebAssembly (Wasm) modules. By eliminating redundant parsing and compilation steps across repeated executions, this implementation heavily optimizes the contract execution pipeline.

How It Was Done

  • WasmCache Module: Created crates/core/src/cache/wasm.rs containing a specialized WasmCache struct that leverages the existing CacheProvider trait.
  • Deterministic Hashing: Added a hash_bytecode utility using sha2::Sha256 to create unique, cryptographic cache keys derived from the raw contract bytecode.
  • Cache Interfacing: Implemented generic get, put, and clear caching methods to seamlessly retrieve and store instantiated Wasm module buffers (Vec<u8>).
  • Integration: Exported the wasm module in crates/core/src/cache/mod.rs.
  • Validation: Added inline unit tests using a mocked InMemoryCacheDouble to ensure safe operation logic independently from file system constraints.

Issues Encountered (If Any)

No significant roadblocks. We were able to leverage the existing sha2 dependency present in the grat-core cargo manifest and smoothly map the caching data over the shared CacheProvider trait layout.

How It Was Tested

  • Unit Testing: Added asynchronous tokio::test cases inside crates/core/src/cache/wasm.rs.
  • Hash Consistency: Verified SHA-256 determinism (identical hashes for same bytecode, separate hashes for differing bytes).
  • Roundtrip Integrity: Verified correct storage and retrieval of the compiled buffers, ensuring no cache misses on previously inserted entries.
  • Suite Execution: Ran cargo test --package grat-core --lib cache::wasm to verify successful test suite completion.

Screenshots / Video (If Applicable)

N/A - This is a backend caching infrastructural optimization.


You can copy and paste this directly into your GitHub Pull Request description!

@coderabbitai

coderabbitai Bot commented Aug 24, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 234703a4-dbfd-4408-9c54-a8b6e381a47d


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

Implement WasmCache for Contract Bytecode

1 participant