foundry icon indicating copy to clipboard operation
foundry copied to clipboard

feat(`cheatcodes`): ability to capture and store state diffs

Open sakulstra opened this issue 2 years ago • 9 comments

Component

Forge

Describe the feature you would like

For certain transactions (especially related to DAO governance processes) it makes sense to diff the chain state from before and after a certain tx execution to have a reasonable preview of what the outcome/side effects of a certain action are.

I'm aware this feature can grow to infinite complexity when trying to decode the stateDiffs accross proxy implementations or similar, so for a first iteration i'd suggest to keep it as simple as possible and just track address.key.before/after values and see where we can go from there.

Not quite sure if diffs over multiple txn or overlapping diffs are needed. A simple api could be sth like vm.diff(identifier) which would track state changes of the next txn executed. The identifier could be the file to log to.

As for a more complex api I would imagine sth similar to startPrank api but allowing overlaps.

vm.startStorageDiff('execution');
contract.doSthAwesome();
vm.startStorageDiff('partial');
contract.doSthElse();
vm.stopStorageDiff('partial');
vm.stopStorageDiff('execution');

Additional context

tenderly has a great feature called "State changes" used in aave/unswap seatbelt, which does exactly that (diff the state between before and after a simulation). Would be cool if sth similar or a slimmed down version of this could exist within foundry as foundry & tenderly don't work very well together. For complex scenarios tenderly would probably still be the go-to as they solved state decoding in a relatively reliable way, but for more simple cases it would be cool if one could resort to foundry.

sakulstra avatar Aug 19 '22 14:08 sakulstra