-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
feat: support evm address #668
Conversation
Needs forc update |
// ANCHOR_END: evm_address | ||
|
||
impl EvmAddress { | ||
fn clear_12_bytes(bytes: [u8; 32]) -> [u8; 32] { |
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.
Since it's private might save space and just make it a fn instead of an associated fn.
Goes without saying that it doesn't make any difference functionally.
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 like that it's an associated function since it's a very specific "utility", it would be weird to see it implemented outside this context.
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.
Looking good, some questions
// ANCHOR_END: evm_address | ||
|
||
impl EvmAddress { | ||
fn clear_12_bytes(bytes: [u8; 32]) -> [u8; 32] { |
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 like that it's an associated function since it's a very specific "utility", it would be weird to see it implemented outside this context.
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 think we should make it clearer if we're going with the leftmost clearing just by convention or specs. Otherwise great!
{{#include ../../../packages/fuels/tests/bindings.rs:evm_address_arg}} | ||
``` | ||
|
||
> **Note:** when creating an `EvmAddress` from `Bits256`, the first 12 bytes will be cleared because an evm address is only 20 bytes long. |
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.
Explain the choice of clearing the leftmost ones. If it is a deliberate choice (ie not based on spec), then this choice should be stated clearly ("We chose the convention of clearing the leftmost bytes").
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.
The choice was made based on the Sway implementation of the same type. I find this a bit tricky to comment since we had a task to specifically remove all mentions of sway.
Co-authored-by: iqdecay <victor@berasconsulting.com>
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.
LGTM. Good work! Left just a tiny comment.
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.
Very nice!
Closes #661
The
EvmAddress
is implemented equivalent to the Sway type, as a wrapper overBits256
. And just like in Sway, the first 12 bytes are zeroed out when it is instantiated fromBits256
.Encoding/decoding this type is treated as a struct with a single
Bits256
field.