Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cheatcodes): add delegatecall to pranking #8863

Merged
merged 20 commits into from
Nov 15, 2024

Conversation

EdwardJES
Copy link
Contributor

@EdwardJES EdwardJES commented Sep 13, 2024

Motivation

Closes #824. Currently there is no easy way to test delegate calls using foundry tests.

Solution

  • Add a delegate_call flag to the prank.
  • ....

@@ -833,6 +833,19 @@ impl Cheatcodes {

// Apply our prank
if let Some(prank) = &self.prank {
// Apply delegate call. call.caller will not equal prank.prank_caller
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @zerosnacks, my understanding is a little fuzzy here. It seems in the case of a delegate call that call.caller == prank.prank_caller will not be true. Is it suitable to have this here? Ty.

Copy link
Member

Choose a reason for hiding this comment

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

cc @DaniPopes would you have more context on this?

@EdwardJES EdwardJES force-pushed the edwardjes/delegatecall branch from a7e8123 to 325c218 Compare September 13, 2024 01:33
@EdwardJES EdwardJES force-pushed the edwardjes/delegatecall branch from 8a65994 to d964aad Compare September 13, 2024 04:00
@EdwardJES EdwardJES changed the title feat(cheatcodes): add delegatecall to pranking [WIP] feat(cheatcodes): add delegatecall to pranking Sep 13, 2024
@zerosnacks
Copy link
Member

Hi @EdwardJES thanks for your PR - my apologies that it has taken a while to respond

@EdwardJES EdwardJES marked this pull request as ready for review September 27, 2024 00:44
@EdwardJES EdwardJES changed the title [WIP] feat(cheatcodes): add delegatecall to pranking feat(cheatcodes): add delegatecall to pranking Sep 30, 2024
@EdwardJES
Copy link
Contributor Author

gentle bump on this @zerosnacks, @DaniPopes . Thank you 🙏

@grandizzy grandizzy self-assigned this Nov 5, 2024
@grandizzy
Copy link
Collaborator

@EdwardJES is there anything waiting from us to unblock the PR or can we start the review? thank you!

@EdwardJES
Copy link
Contributor Author

@grandizzy all good to go, thanks!

@grandizzy grandizzy force-pushed the edwardjes/delegatecall branch from bac569b to 3632509 Compare November 15, 2024 08:51
Copy link
Collaborator

@grandizzy grandizzy left a comment

Choose a reason for hiding this comment

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

looks good, thank you! I rebased and added a negative test (EOA prank), have one comment re handling ExtDelegateCall as well

crates/cheatcodes/src/inspector.rs Outdated Show resolved Hide resolved
@EdwardJES
Copy link
Contributor Author

@grandizzy, thank you for the review and help in rebasing. Added your suggestion 🙏.

@grandizzy grandizzy self-requested a review November 15, 2024 11:03
Copy link
Collaborator

@grandizzy grandizzy left a comment

Choose a reason for hiding this comment

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

lgtm, thank you! pending other reviews before merging

Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

lgtm

@mattsse mattsse merged commit c526cab into foundry-rs:master Nov 15, 2024
21 checks passed
@leovct
Copy link
Contributor

leovct commented Nov 25, 2024

I tried to use this new feature but it doesn't work since I guess it requires an update of forge-std?

Error (9582): Member "startPrank" not found or not visible after argument-dependent lookup in contract Vm.
  --> test/EthernautCTF/DelegationExploit.t.sol:26:5:
   |
26 |     vm.startPrank(exploiter, true);
   |     ^^^^^^^^^^^^^

Error: Compilation failed

@grandizzy
Copy link
Collaborator

indeed, will update and release a version with, thanks for flagging

mds1 pushed a commit to foundry-rs/forge-std that referenced this pull request Nov 25, 2024
- add `delegatecall` flag to `prank` cheatcodes
(foundry-rs/foundry#8863)
- support EIP-7702 Delegations (`create/sign/attachDelegation`)
(foundry-rs/foundry#9236)
- add `contains` to check if a string contains another string
(foundry-rs/foundry#9085)
rplusq pushed a commit to rplusq/foundry that referenced this pull request Nov 29, 2024
* begin api and rough comments

* impl cheatcode

* add check for eoa

* fix eoa check on each prank call

* add to assets

* prank compiling

* delegate call working, storage not upating

* delegate call working, some tidy up

* add prank2 calls

* impl remaining tests

* formatting

* forge fmt

* add pranks to cheatcodes.json

* run cargo cheats

* If verbosity level is 1 or higher, it shows dirty files.

* Fix, add EOA prank test

* Revert "If verbosity level is 1 or higher, it shows dirty files."

This reverts commit d03ac1d.

* Fix test

* apply on extdelegatecall

---------

Co-authored-by: mgiagante <[email protected]>
Co-authored-by: grandizzy <[email protected]>
@grandizzy grandizzy added T-feature Type: feature C-forge Command: forge labels Dec 18, 2024
@varun-doshi
Copy link

Hi
Wondering if delegatePrank is now available? I couldn't find it in the book

@grandizzy
Copy link
Collaborator

@varun-doshi yes it is, book is not updated yet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-forge Command: forge T-feature Type: feature
Projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

feat(cheatcodes): add vm.delegatePrank to execute a delegatecall in the context of the pranked address
7 participants