foundry icon indicating copy to clipboard operation
foundry copied to clipboard

Disallow some cheatcodes for precompiles

Open onbjerg opened this issue 2 years ago • 2 comments

I think we should disallow vm.etch for addresses 0 < n < 10, and throw an error about using an address >10.

I prefer breaking these early and getting "correct" behavior vs hacking something on Revm.

(This should be fine for transfers etc on the <10 addresses and seems only a vm.etch issue?)

Originally posted by @gakonst in https://github.com/gakonst/foundry/issues/1146#issuecomment-1084837454

Worth considering disallowing other cheatcodes for those addresses. It's not realistic to prank that address or mockCall with it, and you also don't want to save or load slots from there, for example.

As for what addresses to block off, to be safe we might also want to:

  • Disallow a larger range, such as 0 < n < 99 to account for precompiles being added or other EVM chains that have additional precompiles
  • Prevent etching at addresses that other chains have predeployed contracts at. For example Optimism has predeployed contracts at 0x420...000 < n < 0x420...013, not sure about other networks offhand

Originally posted by @mds1 in https://github.com/gakonst/foundry/issues/1146#issuecomment-1084848530

This is a breaking change

onbjerg avatar Mar 31 '22 17:03 onbjerg

One observation is that vm.prank from such addresses is only problematic if you are calling a function that expects the caller to be an EOA. For example if it has code like payable(msg.sender).transfer(). So for some tests, I can actually use cheat codes like prank from these and it's fine. If we stop pranking from them entirely, then would it be preventing people from testing things they might actually want to test?

An alternative might be to issue a warning when this is seen, instead of disallowing.

Also, I've noticed a few other addresses have been problematic in my tests that might be worth adding to this list:

        address(0xCe71065D4017F316EC606Fe4422e11eB2c47c246), // FuzzerDict
        address(0x4e59b44847b379578588920cA78FbF26c0B4956C), // CREATE2 Factory (?)
        address(0xb4c79daB8f259C7Aee6E5b2Aa729821864227e84), // address(this)
        address(0x185a4dc360CE69bDCceE33b3784B0282f7961aea), // ???
        address(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D) // ???

varunsrin avatar Aug 26 '22 18:08 varunsrin

For reference:

  • 0x185a4dc360CE69bDCceE33b3784B0282f7961aea is the default sender account: https://github.com/foundry-rs/foundry/blob/307576dfb9e94536177e940c2710045ada69d8d7/evm/src/lib.rs#L33-L42
  • 0x7109709ECfa91a80626fF3989D68f67F5b1DD12D is the cheatcode address: https://github.com/foundry-rs/foundry/blob/307576dfb9e94536177e940c2710045ada69d8d7/evm/src/executor/abi/mod.rs#L5-L12

Also, the last 4 addresses in the above comment should probably all have default labels set if they don't already.

mds1 avatar Aug 28 '22 21:08 mds1