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

Finish buf refactor #917

Merged
merged 1 commit into from
Aug 28, 2023
Merged

Conversation

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

@g-r-a-n-t g-r-a-n-t commented Aug 23, 2023

What was wrong?

There were still some std::evm functions that used memory offset and length parameters instead of MemoryBuffer.

How was it fixed?

To-Do

  • OPTIONAL: Update Spec if applicable
  • Add entry to the release notes (may forgo for trivial changes)
  • Clean up commit history

@g-r-a-n-t g-r-a-n-t force-pushed the finish-buf-refactor branch 3 times, most recently from 0bf96fd to 4e29dc5 Compare August 24, 2023 20:23
crates/library/std/src/evm.fe Outdated Show resolved Hide resolved
crates/library/std/src/evm.fe Outdated Show resolved Hide resolved
@@ -112,7 +112,7 @@ pub struct MemoryBuffer {
}

/// The start of the buffer in EVM memory.
pub fn offset(self) -> u256 {
pub unsafe fn offset(self) -> u256 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why does this need to be unsafe ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Im not sure if it needs to be and we can always change it back. it's kind of like getting a raw pointer tho, so I figure it should be unsafe

}

pub fn eq(_ x: u256, _ y: u256) -> u256 {
unsafe { return __eq(x, y) }
unsafe { return __eq(x, y) }
Copy link
Collaborator

Choose a reason for hiding this comment

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

inconsistency ?

unsafe { return __staticcall(gas, u256(addr), buf.offset(), buf.input_len(), buf.offset(), buf.output_len()) == 1 }
}

pub unsafe fn call_2(gas: u256, addr: address, value: u256, input_offset: u256, input_len: u256, output_offset: u256, output_len: u256) -> bool {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess these functions are made for scenarios where manual memory allocation is required (for example in precompiles.fe)

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, I spent a decent amount of time trying to figure out how to make a low-cost abstraction for static_call usage in precompiles with RawCallBuffer, but just couldnt make it work, so I ended up doing this

@@ -238,40 +238,40 @@ pub unsafe fn call_data_size() -> u256 {
return __calldatasize()
}

pub fn call_data_copy(buf: MemoryBuffer, from_offset f: u256) {
unsafe { __calldatacopy(buf.offset(), f, buf.len()) }
pub fn call_data_copy(mut buf: MemoryBuffer, from_offset f: u256) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

There are more functions that accept immutable bufs (e.g call_data_copy, log , return_mem), do we need to change those also ?

Copy link
Member Author

Choose a reason for hiding this comment

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

call_data_copy?? typo?

the other ones are not writing to the buf, so they can stay as immutable

@g-r-a-n-t g-r-a-n-t merged commit 0b0172a into ethereum:master Aug 28, 2023
7 checks passed
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.

2 participants