Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

EIP-211 RETURNDATACOPY and RETURNDATASIZE #5678

Merged
merged 3 commits into from Jun 6, 2017
Merged

EIP-211 RETURNDATACOPY and RETURNDATASIZE #5678

merged 3 commits into from Jun 6, 2017

Conversation

arkpar
Copy link
Collaborator

@arkpar arkpar commented May 22, 2017

@arkpar arkpar added A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. M4-core ⛓ Core client code / Rust. labels May 22, 2017
@arkpar arkpar force-pushed the eip211 branch 2 times, most recently from ad57684 to a327c9d Compare May 30, 2017 10:55
@arkpar arkpar added A0-pleasereview 🤓 Pull request needs code review. and removed A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. labels May 30, 2017
}
/// Create `ReturnData` from give buffer and slice.
pub fn new(mem: Vec<u8>, offset: usize, size: usize) -> Self {
ReturnData {
Copy link
Contributor

@rphmeier rphmeier May 30, 2017

Choose a reason for hiding this comment

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

should probably truncate the allocation here to just size to alleviate peak memory usage concerns. At least, how I understand the code is that currently all calls returning data will have their entire memory kept around as opposed to just the requested amount. I'm not aware of a fast way to do it safely, though.

let _ = mem.drain(..offset); mem.truncate(size); mem.shrink_to_fit() might be a lot of work to do on every return.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated. Now it reallocates but only if too much memory is wasted.

@rphmeier rphmeier added A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. A0-pleasereview 🤓 Pull request needs code review. and removed A0-pleasereview 🤓 Pull request needs code review. A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. labels May 30, 2017
@rphmeier
Copy link
Contributor

where is the implementation of RETURNDATASIZE? I don't see it when searching the diff

@arkpar arkpar added A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. and removed A0-pleasereview 🤓 Pull request needs code review. labels May 30, 2017
@arkpar
Copy link
Collaborator Author

arkpar commented May 30, 2017

@rphmeier It was missing :) Added now

@arkpar arkpar added A0-pleasereview 🤓 Pull request needs code review. and removed A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. labels May 30, 2017
return ReturnData::empty()
}
if self.len() - size > MAX_RETURN_WASTE_BYTES {
let mem = self.drain(offset..).take(size).collect();
Copy link
Contributor

@rphmeier rphmeier May 30, 2017

Choose a reason for hiding this comment

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

i really doubt the optimizer is smart enough to turn this into a single malloc + memmove, so it ends up paying both the O(n) iteration and having to allocate self.len() + size bytes in total.

i would suggest either using a drain, truncate, shrink_to_fit combo or allocating a vec![0; size] and using copy_from_slice to pay only one of those costs.

Copy link
Contributor

Choose a reason for hiding this comment

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

(unless the optimized IR/ASM shows that this is actually a non-issue)

fn into_return_data(mut self, offset: U256, size: U256) -> ReturnData {
let offset = offset.low_u64() as usize;
let size = size.low_u64() as usize;
if !is_valid_range(offset, size) {
Copy link
Contributor

@rphmeier rphmeier May 30, 2017

Choose a reason for hiding this comment

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

this just checks whether offset + size would overflow, but they should also be bounds-checked against self.len() at this point.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Memory is guaranteed to be allocated at this point. This is assured by mem/gas requirements checking before each instruction. That's why none of the methods in this struct check for bounds.

@arkpar arkpar changed the title EIP-211 EIP-211 RETURNDATACOPY and RETURNDATASIZE May 30, 2017
@rphmeier rphmeier added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels May 30, 2017
@NikVolf
Copy link
Contributor

NikVolf commented May 30, 2017

lgtm as well

@arkpar arkpar mentioned this pull request May 31, 2017
12 tasks
@NikVolf NikVolf merged commit 99bfef2 into master Jun 6, 2017
@NikVolf NikVolf deleted the eip211 branch June 6, 2017 15:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well. M4-core ⛓ Core client code / Rust.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants