forked from FuelLabs/sway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds ethAddress type (FuelLabs#1452)
* eth address type * document MemoryOverflow * ecr for eth_address working. * eth -> evm * reference std::vm in sway book * add reference to ethereum address recovery to cryptography docs * make evm specific ecrecover explicit. formatting * Update docs/src/blockchain-development/hashing_and_cryptography.md Co-authored-by: John Adler <[email protected]> * Update docs/src/introduction/standard_library.md Co-authored-by: John Adler <[email protected]> * Update sway-lib-std/src/vm/evm/ecr.sw Co-authored-by: John Adler <[email protected]> * Update sway-lib-std/src/vm/evm/ecr.sw Co-authored-by: John Adler <[email protected]> * Update sway-lib-std/src/vm/evm/evm_address.sw Co-authored-by: John Adler <[email protected]> Co-authored-by: simonr0204 <[email protected]> Co-authored-by: Simon Roberts <[email protected]> Co-authored-by: John Adler <[email protected]>
- Loading branch information
1 parent
38a857f
commit d73d9d2
Showing
10 changed files
with
60 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
library chain; | ||
dep chain/auth; | ||
dep chain/auth; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
library evm_address; | ||
|
||
//! A wrapper around the b256 type to help enhance type-safety. | ||
/// The Address type, a struct wrappper around the inner `value`. | ||
pub struct EvmAddress { | ||
value: b256, | ||
} | ||
|
||
impl core::ops::Eq for EvmAddress { | ||
fn eq(self, other: Self) -> bool { | ||
// An `Address` in Sway is 32 bytes | ||
asm(r1: self, r2: other, result, bytes_to_compare: 32) { | ||
meq result r1 r2 bytes_to_compare; | ||
result: bool | ||
} | ||
} | ||
} | ||
|
||
pub trait From { | ||
fn from(b: b256) -> Self; | ||
} { | ||
fn into(addr: EvmAddress) -> b256 { | ||
addr.value | ||
} | ||
} | ||
|
||
/// Functions for casting between the b256 and Address types. | ||
impl From for EvmAddress { | ||
fn from(bits: b256) -> EvmAddress { | ||
// An EVM address is only 20 bytes, so the first 12 are set to zero | ||
asm(r1: bits) { | ||
mcli r1 i12; | ||
}; | ||
|
||
EvmAddress { | ||
value: bits, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
library evm; | ||
|
||
dep evm_address; | ||
dep ecr; |
8 changes: 1 addition & 7 deletions
8
test/src/sdk-harness/test_artifacts/reentrancy_attacker_contract/src/main.sw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 1 addition & 9 deletions
10
test/src/sdk-harness/test_artifacts/reentrancy_target_contract/src/main.sw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters