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

BasicOrder Memory Reuse #54

Merged
merged 2 commits into from
Mar 5, 2024
Merged

BasicOrder Memory Reuse #54

merged 2 commits into from
Mar 5, 2024

Conversation

Saw-mon-and-Natalie
Copy link
Collaborator

@Saw-mon-and-Natalie Saw-mon-and-Natalie commented Mar 4, 2024

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.

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.
@Saw-mon-and-Natalie Saw-mon-and-Natalie changed the title BasicOrder Memory Reuse BasicOrder Memory Reuse Mar 4, 2024
ptr = getFreeMemoryPointer();
// Derive offset to pre `OrderFulfilled`'s spent item event data
// using base offset & total original recipients.
ptr = MemoryPointer.wrap(
Copy link
Contributor

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

Copy link
Collaborator Author

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.

@0age 0age merged commit c10242a into main Mar 5, 2024
4 checks passed
@0age 0age deleted the memory-reuse-basic-order branch March 5, 2024 00:50
unchecked {
// Derive offset to pre `OrderFulfilled`'s spent item event data
// using base offset & total original recipients.
ptr = MemoryPointer.wrap(
Copy link
Collaborator

@MrToph MrToph Mar 5, 2024

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
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants