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

Dynamically sized return support for external calls #415

Merged
merged 1 commit into from
May 26, 2021

Conversation

g-r-a-n-t
Copy link
Member

@g-r-a-n-t g-r-a-n-t commented May 21, 2021

What was wrong?

closes #405
closes #400
closes #321

I also noticed that there was a bug preventing us from calling functions on contract fields (e.g. self.my_contract).

How was it fixed?

Used returndatasize and returndatacopy to deal with sizes that aren't known at compile-time (it's now much simpler).

See the note at the bottom of this section:

The call* instructions use the out and outsize parameters to define an area in memory where the return or failure data is placed. This area is written to depending on how many bytes the called contract returns. If it returns more data, only the first outsize bytes are written. You can access the rest of the data using the returndatacopy opcode. If it returns less data, then the remaining bytes are not touched at all. You need to use the returndatasize opcode to check which part of this memory area contains the return data. The remaining bytes will retain their values as of before the call.

To-Do

  • OPTIONAL: Update Spec if applicable

  • Add entry to the release notes (may forgo for trivial changes)

  • Clean up commit history

// We must ensure the expression is loaded onto the stack.
context
.borrow_mut()
.update_expression(value, value_attributes.clone().into_loaded()?);
Copy link
Member Author

Choose a reason for hiding this comment

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

Originally, calls to contract fields would fail (e.g. self.foo.get_my_string()). This is because the call was being made to a non-existent contract at the address of the last 20 bytes of the storage pointer.

@g-r-a-n-t g-r-a-n-t requested a review from cburgdorf May 25, 2021 18:59
Copy link
Collaborator

@cburgdorf cburgdorf left a comment

Choose a reason for hiding this comment

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

Adding features by simplifying the code, I like!

@cburgdorf cburgdorf merged commit ddd4f0a into ethereum:master May 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment