feat(soroban): build low-level memory layout analyzer (Issue #605)#614
Merged
mijinummi merged 3 commits intoJul 26, 2026
Conversation
|
@jotel-dev Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This pull request introduces the Soroban Low-Level Memory Layout Analyzer (
WasmInspector) inpackages/rules/soroban/src/analyzer/. It examines compiled Soroban WebAssembly (.wasm) bytecode binaries to pinpoint unoptimized linear memory allocations, static data segment bloat, host import call frequencies, dynamic memory growth (memory.grow), stack frame allocation bloat, and unaligned memory accesses. Findings are correlated back to source Rust file line numbers and function symbols.What Changed
packages/rules/soroban/src/analyzer/wasm-inspector.ts:WasmParser: Decodes WebAssembly binary headers, LEB128 unsigned/signed variable-length integers, and sections (Type, Import, Function, Memory, Global, Export, Code, Data, and Custom sections including symbolnamesection and source path references).WasmInspector:memory.grow): Identifies opcode0x40(memory.grow) calls which introduce runtime penalties in Soroban.__stack_pointer(> 1024 bytes) and unaligned memory loads/stores.src/contract.rs:42:10) and function names.packages/rules/soroban/src/analyzer/wasm-inspector.spec.ts:memory.growdetection, and source location mapping.packages/rules/soroban/src/index.ts:WasmInspectorand related types from the Soroban rules package.Why
High-level Rust abstractions often hide inefficient memory operations and allocation overheads that are only visible at the compiled WASM bytecode level. This analyzer allows GasGuard to inspect Soroban contract binary outputs directly and pinpoint exact source line locations for developer optimizations.
Testing Performed
wasm-inspector.spec.ts(100% passing rate).packages/rules/soroban(10/10 tests passing).Edge Cases Considered
namesection demangling or function indices).i32.load,i64.load, etc.).Risks
None. This is a non-breaking additive addition in
packages/rules/soroban/src/analyzer/.Closes #605