-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Migrate slot library to U256 - Use 256 in ERC721Token & ERC20Token - Implement From and Into for U256 type (Bytes32) - Add from_field function for U256
- Loading branch information
Showing
9 changed files
with
223 additions
and
105 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
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,27 +1,25 @@ | ||
use dep::ethereum::misc::{ | ||
types::{Address, Bytes32, ADDRESS_LENGTH, BYTES32_LENGTH}, bytes32::field_to_bytes32, | ||
bytes::add_bigint | ||
}; | ||
use dep::ethereum::misc::types::Bytes32; | ||
use dep::std::hash::keccak256; | ||
use dep::ethereum::uint256::U256; | ||
|
||
global STORAGE_KEY_HASH_INPUT_LENGTH = 64; | ||
|
||
pub(crate) fn mapping(slot: Bytes32, key: Bytes32) -> Bytes32 { | ||
pub(crate) fn mapping(slot: U256, key: Bytes32) -> U256 { | ||
let mut vector: BoundedVec<u8, STORAGE_KEY_HASH_INPUT_LENGTH> = BoundedVec::new(); | ||
vector.extend_from_array(key); | ||
vector.extend_from_array(slot); | ||
keccak256(vector.storage(), STORAGE_KEY_HASH_INPUT_LENGTH) | ||
vector.extend_from_array(U256::into(slot)); | ||
U256::from(keccak256(vector.storage(), STORAGE_KEY_HASH_INPUT_LENGTH)) | ||
} | ||
|
||
pub(crate) fn dynamic_array(slot: Bytes32, size: Field, index: Field) -> Bytes32 { | ||
let start = keccak256(slot, 32); | ||
pub(crate) fn dynamic_array(slot: U256, size: Field, index: Field) -> U256 { | ||
let start: U256 = U256::from(keccak256(U256::into(slot), 32)); | ||
dynamic_array_with_precalculated_slot(start, size, index) | ||
} | ||
|
||
pub(crate) fn dynamic_array_with_precalculated_slot(slot: Bytes32, size: Field, index: Field) -> Bytes32 { | ||
add_bigint(slot, field_to_bytes32(size * index)) | ||
pub(crate) fn dynamic_array_with_precalculated_slot(slot: U256, size: Field, index: Field) -> U256 { | ||
slot + U256::from_field(size * index) | ||
} | ||
|
||
pub(crate) fn struct_slot(slot: Bytes32, offset: Field) -> Bytes32 { | ||
add_bigint(slot, field_to_bytes32(offset)) | ||
pub(crate) fn struct_slot(slot: U256, offset: Field) -> U256 { | ||
slot + U256::from_field(offset) | ||
} |
Oops, something went wrong.