-
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
BasicOrder
Memory Reuse
#54
Conversation
Avoid copying spent items and received items from memory to memory for restricted orders when one is calling the zone's `authorizeOrder` and `validateOrder` instead populate the data in the memory region before and after the spend items and received items used for the `OrderFulfilled`'s event data.
ptr = getFreeMemoryPointer(); | ||
// Derive offset to pre `OrderFulfilled`'s spent item event data | ||
// using base offset & total original recipients. | ||
ptr = MemoryPointer.wrap( |
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 could be unchecked; if totalOriginalAdditionalRecipients is big enough to overflow the addition or zero out the shift, then it'd fail the hash derivation that goes down prior to reaching here
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.
fixed it in the next commit.
unchecked { | ||
// Derive offset to pre `OrderFulfilled`'s spent item event data | ||
// using base offset & total original recipients. | ||
ptr = MemoryPointer.wrap( |
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.
note for myself: The original eventDataPtr
is @ OrderFulfilled_baseOffset=0x200 + BasicOrder_totalOriginalAdditionalRecipients_cdPtr * 0x20
. Here we go to authorizeOrder_calldata_baseOffset=0x80 + BasicOrder_totalOriginalAdditionalRecipients_cdPtr * 0x20
. So we're 0x180 in front of it, which is what we want.
* the layout of that event data changes. | ||
* and encodes it as `authorizeOrder` calldata. Note that memory data is reused | ||
* from `OrderFulfilled` event data, and the rest of the calldata is prefixed and | ||
* postfixed to this memory region. Importantly the memory region before the |
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.
Importantly the memory region before the
OrderFulfilled
's spent and received items are overwritten
why is it safe to do that? @Saw-mon-and-Natalie
Avoid copying spent items and received items from memory to memory for restricted orders when one is calling the zone's
authorizeOrder
andvalidateOrder
instead populate the data in the memory region before and after the spend items and received items used for theOrderFulfilled
's event data.