Repository navigation
Fix asset discovery in simulateCalls - #4997
Conversation
|
@Ghadi8 is attempting to deploy a commit to the Wevm Team on Vercel. A member of the Team first needs to authorize it. |
🦋 Changeset detectedLatest commit: 3fb956c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6439a44190
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // Included even for calls without data: contracts that mint on receiving | ||
| // native value (WETH) emit `Deposit`, not a `Transfer` the logs would catch. | ||
| // Candidates without code fall out at `isBalance`. | ||
| ...parameters.calls.map((call: any) => call.to?.toLowerCase()), |
There was a problem hiding this comment.
Validate arbitrary call targets before ABI decoding
When traceAssetChanges is used with a non-token call target whose fallback succeeds with non-empty malformed data, adding every to address here makes the later typed balanceOf probe abort the entire action. simulateBlocks eagerly passes any successful non-empty response to decodeFunctionResult, so isBalance is never reached for responses such as 0x01; instead, simulateCalls throws an ABI decoding error even if the original calls succeeded. Probe these speculative candidates without an ABI and validate that the returned data is a valid encoded uint256 before decoding.
Useful? React with 👍 / 👎.
| blocks: [ | ||
| { | ||
| calls: calls.map((call) => ({ |
There was a problem hiding this comment.
Run discovery at the same simulated block as the batch
When a call branches on block.number, block.timestamp, or another block field, this discovery batch executes in the first simulated block after the base, while the measurement request prepends the ETH and asset pre-balance blocks and therefore executes the real calls in the third simulated block. The two passes can consequently take different branches and move different tokens even though they share a base block, causing the actual asset change to be omitted. Add equivalent leading simulated blocks to discovery or otherwise align the execution block environment.
Useful? React with 👍 / 👎.
| const balancesPre = [...ethPre, ...assetsPre].map((call) => | ||
| call.status === 'success' ? hexToBigInt(call.data) : null, | ||
| isBalance(call) ? hexToBigInt(call.data) : null, | ||
| ) |
There was a problem hiding this comment.
Treat a missing pre-deployment balance as zero
When the batch deploys a token and mints it to the traced account, log discovery correctly finds the new token address and its post-execution balanceOf succeeds, but the pre-balance probe runs before the contract exists and returns empty data. This maps the pre-balance to null, and the loop later skips the change entirely instead of reporting a transition from 0n to the minted balance. If the post probe establishes that the candidate is a token, an empty successful pre-deployment response should be treated as zero.
Useful? React with 👍 / 👎.
| traceAssetChanges && | ||
| typeof blockNumber !== 'bigint' && | ||
| blockTag_ === 'latest' | ||
| ? await getBlockNumber(client, { cacheTime: 0 }) |
There was a problem hiding this comment.
Include block-number lookup failures in the error union
When traceAssetChanges is enabled without an explicit non-latest block, this new call can reject with GetBlockNumberErrorType variants such as transport retry or abort errors, but SimulateCallsErrorType was not extended to include that type. Consumers using the exported error union therefore cannot exhaustively type errors from a newly introduced runtime path. Import GetBlockNumberErrorType and add it to SimulateCallsErrorType.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0d3fc413d4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| traceAssetChanges && | ||
| typeof blockNumber !== 'bigint' && | ||
| blockTag_ === 'latest' | ||
| ? await getBlockNumber(client, { cacheTime: 0 }) | ||
| : blockNumber |
There was a problem hiding this comment.
Pin moving block tags across both simulation passes
When traceAssetChanges uses safe, finalized, or pending (explicitly or through experimental_blockTag), this condition leaves the tag unresolved and sends it in two separate eth_simulateV1 requests. If the tag advances or pending state changes between discovery and measurement, discovery can collect tokens from one base state while the returned balances and call results come from another, recreating the mismatch that this pinning is intended to prevent. Resolve moving tags to a concrete block number before both passes; only earliest is inherently stable.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: db0e4f828e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| { calls: [] }, | ||
| { calls: [] }, |
There was a problem hiding this comment.
Mirror the actual preflight blocks in discovery
When a call branches on block.basefee or blockhash(block.number - 1), these empty placeholders do not reproduce the execution environment of the measurement pass: its first two blocks execute the ETH and token balance probes at lines 338-360, changing their gas usage and block hashes. The third-block call can therefore emit transfers for different tokens during discovery and measurement, leaving the measured token absent from assetChanges. Fresh evidence beyond the earlier block-alignment comment is that the newly added leading blocks align only the height, not the preceding block contents; discovery should simulate equivalent preflight blocks.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 72f0399e23
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| ...(stateOverrides ?? []).filter( | ||
| ({ address }) => address.toLowerCase() !== zeroAddress, | ||
| ), | ||
| { ...zeroStateOverride, address: zeroAddress, nonce: 0 }, |
There was a problem hiding this comment.
Preserve the caller's zero-address nonce override
When stateOverrides intentionally installs factory code at zeroAddress with a nonzero nonce, forcing its nonce to 0 makes the measurement pass execute the user's call against different state than discovery. For example, if that overridden factory uses CREATE, discovery finds the token deployed from the requested nonce, while measurement deploys it at the nonce-0 address and then probes only the discovery address, so the resulting asset change is omitted even though the returned call result reflects the original override. Use a probe sender that cannot collide with user state, or otherwise avoid changing the override used by the user's calls.
Useful? React with 👍 / 👎.
| const block = await getBlock(client, { blockTag: blockTag_ }) | ||
| if (typeof block.number !== 'bigint') | ||
| throw new BaseError( | ||
| `Block tag \`${blockTag_}\` did not resolve to a number.`, | ||
| ) | ||
| baseBlockNumber = block.number |
There was a problem hiding this comment.
Keep pending simulations on the pending block tag
When traceAssetChanges is used with blockTag: 'pending' (including through experimental_blockTag), getBlock normally returns either the next, not-yet-canonical block number or no number at all. This code then either pins both eth_simulateV1 requests to a height that does not exist and gets a header-not-found response, or throws the new BaseError, although simulateBlocks could previously simulate directly against pending. Fresh evidence after the earlier tag-pinning concern is this conversion of the pending tag into an unusable concrete height; pending needs to remain a tag or be snapshotted by a mechanism that preserves its state.
Useful? React with 👍 / 👎.
| ...assetAddresses.map((address, i) => ({ | ||
| data: AbiFunction.encodeData(balanceOfFunction, [ | ||
| account!.address, | ||
| ]), | ||
| to: address, | ||
| from: zeroAddress, | ||
| nonce: i, | ||
| })), |
There was a problem hiding this comment.
Isolate speculative balance probes from the user's calls
When any discovered candidate has a state-changing balanceOf implementation or fallback that returns a valid 32-byte value, these raw probe transactions mutate it immediately before the user's calls in the measurement pass. Discovery and the returned results execute without those probes, so the measurement can take a different branch and report asset balances for an execution that does not match the returned results. Fresh evidence beyond the earlier malformed-response case is that accepting a valid response now allows an arbitrary call target to alter measurement state; run pre-balance probes in an isolated state rather than in the same block before the batch.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d4a727ea2a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const blockTag_ = blockTag ?? client.experimental_blockTag ?? 'latest' | ||
| if (traceAssetChanges && blockTag_ === 'pending') |
There was a problem hiding this comment.
Let explicit block numbers bypass pending-tag rejection
When the client defaults experimental_blockTag to pending but the caller explicitly supplies a concrete blockNumber, this condition still rejects asset tracing even though every subsequent request would use that stable number and ignore the client tag. This affects clients for chains with experimental_preconfirmationTime, which automatically receive the pending default, and prevents callers from opting into supported tracing by pinning a block; only reject pending when no blockNumber was provided.
Useful? React with 👍 / 👎.
| } catch { | ||
| return { data: '0x' as const, status: 'failure' as const } |
There was a problem hiding this comment.
Propagate RPC failures from pre-balance reads
When a pre-balance eth_call fails because of a transport outage, rate limit, abort, or other request-level error, this blanket catch converts it into a failed speculative balance and simulateCalls silently omits the corresponding asset from assetChanges while still returning successful call results. With the new fan-out of one request per candidate, even a single throttled request can therefore produce incomplete accounting; tolerate expected contract execution failures, but rethrow request and transport failures.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 90380c75c9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| !(error instanceof CallExecutionError) || | ||
| !(error.cause instanceof ExecutionRevertedError) | ||
| ) | ||
| throw error |
There was a problem hiding this comment.
Include balance-read errors in the exported union
When traceAssetChanges is enabled and a pre-balance eth_call encounters a transport, abort, serialization, or other non-revert failure, this branch rethrows the CallExecutionError produced by call, but SimulateCallsErrorType does not include CallErrorType. Consumers therefore cannot exhaustively type errors from the new balance-reading path. Import CallErrorType and add it to the exported error union.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 699ae60285
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| // `contracts/src/deployless/StaticCall.sol` compiled with Solidity 0.8.35. | ||
| const staticCallCode = | ||
| '0x608060405234801561000f575f5ffd5b50604051610252380380610252833981810160405281019061003191906101f7565b5f5f825160208401855afa610048573d5f5f3e3d5ffd5b3d5f5f3e3d5ff35b5f604051905090565b5f5ffd5b5f5ffd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f61008a82610061565b9050919050565b61009a81610080565b81146100a4575f5ffd5b50565b5f815190506100b581610091565b92915050565b5f5ffd5b5f5ffd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b610109826100c3565b810181811067ffffffffffffffff82111715610128576101276100d3565b5b80604052505050565b5f61013a610050565b90506101468282610100565b919050565b5f67ffffffffffffffff821115610165576101646100d3565b5b61016e826100c3565b9050602081019050919050565b8281835e5f83830152505050565b5f61019b6101968461014b565b610131565b9050828152602081018484840111156101b7576101b66100bf565b5b6101c284828561017b565b509392505050565b5f82601f8301126101de576101dd6100bb565b5b81516101ee848260208601610189565b91505092915050565b5f5f6040838503121561020d5761020c610059565b5b5f61021a858286016100a7565b925050602083015167ffffffffffffffff81111561023b5761023a61005d565b5b610247858286016101ca565b915050925092905056fe' |
There was a problem hiding this comment.
Compile the helper for pre-Cancun EVM revisions
When blockNumber targets a pre-Cancun block, or the configured chain has not enabled Cancun, this Solidity 0.8.35 bytecode executes the MCOPY opcode (0x5e) before that opcode is valid. Every static-call wrapper consequently fails with an invalid opcode, causing the post-balance probes to be rejected by isBalance and all discovered token changes to be silently omitted. Compile this helper for an older EVM target that is compatible with the historical blocks and chains supported by simulateCalls.
Useful? React with 👍 / 👎.
| data: encodeStaticCall( | ||
| address, | ||
| AbiFunction.encodeData(balanceOfFunction, [ | ||
| account!.address, | ||
| ]), | ||
| ), |
There was a problem hiding this comment.
Reuse one wrapper caller for pre- and post-balance reads
When a token's balanceOf depends on the exact msg.sender, these deployless wrappers do not provide the promised consistent caller: each target sees the newly created wrapper as its caller, the standalone pre-read creates it at the base nonce, and the post-read creates it after the ETH probe and any preceding candidates have advanced the creation sender's nonce. Such a token can therefore return different balances without any user-induced change, producing a spurious diff or omitting the asset; execute both reads through the same fixed helper address.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 23859a34ec
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const account_ = pad(account.toLowerCase() as Hex, { size: 32 }) | ||
| return logs | ||
| .filter((log) => { | ||
| if (log.topics[0] !== transferEventSelector) return false |
There was a problem hiding this comment.
Normalize the transfer selector before comparing
When an RPC or custom transport returns valid hex topics containing uppercase digits, formatLog preserves that casing, so this comparison rejects the Transfer selector even though topics 1 and 2 are normalized below. The affected token is then omitted unless it also appears as a direct call target, producing incomplete assetChanges; compare a lowercased topic against the selector.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2c965939ae
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| Asset tracing does not support the `pending` block tag because discovery and balance | ||
| measurement require a stable base block. |
There was a problem hiding this comment.
Align the pending-tag documentation with runtime behavior
This states that asset tracing does not support pending, but simulateCalls explicitly preserves that tag and the new traceAssetChanges preserves the pending block tag test expects the operation to succeed and return asset changes. Either reject pending at runtime to enforce this documented restriction or document that it is accepted, including the consistency limitations of performing discovery and measurement in separate requests.
Useful? React with 👍 / 👎.
* feat: add block header watcher (#4999) * fix: complete block header watcher integration (#5001) * chore: version package (#5000) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * fix(tempo): bind encrypted deposits to sender (#5002) * fix(tempo): bind encrypted deposits to sender Co-authored-by: Derek Cofausper <[email protected]> * ci: test sender-bound zone deposits * ci: align Tempo and Zone fixtures * test(tempo): routed T10 fixtures through encrypted deposits * chore: logged local Zone provisioning stall * chore: ignored unpatched extract-zip advisory * fix(tempo): defaulted encrypted deposit sender * ci: skipped Wagmi verification * chore: remove friction log --------- Co-authored-by: 0xrusowsky <[email protected]> Co-authored-by: Derek Cofausper <[email protected]> Co-authored-by: Steven Truong <[email protected]> Co-authored-by: jxom <[email protected]> * chore: version package (#5003) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * fix(siwe): reject unparseable expirationTime and notBefore (#4990) * fix(siwe): reject unparseable expirationTime and notBefore Invalid Date values from parseSiweMessage (e.g. Expiration Time: never) are truthy, so comparisons like `time >= expirationTime` are always false and lifetime / nbf checks were skipped. Fail closed when either field is present but not a real date (sibling of thirdweb-dev/js#8875 / supabase/auth#2688). * fix(siwe): require EIP-4361 date-time strings and reject invalid time Validate raw SIWE timestamps against the RFC 3339 profile before Date coercion, and fail closed when the caller-supplied time is invalid so lifetime comparisons cannot be skipped. * fix(siwe): inline date validation --------- Co-authored-by: jxom <[email protected]> * fix: asset discovery in `simulateCalls` (#4997) * fix(simulateCalls): discover assets from simulated logs * refactor(simulateCalls): align asset discovery with repo conventions * fix(simulateCalls): pin both asset-tracing passes to one base block * test(simulateCalls): skip asset tracing on the pinned Anvil * chore: update accessListHints comment * fix(simulateCalls): preserve block tags and request errors * fix(simulateCalls): harden asset trace discovery * test: use reth for mainnet forks * test(simulateCalls): run asset tracing against reth * fix(simulateCalls): align asset trace simulations * fix(simulateCalls): stabilize asset tracing * chore: add static call source * fix(simulateCalls): simplify asset tracing * fix(simulateCalls): isolate asset balance probes * fix(simulateCalls): align asset probe callers * fix(simulateCalls): preserve pending block tag * fix(simulateCalls): normalize transfer topics * refactor(simulateCalls): remove redundant asset deduplication * test(simulateCalls): cover asset tracing edge cases * docs(simulateCalls): describe pending asset tracing --------- Co-authored-by: jxom <[email protected]> * fix: update nanoid security override * fix: increase package size limits * ci: remove docs deployment --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: struong <[email protected]> Co-authored-by: 0xrusowsky <[email protected]> Co-authored-by: Derek Cofausper <[email protected]> Co-authored-by: Steven Truong <[email protected]> Co-authored-by: Sash <[email protected]> Co-authored-by: Ghadi <[email protected]>
What this solves
With
traceAssetChanges: true, candidate tokens were discovered by runningeth_createAccessListper call, independently, against unmodified state atlatest. Consequences:createAccessListrejects reverting calls, so one call that fails against current state (a transfer the account cannot yet afford) failed the whole action instead of landing inresults.stateOverrides. The probes passed none (support for overrides oneth_createAccessListis not portable across nodes), so discovery could not see balances or allowances the caller overrode, even though the result simulation could.blockNumber. No block was forwarded; discovery ran atlatestwhile results were simulated at the requested block.deposit()thentransfer()) contributed no assets.latestindependently: separate requests, possibly different replicas, head free to advance in between. A token the measurement pass moved but discovery never saw was silently absent fromassetChanges.Discovery now simulates the batch once via
eth_simulateV1and takes token addresses fromTransferlogs where the account isfromorto, plus each call'sto. That inherits sequential execution, state overrides, and the requested block. The access-list pass remains as supplementary hints (assets that change without aTransferthe account participates in), now block-pinned and failure-tolerant. For (5), the base block is resolved once up front and both passes plus the hints are pinned to it; onlylatestis resolved, an explicit block or tag passes through untouched.balanceOfprobes now require non-empty return data, not juststatus === 'success': each call'stois a candidate, and atowithout code returns empty data that would decode as a bogus0nbalance.Tests
New coverage: a call that reverts in isolation; a call that depends on an earlier call; a token reachable only through logs (ETH to USDC via the Uniswap V2 router, where the only
tois the router); and two RPC-spy tests asserting that both simulations and the access-list pass use the requested block, and that they stay pinned to the base when the head advances between them.All
traceAssetChangestests are skipped on the pinned Anvil, including the pre-existingbehavior: with mutation calls + asset changes. Tracing reads the account's ETH balance through a deployless call with noto, and Anvil v1.7.1 (the versionverify.ymlpins) rejects those ineth_simulateV1witheip1559 transaction can't be built due to missing keys: ["to"]. Anvil 1.5.1 handles these correctly, and the capability was restored on master by foundry-rs/foundry#15784 (merged 2026-07-16, unreleased at the time of writing). The tests pass against Anvil 1.5.1 and against builds carrying that fix.Alternatives explored
parseEventLogswitherc20Abi. ERC-721Transferhas three indexed params and fails strict decoding; matchingtopics[0..2]directly covers both under one predicate.number - 1n) instead of resolving it. No extra request, but the numbering is not portable: the spec and geth put the first simulated block at base + 1, while Anvil (through v1.7.1) puts it at base. The derivation would pin measurement one block behind discovery on Anvil, reintroducing the divergence deterministically. Resolvingeth_blockNumberonce (cacheTime: 0, so a cached head cannot pin to a stale block) is version-agnostic at the cost of a round trip.Worth reviewer attention
traceAssetChanges: truenow costs one extraeth_simulateV1, plus oneeth_blockNumberwhen no block is requested. The hints run concurrently with the discovery simulation. Discovery cannot fold into the existing multi-block request: the token set must be known before the balance blocks are built.eth_simulateV1takes no block hash, so a reorg between the two requests remains possible; that is the ceiling the API allows.accessListHintsswallows all errors by design (some nodes lack the method, and it rejects reverting calls); log-based discovery is the primary path. Happy to drop the supplementary pass entirely if you prefer the simpler version.balanceOftakes a token id, so it does not fit the single-probe shape.Docs updated with how discovery works and the balances that are not traced.