Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean dirty addresses and booleans #5195

Merged
merged 4 commits into from
Sep 18, 2024

Conversation

cairoeth
Copy link
Contributor

Fixes M-01

PR Checklist

  • Tests
  • Documentation
  • Changeset entry (run npx changeset add)

Copy link

changeset-bot bot commented Sep 11, 2024

⚠️ No Changeset found

Latest commit: ec6d27d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@@ -10,6 +10,13 @@ import {SlotDerivation} from "@openzeppelin/contracts/utils/SlotDerivation.sol";
contract SlotDerivationTest is Test, SymTest {
using SlotDerivation for bytes32;

function testDirtyAddress() public {
bytes32 result1 = SlotDerivation.deriveMapping(0, address(uint160(type(uint256).max)));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not contain dirty upper bits. The casting to uint160 cleans it.

Copy link
Contributor Author

@cairoeth cairoeth Sep 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only when stored in memory explicitly afaik -- https://x.com/optimizoor/status/1560590413768994816?s=46. test reverts with current master behaviour.

Copy link
Collaborator

@Amxx Amxx Sep 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, good to know. That means its actually possible to generate dirty bytes without assembly !

I changed the tests to something that is clearer IMO, and that support dirtying any type (bool, addres, anything else we want to add)

Copy link
Member

@ernestognw ernestognw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit if you're eager to discuss. LGTM

scripts/generate/helpers/sanitize.js Show resolved Hide resolved
@cairoeth cairoeth merged commit 3f90169 into OpenZeppelin:master Sep 18, 2024
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants