Skip to content

Conversation

grandizzy
Copy link
Collaborator

Motivation

Solution

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

Copy link
Contributor

@pcaversaccio pcaversaccio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also document this somehow in the docs because this is pretty useful to know

Copy link
Contributor

@pcaversaccio pcaversaccio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed with @grandizzy offline, the test is correctly testing the wrong case (should return 0x000...001) and I also tested it locally using this

cast call --trace --from "0x89D5C0AF48e9C945F280E0450579DE8c4d92a718" \
  "0x5EA1d9A6dDC3A0329378a327746D71A2019eC332" \
  --data "0xe75235b8" \
  --override-state-diff "0x5EA1d9A6dDC3A0329378a327746D71A2019eC332:0x7817a5f88884c5cb3dfd88434e99bb216a32ad4560cf73fe0fbe518279f8163e:1,0x5EA1d9A6dDC3A0329378a327746D71A2019eC332:4:1,0x5EA1d9A6dDC3A0329378a327746D71A2019eC332:0x4a204f620c8c5ccdca3fd54d003badd85ba500436a431f0cbda4f558c93c34c8:0,0x5EA1d9A6dDC3A0329378a327746D71A2019eC332:0xb104e0b93118902c651344349b610029d694cfdec91c589c91ebafbcd0289947:0" \
  --rpc-url "https://eth.llamarpc.com"

and it doesn't parse it correctly, i.e. not all the state overrides are reflected.

@grandizzy
Copy link
Collaborator Author

As discussed with @grandizzy offline, the test is correctly testing the wrong case (should return 0x000...001) and I also tested it locally using this

cast call --trace --from "0x89D5C0AF48e9C945F280E0450579DE8c4d92a718" \
  "0x5EA1d9A6dDC3A0329378a327746D71A2019eC332" \
  --data "0xe75235b8" \
  --override-state-diff "0x5EA1d9A6dDC3A0329378a327746D71A2019eC332:0x7817a5f88884c5cb3dfd88434e99bb216a32ad4560cf73fe0fbe518279f8163e:1,0x5EA1d9A6dDC3A0329378a327746D71A2019eC332:4:1,0x5EA1d9A6dDC3A0329378a327746D71A2019eC332:0x4a204f620c8c5ccdca3fd54d003badd85ba500436a431f0cbda4f558c93c34c8:0,0x5EA1d9A6dDC3A0329378a327746D71A2019eC332:0xb104e0b93118902c651344349b610029d694cfdec91c589c91ebafbcd0289947:0" \
  --rpc-url "https://eth.llamarpc.com"

and it doesn't parse it correctly, i.e. not all the state overrides are reflected.

I updated the test, it didn't use 0xe75235b8 as data hence the diff

0xrusowsky
0xrusowsky previously approved these changes Sep 5, 2025
@grandizzy grandizzy marked this pull request as draft September 5, 2025 08:21
@grandizzy
Copy link
Collaborator Author

grandizzy commented Sep 5, 2025

need to call

let (addr, slot, value) = address_slot_value_override(override_str)?;
state_overrides_builder =
state_overrides_builder.with_state_diff(addr, [(slot.into(), value.into())]);
}
only once per address with all state diffs for all slots, otherwise only the last diff set is applied

Copy link
Contributor

@pcaversaccio pcaversaccio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, a good complex test for this is this:

  • Checks if the Safe signer threshold is set to 1 (overrides the storage slot 4 to 1, which is the storage slot for the threshold and calls getThreshold() (0xe75235b8)):
cast call --trace --from "0x2066901073a33ba2500274704aB04763875cF210" \
  "0x5EA1d9A6dDC3A0329378a327746D71A2019eC332" \
  --data "0xe75235b8" \
  --override-state-diff "0x5EA1d9A6dDC3A0329378a327746D71A2019eC332:0xf0af0268363540b847b4c07f2f9a0401c607c1b11ebca511724a71755dfd4137:1,0x5EA1d9A6dDC3A0329378a327746D71A2019eC332:4:1,0x5EA1d9A6dDC3A0329378a327746D71A2019eC332:0x4a204f620c8c5ccdca3fd54d003badd85ba500436a431f0cbda4f558c93c34c8:0,0x5EA1d9A6dDC3A0329378a327746D71A2019eC332:0xb104e0b93118902c651344349b610029d694cfdec91c589c91ebafbcd0289947:0" \
  --rpc-url "https://eth.llamarpc.com"

and

  • Checks if the Safe signer 0x2066901073a33ba2500274704aB04763875cF210 is an owner, i.e. should return true (overrides/sets the specific mapping slot for the owners[signer_address] = address(0x1) - can be calculate like $(cast keccak $(cast abi-encode "mappingOwnerSlot(address,uint256)" "$signer_address" "2")), and calls isOwner(address) (0x2f54bf6e0000000000000000000000002066901073a33ba2500274704ab04763875cf210)):
cast call --trace --from "0x2066901073a33ba2500274704aB04763875cF210" \
  "0x5EA1d9A6dDC3A0329378a327746D71A2019eC332" \
  --data "0x2f54bf6e0000000000000000000000002066901073a33ba2500274704ab04763875cf210" \
  --override-state-diff "0x5EA1d9A6dDC3A0329378a327746D71A2019eC332:0xf0af0268363540b847b4c07f2f9a0401c607c1b11ebca511724a71755dfd4137:1,0x5EA1d9A6dDC3A0329378a327746D71A2019eC332:4:1,0x5EA1d9A6dDC3A0329378a327746D71A2019eC332:0x4a204f620c8c5ccdca3fd54d003badd85ba500436a431f0cbda4f558c93c34c8:0,0x5EA1d9A6dDC3A0329378a327746D71A2019eC332:0xb104e0b93118902c651344349b610029d694cfdec91c589c91ebafbcd0289947:0" \
  --rpc-url "https://eth.llamarpc.com"

@grandizzy grandizzy marked this pull request as ready for review September 5, 2025 15:42
@grandizzy grandizzy requested a review from 0xrusowsky September 5, 2025 15:42
@DaniPopes DaniPopes changed the title fix(cast): allow comma sepparated values for overrides fix(cast): allow comma-separated values for overrides Sep 5, 2025
@grandizzy grandizzy merged commit 3396cc7 into foundry-rs:master Sep 5, 2025
23 checks passed
@github-project-automation github-project-automation bot moved this to Done in Foundry Sep 5, 2025
@grandizzy grandizzy deleted the issue-11551 branch September 5, 2025 16:19
grandizzy added a commit to grandizzy/foundry that referenced this pull request Sep 8, 2025
* fix(cast): allow comma sepparated values for overrides

* Fix multiple slots

* Tests with traces
grandizzy added a commit that referenced this pull request Sep 8, 2025
* fix(cast): allow comma-separated values for overrides (#11553)

* fix(cast): allow comma sepparated values for overrides

* Fix multiple slots

* Tests with traces

* chore: bump v1.3.5 (#11576)
MerkleBoy pushed a commit to MerkleBoy/foundry that referenced this pull request Sep 17, 2025
* fix(cast): allow comma sepparated values for overrides

* Fix multiple slots

* Tests with traces
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug(cast call): multiple --override-state-diff slots not correctly parsed

4 participants