foundry-rs / forge-std

Forge Standard Library is a collection of helpful contracts for use with forge and foundry. It leverages forge's cheatcodes to make writing tests easier and faster, while improving the UX of cheatcodes. For more in-depth usage examples checkout the tests.
Apache License 2.0
850 stars 335 forks source link

fix(StdStorage): check last read slots first #581

Closed klkvr closed 4 months ago

klkvr commented 4 months ago

simple optimization which resolves https://github.com/foundry-rs/forge-std/issues/580 and optimizes slots detection in some cases

It is more likely that slot we are looking for will be one of latest sloads. e.g. if execution went like

sload slot_1 <- currently we start from here
sload slot_2
sload slot_3 <- in most of the cases this value is returned
return

so this PR simply changes order in which we go through vm.accesses output