-
Notifications
You must be signed in to change notification settings - Fork 6
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
Update basic order flow to avoid allocating unnecessary memory #45
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -874,35 +874,6 @@ contract BasicOrderFulfiller is OrderValidator { | |
* `keccak256(abi.encodePacked(offerItemHashes))` | ||
*/ | ||
mstore(BasicOrder_order_offerHashes_ptr, keccak256(0, OneWord)) | ||
|
||
/* | ||
* 3. Write SpentItem to offer array in OrderFulfilled event. | ||
*/ | ||
let eventConsiderationArrPtr := | ||
add( | ||
OrderFulfilled_offer_length_baseOffset, | ||
shl( | ||
OneWordShift, | ||
calldataload( | ||
BasicOrder_additionalRecipients_length_cdPtr | ||
) | ||
) | ||
) | ||
|
||
// Set a length of 1 for the offer array. | ||
mstore(eventConsiderationArrPtr, 1) | ||
|
||
// Write itemType to the SpentItem struct. | ||
mstore(add(eventConsiderationArrPtr, OneWord), offeredItemType) | ||
|
||
// Copy calldata region with (offerToken, offerIdentifier, | ||
// offerAmount) from OrderParameters to (token, identifier, | ||
// amount) in SpentItem struct. | ||
calldatacopy( | ||
add(eventConsiderationArrPtr, AdditionalRecipient_size), | ||
BasicOrder_offerToken_cdPtr, | ||
ThreeWords | ||
) | ||
} | ||
} | ||
|
||
|
@@ -1035,6 +1006,21 @@ contract BasicOrderFulfiller is OrderValidator { | |
OrderFulfilled_consideration_body_offset | ||
) | ||
|
||
// Set a length of 1 for the offer array. | ||
mstore(add(eventDataPtr, 0x80), 1) | ||
|
||
// Write itemType to the SpentItem struct. | ||
mstore(add(eventDataPtr, 0xa0), offeredItemType) | ||
|
||
// Copy calldata region with (offerToken, offerIdentifier, | ||
// offerAmount) from OrderParameters to (token, identifier, | ||
// amount) in SpentItem struct. | ||
calldatacopy( | ||
add(eventDataPtr, 0xc0), | ||
Comment on lines
+1010
to
+1019
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. TODO: define named constants for these 3 new offsets. |
||
BasicOrder_offerToken_cdPtr, | ||
ThreeWords | ||
) | ||
Comment on lines
+1009
to
+1022
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. I moved these down here, since it would make it more clear what we are doing in memory and also would require less calculation of the pointer. and automatically the offset is also corrected.
Comment on lines
+1009
to
+1022
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. note for myself: these are all shifted by |
||
|
||
// Derive total data size including SpentItem and ReceivedItem data. | ||
// SpentItem portion is already included in the baseSize constant, | ||
// as there can only be one element in the array. | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -12,6 +12,7 @@ import { | |||||
BasicOrder_offerer_cdPtr, | ||||||
BasicOrder_startTime_cdPtr, | ||||||
BasicOrder_startTimeThroughZoneHash_size, | ||||||
BasicOrder_totalOriginalAdditionalRecipients_cdPtr, | ||||||
Common_amount_offset, | ||||||
Common_identifier_offset, | ||||||
Common_token_offset, | ||||||
|
@@ -613,14 +614,19 @@ contract ConsiderationEncoder { | |||||
tailOffset + BasicOrder_consideration_offset_from_offer | ||||||
); | ||||||
|
||||||
// Retrieve the offset to the length of additional recipients. | ||||||
// Retrieve the length of additional recipients. | ||||||
uint256 additionalRecipientsLength = CalldataPointer.wrap( | ||||||
BasicOrder_additionalRecipients_length_cdPtr | ||||||
).readUint256(); | ||||||
|
||||||
// Retrieve the length of additional recipients. | ||||||
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.
Suggested change
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. can be fixed in a different PR or even this one. |
||||||
uint256 totalOriginalAdditionalRecipientsLength = CalldataPointer.wrap( | ||||||
BasicOrder_totalOriginalAdditionalRecipients_cdPtr | ||||||
).readUint256(); | ||||||
|
||||||
// Derive offset to event data using base offset & total recipients. | ||||||
uint256 offerDataOffset = OrderFulfilled_offer_length_baseOffset | ||||||
+ (additionalRecipientsLength << OneWordShift); | ||||||
+ (totalOriginalAdditionalRecipientsLength << OneWordShift); | ||||||
|
||||||
// Derive size of offer and consideration data. | ||||||
// 2 words (lengths) + 4 (offer data) + 5 (consideration 1) + 5 * ar | ||||||
|
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.
this was wrong, we needed to use: