Add eth_call state overrides (closes #12)#54
Conversation
Adds Provider.callWithOverrides so simulators can answer "what if?"
questions (modified balances, nonces, code, or storage) without forking
a node. Maps to the geth-style third parameter of eth_call:
eth_call(transaction, blockTag, stateOverrideObject)
Supported by Anvil, Geth, Reth, Alchemy, Infura, and QuickNode.
New module: src/state_overrides.zig
pub const StateOverrides = struct {
pub fn setBalance(addr, value) !void
pub fn setNonce(addr, value) !void
pub fn setCode(addr, bytecode) !void // deep-copies the bytes
pub fn setStorageAt(addr, slot, value) !void // overlay onto existing state
pub fn setFullStorage(addr, slot, value) !void // replace state entirely
pub fn serializeJson(allocator) ![]u8
};
setStorageAt feeds the JSON-RPC `stateDiff` field; setFullStorage feeds
`state`. Multiple addresses, multiple slots, and arbitrary combinations
of fields per address are supported.
Provider:
- callWithOverrides(to, data, *const StateOverrides) ![]u8
- formatCallParamsWithOverrides() helper that produces the three-arg
eth_call body shape.
Tests:
- 9 unit tests in state_overrides.zig (empty -> {}, balance / nonce /
code combined, stateDiff merging, full-state replacement, setCode
overwrite without leak, multiple addresses, hex encoding edge cases).
- 2 unit tests in provider.zig for formatCallParamsWithOverrides
(with and without overrides; verifies wire shape).
- 3 integration tests against Anvil:
- code + balance override (deploy ADDRESS BALANCE return-bytecode,
verify the overridden balance is observed)
- stateDiff (deploy SLOAD return-bytecode, verify slot value)
- empty overrides path matches plain eth_call
All 1300+ unit tests pass; 21/21 integration tests pass against Anvil.
Closes #12.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Rate limit exceeded
To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
✨ Finishing Touches🧪 Generate unit tests (beta)
Review rate limit: 0/5 reviews remaining, refill in 3 minutes and 45 seconds. Comment |
Summary
Adds
Provider.callWithOverridesso simulators can answer "what if?" questions (modified balances, nonces, code, or storage) without forking a node. Maps to the geth-style third parameter ofeth_call:Supported by Anvil, Geth, Reth, Alchemy, Infura, and QuickNode.
New module:
src/state_overrides.zigsetStorageAtfeeds the JSON-RPCstateDifffield;setFullStoragefeedsstate. Multiple addresses, multiple slots, and arbitrary combinations of fields per address are supported.Provider changes
callWithOverrides(to, data, *const StateOverrides) ![]u8formatCallParamsWithOverrides()helper that produces the three-argeth_callbody shape.Test plan
make cipasses (1300+ unit tests)zig build integration-testagainst Anvil: 21/21 pass, including 3 new tests:ADDRESS BALANCE return-bytecodeshim viasetCode, sets a custom balance viasetBalance, calls the contract, and verifies the returned 32-byte word is the overridden balanceSLOAD return-bytecodeshim, sets storage slot 5 to a sentinel, verifies the returned wordeth_callcoderabbit review --prompt-only --type committed --base origin/main: no findings (after addressing two iterations of feedback: defensiveerrdeferon thesetCodecopy, and a redundant@constCastindeinit)std.debug.printin library code, no emojisOut of scope
eth_call(Deprecated allocator initialization + tests fix LLVM crash by AI #10) -- the batch API takes raw params strings; users can pre-build viaformatCallParamsWithOverridesif needed. A typed batch + overrides convenience can be added later.Overridestruct-construction API (the issue mentionssetStorageAt(pool, slot, value)style which is what we implemented; we did not add a fluent builder)Closes #12.