Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Fix slot overwrite on packed variables #118

@wei3erHase

Description

@wei3erHase

Bug description:

PR #117

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions