-
Notifications
You must be signed in to change notification settings - Fork 187
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
Finish buf refactor #917
Conversation
0bf96fd
to
4e29dc5
Compare
4e29dc5
to
9896787
Compare
@@ -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 { |
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.
Why does this need to be unsafe
?
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.
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
crates/library/std/src/evm.fe
Outdated
} | ||
|
||
pub fn eq(_ x: u256, _ y: u256) -> u256 { | ||
unsafe { return __eq(x, y) } | ||
unsafe { return __eq(x, y) } |
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.
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 { |
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.
I guess these functions are made for scenarios where manual memory allocation is required (for example in precompiles.fe)
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.
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) { |
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.
There are more functions that accept immutable buf
s (e.g call_data_copy
, log
, return_mem
), do we need to change those also ?
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.
call_data_copy
?? typo?
the other ones are not writing to the buf, so they can stay as immutable
9896787
to
bd4bad6
Compare
What was wrong?
There were still some
std::evm
functions that used memory offset and length parameters instead ofMemoryBuffer
.How was it fixed?
To-Do