feat(analysis): build multi-contract execution call-graph generator (Issue #604)#615
Merged
mijinummi merged 3 commits intoJul 26, 2026
Conversation
…uator, and update project dependency build configuration
|
@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! 🚀 |
Collaborator
|
Please kindly resolve conflict @jotel-dev |
2 tasks
Collaborator
|
LGTM! |
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 implements the Multi-Contract Execution Call-Graph Generator (
CallGraphBuilderandGasTreeEvaluator) undersrc/analysis/graph/. It parses multi-contract monorepo suites, constructs a directed execution call graph tracing cross-contract and internal function invocations, and evaluates cumulative gas expenditure down the entire call stack to pinpoint gas bottlenecks, recursive call loops, and deep call stacks.What Changed
src/analysis/graph/call-graph-builder.ts:CallGraphBuilder: Parses multi-contract import graphs and contract declarations (Solidity, Soroban Rust, Vyper).CallGraphNode) detailing visibility, state accesses (SSTORE/SLOAD/storage), base gas estimates, and source line locations.CallGraphEdge) for internal calls, cross-contract calls,delegatecall,staticcall, andenv.invoke_contract().forandwhileloops and applies execution loop multipliers.src/analysis/graph/gas-tree-evaluator.ts:GasTreeEvaluator: Performs depth-first traversal (DFS) starting from each entry point down the execution call stack.ContractA->ContractB->ContractA) and deep call stack depths (> 5 hops).HIGH_CUMULATIVE_GAS_EXCEEDED: Cumulative gas expenditure exceeds safety threshold.DEEP_CALL_STACK_EXCEEDED: Execution call stack depth exceeds maximum hops limit (63/64th gas rule risk).RECURSIVE_CALL_LOOP: Recursive call cycles detected in execution path.EXPENSIVE_CROSS_CONTRACT_LOOP: External function calls executed repeatedly inside loops.src/analysis/graph/call-graph-builder.spec.ts&gas-tree-evaluator.spec.ts:src/analysis/graph/index.ts:CallGraphBuilder,GasTreeEvaluator, and associated types.Why
Single-function analyzers miss gas bottlenecks caused by deep external call trees, recursive contract loops, and expensive cross-contract state queries. This multi-contract execution call graph generator allows GasGuard to trace execution paths across entire contract suites and calculate total cumulative gas usage.
Testing Performed
call-graph-builder.spec.tsandgas-tree-evaluator.spec.ts(100% pass rate).cargo test -p gasguard-rules(104/104 tests passing).Edge Cases Considered
for/whileloops.Risks
None. This is an additive feature in
src/analysis/graph/.Closes #604