Skip to content

Conversation

@alexggh
Copy link

@alexggh alexggh commented Oct 2, 2025

Depends on: paritytech/polkadot-sdk#9909
Fixes: #324
Fixes: #335

There are a few problems with the way we currently do calls:

  1. We are not correctly setting the origin, fixed it by using ecx.tx.caller., when calling bare_call/bare_instantiate.
  2. Delegate calls don't work at all because we are using bare_call for all type of calls, and that does not allow setting any delegate call info.
  3. For prank/startPrank/stopPrank pallet revive does not have any ability to play with the caller/msg.sender.
  4. For mock* cheatcodes pallet revive does not have the ability to intercept the flows.

In this pr I ended up adding a series of hooks in pallet-revive which allows to intercept and control the flow, the interface is described here https://github.com/paritytech/polkadot-sdk/pull/9909/files#diff-62436392e75447324001e88786b55d2966415fdd7e6cf6319708c8d48a980c2fR31 and implemented in this PR.

Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>

fn fund_pranked_accounts(prank_enabled: bool, account: Address) {
// Fuzzed prank addresses have no balance, so they won't exist in revive, and
// calls will fail, this is not a problem when running in REVM.
Copy link
Collaborator

Choose a reason for hiding this comment

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

how is it done that account without funds can be used to trigger call in REVM - how is gas charged in this case?

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, that's something I want to investigate.

Copy link
Author

Choose a reason for hiding this comment

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

So, I did some digging, it seems to be because for revive we want to charge the storage deposit from the pranked accounts, I can probably add some hook in there:
https://github.com/paritytech/polkadot-sdk/blob/c61e227f2c59fa0ce7df5f977dad4076ff470f00/substrate/frame/revive/src/lib.rs#L1308

But, I also don't think the funding is such a bad solution.

Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
@alindima
Copy link

alindima commented Oct 6, 2025

For pranking, couldn't you use an approach like we do in Anvil? #332

Overriding the host functions that do the account recovery

@alexggh
Copy link
Author

alexggh commented Oct 6, 2025

For pranking, couldn't you use an approach like we do in Anvil? #332

Overriding the host functions that do the account recovery

Unless, I'm misunderstanding #332, these are two different things msg.sender and tx.orgin are already set by the host when calling into the smart-contracts VM, so overriding the host functions here wouldn't have any impact. Because the pallet-revive env will just set it to whatever it detects automatically.

Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
@alexggh alexggh changed the title add vm.prank/startPrank/stopPrank support add prank* and mock* cheatcodes family support Oct 8, 2025
@alexggh alexggh marked this pull request as ready for review October 8, 2025 15:52
Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
@alexggh alexggh mentioned this pull request Oct 24, 2025
Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
github-merge-queue bot pushed a commit to paritytech/polkadot-sdk that referenced this pull request Oct 28, 2025
Needed for: paritytech/foundry-polkadot#334.

In foundry-polkadot we need the ability to be able to manipulate the
`msg.sender` and the `tx.origin` that a solidity contract sees cheatcode
documentation, plus the ability to mock calls and functions.

Currently all create/call methods use the `bare_instantiate`/`bare_call`
to run things in pallet-revive, the caller then normally gets set
automatically, based on what is the call stack, but for `forge test` we
need to be able to manipulate, so that we can set it to custom values.

Additionally, for delegate_call, bare_call is used, so there is no way
to specify we are dealing with a delegate call, so the call is not
working correcly.
 
For both this paths, we need a way to inject this information into the
execution environment, hence I added an optional hooks interface that we
implement from foundry cheatcodes for prank and mock functionality.

## TODO
- [x] Add tests to make sure the hooks functionality does not regress.

---------

Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
github-merge-queue bot pushed a commit to paritytech/polkadot-sdk that referenced this pull request Oct 28, 2025
Needed for: paritytech/foundry-polkadot#334.

In foundry-polkadot we need the ability to be able to manipulate the
`msg.sender` and the `tx.origin` that a solidity contract sees cheatcode
documentation, plus the ability to mock calls and functions.

Currently all create/call methods use the `bare_instantiate`/`bare_call`
to run things in pallet-revive, the caller then normally gets set
automatically, based on what is the call stack, but for `forge test` we
need to be able to manipulate, so that we can set it to custom values.

Additionally, for delegate_call, bare_call is used, so there is no way
to specify we are dealing with a delegate call, so the call is not
working correcly.
 
For both this paths, we need a way to inject this information into the
execution environment, hence I added an optional hooks interface that we
implement from foundry cheatcodes for prank and mock functionality.

## TODO
- [x] Add tests to make sure the hooks functionality does not regress.

---------

Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

6 participants