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

sb-i74 #325

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_permit.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
79506
79595
Original file line number Diff line number Diff line change
@@ -1 +1 @@
62394
62483
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_permit_twice.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
45282
45371
5 changes: 5 additions & 0 deletions src/base/EIP712_v4.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ contract EIP712_v4 is IEIP712_v4 {
mstore(add(fmp, 0x02), domainSeparator)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hensha256 when is it left packed vs right packed?

Copy link
Contributor

Choose a reason for hiding this comment

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

bytes are left-aligned, numbers and addresses are right-aligned. So the line above this

      mstore(fmp, hex"1901")

stores 0x1901 in [fmp..fmp+2)
whereas if you wrote

      mstore(fmp, 6401)     // 6401 == 0x1901

it would right align it into [fmp+30..fmp+32)

Copy link
Contributor

Choose a reason for hiding this comment

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

In fact even just mstore(fmp, 0x1901) would right align it because 0x1901 gets compiled as a number. You have to write hex"1901" for it to compile it as bytes and left-align

mstore(add(fmp, 0x22), dataHash)
digest := keccak256(fmp, 0x42)

// now clean the memory we used
mstore(fmp, 0) // fmp held "\x19\x01", domainSeparator
mstore(add(fmp, 0x20), 0) // fmp+0x20 held domainSeparator, dataHash
mstore(add(fmp, 0x40), 0) // fmp+0x40 held dataHash
}
}
}
14 changes: 14 additions & 0 deletions src/libraries/ERC721PermitHash.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ library ERC721PermitHashLibrary {
mstore(add(fmp, 0x60), nonce)
mstore(add(fmp, 0x80), deadline)
digest := keccak256(fmp, 0xa0)

// now clean the memory we used
mstore(fmp, 0) // fmp held PERMIT_TYPEHASH
mstore(add(fmp, 0x20), 0) // fmp+0x20 held spender
mstore(add(fmp, 0x40), 0) // fmp+0x40 held tokenId
mstore(add(fmp, 0x60), 0) // fmp+0x60 held nonce
mstore(add(fmp, 0x80), 0) // fmp+0x80 held deadline
}
}

Expand All @@ -39,6 +46,13 @@ library ERC721PermitHashLibrary {
mstore(add(fmp, 0x60), nonce)
mstore(add(fmp, 0x80), deadline)
digest := keccak256(fmp, 0xa0)

// now clean the memory we used
mstore(fmp, 0) // fmp held PERMIT_FOR_ALL_TYPEHASH
mstore(add(fmp, 0x20), 0) // fmp+0x20 held operator
mstore(add(fmp, 0x40), 0) // fmp+0x40 held approved
mstore(add(fmp, 0x60), 0) // fmp+0x60 held nonce
mstore(add(fmp, 0x80), 0) // fmp+0x80 held deadline
}
}
}
Loading