-
Notifications
You must be signed in to change notification settings - Fork 841
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
Add function to directly set extra data #336
Merged
Vectorized
merged 8 commits into
chiru-labs:main
from
Vectorized:feature/directExtraData
Jun 15, 2022
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cea414b
Add setExtraDataAt
Vectorized aca88a8
Remove unused test variables
Vectorized f64f2c4
Add comments
Vectorized debfcaf
Remove redundant assembly
Vectorized 129ec8b
Remove redundant assembly
Vectorized 1de253a
Remove redundant assembly
Vectorized e0053ba
Lint
Vectorized 68c6514
Lint
Vectorized File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,9 +59,12 @@ contract ERC721A is IERC721A { | |
// The bit position of `extraData` in packed ownership. | ||
uint256 private constant BITPOS_EXTRA_DATA = 232; | ||
|
||
// Mask of all 256 bits in a packed ownership except the 24 bits for `extraData`. | ||
uint256 private constant BITMASK_EXTRA_DATA_COMPLEMENT = (1 << 232) - 1; | ||
|
||
// The mask of the lower 160 bits for addresses. | ||
uint256 private constant BITMASK_ADDRESS = (1 << 160) - 1; | ||
|
||
// The maximum `quantity` that can be minted with `_mintERC2309`. | ||
// This limit is to prevent overflows on the address data entries. | ||
// For a limit of 5000, a total of 3.689e15 calls to `_mintERC2309` | ||
|
@@ -208,8 +211,8 @@ contract ERC721A is IERC721A { | |
function _setAux(address owner, uint64 aux) internal { | ||
uint256 packed = _packedAddressData[owner]; | ||
uint256 auxCasted; | ||
// Cast `aux` with assembly to avoid redundant masking. | ||
assembly { | ||
// Cast aux without masking. | ||
auxCasted := aux | ||
} | ||
packed = (packed & BITMASK_AUX_COMPLEMENT) | (auxCasted << BITPOS_AUX); | ||
|
@@ -763,6 +766,21 @@ contract ERC721A is IERC721A { | |
} | ||
} | ||
|
||
/** | ||
* @dev Directly sets the extra data for the ownership data `index`. | ||
*/ | ||
function _setExtraDataAt(uint256 index, uint24 extraData) internal { | ||
uint256 packed = _packedOwnerships[index]; | ||
if (packed == 0) revert OwnershipNotInitializedForExtraData(); | ||
uint256 extraDataCasted; | ||
// Cast `extraData` with assembly to avoid redundant masking. | ||
assembly { | ||
extraDataCasted := extraData | ||
} | ||
packed = (packed & BITMASK_EXTRA_DATA_COMPLEMENT) | (extraDataCasted << BITPOS_EXTRA_DATA); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious, is this cheaper to do in assembly? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope. That's why I removed it. |
||
_packedOwnerships[index] = packed; | ||
} | ||
|
||
/** | ||
* @dev Returns the next extra data for the packed ownership data. | ||
* The returned result is shifted into position. | ||
|
@@ -771,12 +789,9 @@ contract ERC721A is IERC721A { | |
address from, | ||
address to, | ||
uint256 prevOwnershipPacked | ||
) internal view virtual returns (uint256) { | ||
uint24 previousExtraData; | ||
assembly { | ||
previousExtraData := shr(BITPOS_EXTRA_DATA, prevOwnershipPacked) | ||
} | ||
return uint256(_extraData(from, to, previousExtraData)) << BITPOS_EXTRA_DATA; | ||
) private view returns (uint256) { | ||
uint24 extraData = uint24(prevOwnershipPacked >> BITPOS_EXTRA_DATA); | ||
return uint256(_extraData(from, to, extraData)) << BITPOS_EXTRA_DATA; | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessarily specific to this PR, but we use
index
andtokenId
to access _packedOwnerships. We should probably make these consistent in a a future PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
index
refers to something that may not be initialized, and will expose the user to the underlying logic.tokenId
refers to something that is initialized.