Skip to content

Delegatecall from any contract. A kind of vm.prank for delegatecalls.

License

Notifications You must be signed in to change notification settings

adhusson/delegate-prank

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Delegatecall from any contract.

Make arbitrary delegatecalls to an implementation contract.

Supplements vm.prank.

Install:

$ forge install adhusson/delegate-prank

How to use:

You already know how to make an address c call dest.fn(args):

vm.prank(c);
dest.fn(args);

Now you can make c delegatecall dest.fn(args):

delegatePrank(c,address(dest),abi.encodeCall(dest.fn,(args)));

It works by swapping the bytecode of the pranked address with a delegator contract.

Cool things:

  • The bytecode is swapped back on the fly, so you can never tell your bytecode got changed. This means reentrancy works.
  • You can still vm.prank before using delegatePrank

In-context example

import {DelegatePrank} from "delegate-prank/DelegatePrank.sol";

contract MyTest is Test, DelegatePrank {

  address multisig;
  Spell spell;

  ...

  function test_one() public {
    bytes memory cd = abi.encodeCall(spell.execute,());
    delegatePrank(multisig,address(spell),cd);
  }

}

Notes

Thanks to @ckksec for the idea of restoring the bytecode automatically!

About

Delegatecall from any contract. A kind of vm.prank for delegatecalls.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published