defi-wonderland / smock

The Solidity mocking library
MIT License
319 stars 40 forks source link

bounty: fix slot overwrite bug on packed variables #117

Open wei3erHase opened 2 years ago

wei3erHase commented 2 years ago

Bug description:

When variables are declared nearby (sometimes either in other abstract contract, but close on declaration order), using the setVariable method on one, can erase the information about the other variable.

contract Bug {
  address public myAddress;
  bool public myBool;
}
await bug.setVariable('myAddress', randomAddress)
await bug.setVariable('myBool', true)

console.log(await bug.myAddress()) // => 0x0000...

Given that myAddress (that occupies ~uint160) and myBool are stored together, the second setVariable method aims to the entire data slot and overwrites it with 0x0000...1 (true), and when the myAddress slot is fetched, is filled with 0s.

An example contract is added, and a test replicating the descripted bug.