forge-std icon indicating copy to clipboard operation
forge-std copied to clipboard

feat(stdStorage): Allow writing to a packed storage slot

Open brockelmore opened this issue 3 years ago • 4 comments

Adds the ability to write to a packed storage slot. The caveats being:

  1. Only one slot is read (probably can be lifted in the future but not entirely sure)
  2. the user enables it via stdstorage.enabledPackedSlots(true)... (default off as to not blow up the call trace)

would be nice to use a binary search in the future for internal slot search (leftBits and rightBits).

It does protect against writing too large of a value to the internal slot (i.e. a 16 bit into an 8 bit allocation)

Also enabled the ability to do with_calldata which lets the user specify exactly what calldata to pass to the function, instead of using keys (lets users do lists and the like)

brockelmore avatar Aug 07 '22 22:08 brockelmore

Wow! So far I've noticed checked_write turns a packed bool from false -> true but not true -> false - have not investigated yet.

Also enabled the ability to do with_calldata

This was needed!

ZeroEkkusu avatar Aug 11 '22 21:08 ZeroEkkusu

Pushed a commit which adds a failing test, possibly related to what @ZeroEkkusu mentioned. Didn't try debugging yet, but it really does bloat the trace 😅

mds1 avatar Aug 13 '22 00:08 mds1

Probably should change them all to camelCase for consistency with the rest of forge-std cheat names, but doing so would be a breaking change so I think we leave the names for now and consider changing it for the v0.3 branch

mds1 avatar Aug 13 '22 16:08 mds1

Just to clarify, this PR adds functions with camelCase naming, but the existing ones are snake_case.

stdstore
    .enablePackedSlots(true)
    .target(t)
    .sig(s)
    .checked_write(v)

ZeroEkkusu avatar Aug 17 '22 15:08 ZeroEkkusu

Superceded by https://github.com/foundry-rs/forge-std/pull/505

mds1 avatar Apr 25 '24 12:04 mds1