diff --git a/ethereum/circuits/lib/src/uint256.nr b/ethereum/circuits/lib/src/uint256.nr index 1a2bb215..b9c030bb 100644 --- a/ethereum/circuits/lib/src/uint256.nr +++ b/ethereum/circuits/lib/src/uint256.nr @@ -1,4 +1,7 @@ use dep::std::ops::Add; +use crate::misc::types::Bytes32; +use crate::misc::bytes32::field_to_bytes32; +use crate::misc::arrays::memcpy_up_to_length; global uint128_overflow_value = 340282366920938463463374607431768211456; // 2^128 @@ -19,6 +22,38 @@ impl U256 { fn one() -> Self { Self { high: U128::from_integer(0), low: U128::from_integer(1) } } + + fn from_field(field: Field) -> Self { + U256::from(field_to_bytes32(field)) + } +} + +impl From for U256 { + fn from(bytes: Bytes32) -> Self { + let mut high_bytes = [0; 16]; + memcpy_up_to_length(&mut high_bytes, bytes, 16, 16); + let high = U128::from_le_bytes(high_bytes); + + let mut low_bytes = [0; 16]; + memcpy_up_to_length(&mut low_bytes, bytes, 0, 16); + let low = U128::from_le_bytes(low_bytes); + + U256::new(high, low) + } +} + +impl Into for U256 { + fn into(self) -> Bytes32 { + let mut bytes = [0; 32]; + memcpy_up_to_length(&mut bytes, self.low.to_le_bytes(), 0, 16); + + let high_bytes = self.high.to_le_bytes(); + for i in 0..16 { + bytes[i + 16] = high_bytes[i]; + } + + bytes + } } impl Eq for U256 { diff --git a/ethereum/circuits/lib/src/uint256_test.nr b/ethereum/circuits/lib/src/uint256_test.nr index 175ff768..32c47e54 100644 --- a/ethereum/circuits/lib/src/uint256_test.nr +++ b/ethereum/circuits/lib/src/uint256_test.nr @@ -30,6 +30,64 @@ fn zero_and_one() { assert_eq(one.low, U128::one()); } +mod from_bytes32 { + use crate::uint256::U256; + global high = U128::from_integer(0x10000000000000000000000000000000); + global low = U128::zero(); + global limit = U128::from_integer(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); + + global big_number = U256 { high, low }; + global limit_u256 = U256 {high: limit, low:limit}; + + #[test] + fn zero() { + let bytes = [0x00; 32]; + assert_eq(U256::from(bytes), U256::zero()); + } + + #[test] + fn success() { + let mut bytes = [0x00; 32]; + bytes[31] = 0x10; + assert_eq(U256::from(bytes), big_number); + } + + #[test] + fn u256_limit() { + let bytes = [0xff; 32]; + assert_eq(U256::from(bytes), limit_u256); + } +} + +mod into_bytes32 { + use crate::uint256::U256; + global high = U128::from_integer(0x10000000000000000000000000000000); + global low = U128::zero(); + global limit = U128::from_integer(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); + + global big_number = U256 { high, low }; + global limit_u256 = U256 {high: limit, low:limit}; + + #[test] + fn zero() { + let bytes = [0x00; 32]; + assert_eq(U256::into(U256::zero()), bytes); + } + + #[test] + fn success() { + let mut bytes = [0x00; 32]; + bytes[31] = 0x10; + assert_eq(U256::into(big_number), bytes); + } + + #[test] + fn u256_limit() { + let bytes = [0xff; 32]; + assert_eq(U256::into(limit_u256), bytes); + } +} + #[test] fn eq() { assert_eq(big_number, big_number); @@ -47,23 +105,32 @@ fn not_eq() { assert(big_number != big_number3); } -#[test] -fn sum() { - let sum = big_number + big_number; +mod trait_add { + use crate::uint256::U256; + global high = U128::from_integer(0x10000000000000000000000000000000); + global low = U128::zero(); + global limit = U128::from_integer(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); - assert_eq(sum, U256 { high: U128::from_integer(0x20000000000000000000000000000000), low }); -} + global big_number = U256 { high, low }; + global limit_u256 = U256 {high: limit, low:limit}; -#[test] -fn sum_with_carry() { - let big_number = U256 { high, low: limit }; - let sum = big_number + U256::one(); + #[test] + fn sum() { + let sum = big_number + big_number; - assert_eq(sum, U256 { high: U128::from_integer(0x10000000000000000000000000000001), low }); -} + assert_eq(sum, U256 { high: U128::from_integer(0x20000000000000000000000000000000), low }); + } + + #[test] + fn sum_with_carry() { + let big_number = U256 { high, low: limit }; + let sum = big_number + U256::one(); + + assert_eq(sum, U256 { high: U128::from_integer(0x10000000000000000000000000000001), low }); + } -#[test(should_fail_with="attempt to add with overflow")] -fn sum_overflow() { - let limit_number = U256 { high: limit, low: limit }; - let _ = limit_number + U256::one(); + #[test(should_fail_with="attempt to add with overflow")] + fn sum_overflow() { + let _ = limit_u256 + U256::one(); + } } diff --git a/vlayer/ethereum/circuits/lib/src/nft.nr b/vlayer/ethereum/circuits/lib/src/nft.nr index 9b50b6de..f0ec12d5 100644 --- a/vlayer/ethereum/circuits/lib/src/nft.nr +++ b/vlayer/ethereum/circuits/lib/src/nft.nr @@ -1,11 +1,12 @@ use dep::ethereum::{ account_with_storage::get_account_with_storage, - misc::types::{Address, Bytes32, ADDRESS_LENGTH, BYTES32_LENGTH}, misc::arrays::subarray_inferred_len + misc::{types::{Address, Bytes32, ADDRESS_LENGTH, BYTES32_LENGTH}, arrays::subarray_inferred_len}, + uint256::U256 }; struct ERC721Token { address: Address, - token_id_to_slot: fn (Bytes32) -> Bytes32, + token_id_to_slot: fn (Bytes32) -> U256, chain_id: Field } @@ -16,7 +17,7 @@ trait ERC721 { impl ERC721 for ERC721Token { fn get_owner(self, token_id: Bytes32, block_number: u64) -> Address { let storage_key = (self.token_id_to_slot)(token_id); - let account = get_account_with_storage(self.chain_id, block_number, self.address, storage_key); + let account = get_account_with_storage(self.chain_id, block_number, self.address, U256::into(storage_key)); subarray_inferred_len(account.values[0], BYTES32_LENGTH - ADDRESS_LENGTH) } } diff --git a/vlayer/ethereum/circuits/lib/src/nft_list.nr b/vlayer/ethereum/circuits/lib/src/nft_list.nr index dcee23f5..9f554058 100644 --- a/vlayer/ethereum/circuits/lib/src/nft_list.nr +++ b/vlayer/ethereum/circuits/lib/src/nft_list.nr @@ -3,7 +3,7 @@ mod mainnet { use crate::chain_id; use crate::slot::{struct_slot, dynamic_array_with_precalculated_slot, mapping}; use dep::std::field::bytes32_to_field; - use dep::ethereum::misc::{types::Bytes32, bytes32::field_to_bytes32}; + use dep::ethereum::{misc::{types::Bytes32, bytes32::field_to_bytes32}, uint256::U256}; pub fn BORED_APE_YACHT_CLUB() -> ERC721Token { ERC721Token { @@ -12,9 +12,9 @@ mod mainnet { ], token_id_to_slot: |token_id| { let BORED_APE_YACHT_CLUB_MAX_TOKEN_ID: u64 = 9999; - let BORED_APE_YACHT_CLUB_TOKEN_OWNERS_INNER_ENTRIES_SLOT = [ + let BORED_APE_YACHT_CLUB_TOKEN_OWNERS_INNER_ENTRIES_SLOT = U256::from([ 0x40, 0x57, 0x87, 0xfa, 0x12, 0xa8, 0x23, 0xe0, 0xf2, 0xb7, 0x63, 0x1c, 0xc4, 0x1b, 0x3b, 0xa8, 0x82, 0x8b, 0x33, 0x21, 0xca, 0x81, 0x11, 0x11, 0xfa, 0x75, 0xcd, 0x3a, 0xa3, 0xbb, 0x5a, 0xce - ]; + ]); let VALUE_INDEX = 1; assert(bytes32_to_field(token_id) as u64 <= BORED_APE_YACHT_CLUB_MAX_TOKEN_ID, "Token ID is too high"); @@ -32,7 +32,7 @@ mod mainnet { ], token_id_to_slot: |token_id| { let CRYPTO_PUNK_MAX_TOKEN_ID: u64 = 9999; - let CRYPTO_PUNK_TOKEN_OWNERS_INNER_ENTRIES_SLOT = field_to_bytes32(10); + let CRYPTO_PUNK_TOKEN_OWNERS_INNER_ENTRIES_SLOT = U256::from_field(10); assert(bytes32_to_field(token_id) as u64 <= CRYPTO_PUNK_MAX_TOKEN_ID, "Token ID is too high"); mapping(CRYPTO_PUNK_TOKEN_OWNERS_INNER_ENTRIES_SLOT, token_id) @@ -47,7 +47,7 @@ mod sepolia { use crate::chain_id; use crate::slot::{struct_slot, dynamic_array_with_precalculated_slot}; use dep::std::field::bytes32_to_field; - use dep::ethereum::misc::{types::Bytes32, bytes32::field_to_bytes32}; + use dep::ethereum::{misc::{types::Bytes32, bytes32::field_to_bytes32}, uint256::U256}; // free mint: https://sepolia.etherscan.io/address/0x80d97726548fedae6ad7cf8df4f2b514fd24afba#readContract fn FAKE_BORED_APE_YACHT_CLUB() -> ERC721Token { @@ -57,9 +57,9 @@ mod sepolia { ], token_id_to_slot: |token_id| { let BORED_APE_YACHT_CLUB_MAX_TOKEN_ID: u64 = 9999; - let BORED_APE_YACHT_CLUB_TOKEN_OWNERS_INNER_ENTRIES_SLOT = [ + let BORED_APE_YACHT_CLUB_TOKEN_OWNERS_INNER_ENTRIES_SLOT = U256::from([ 0x40, 0x57, 0x87, 0xfa, 0x12, 0xa8, 0x23, 0xe0, 0xf2, 0xb7, 0x63, 0x1c, 0xc4, 0x1b, 0x3b, 0xa8, 0x82, 0x8b, 0x33, 0x21, 0xca, 0x81, 0x11, 0x11, 0xfa, 0x75, 0xcd, 0x3a, 0xa3, 0xbb, 0x5a, 0xce - ]; + ]); let VALUE_INDEX = 1; assert(bytes32_to_field(token_id) as u64 <= BORED_APE_YACHT_CLUB_MAX_TOKEN_ID, "Token ID is too high"); diff --git a/vlayer/ethereum/circuits/lib/src/slot.nr b/vlayer/ethereum/circuits/lib/src/slot.nr index 7d5358b9..dc3079da 100644 --- a/vlayer/ethereum/circuits/lib/src/slot.nr +++ b/vlayer/ethereum/circuits/lib/src/slot.nr @@ -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 = 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) } diff --git a/vlayer/ethereum/circuits/lib/src/slot_test.nr b/vlayer/ethereum/circuits/lib/src/slot_test.nr index 078cd93f..0dc338e5 100644 --- a/vlayer/ethereum/circuits/lib/src/slot_test.nr +++ b/vlayer/ethereum/circuits/lib/src/slot_test.nr @@ -1,24 +1,26 @@ mod mapping { use crate::slot::mapping; - use dep::ethereum::misc::bytes32::address_to_bytes32; - use dep::ethereum::misc::bytes32::field_to_bytes32; + use dep::ethereum::misc::bytes32::{address_to_bytes32, field_to_bytes32}; + use dep::ethereum::uint256::U256; #[test] fn adress_mapping() { - let slot = field_to_bytes32(9); + let slot = U256::from_field(9); let address = [ 0x55, 0xfe, 0x00, 0x2a, 0xef, 0xf0, 0x2f, 0x77, 0x36, 0x4d, 0xe3, 0x39, 0xa1, 0x29, 0x29, 0x23, 0xa1, 0x58, 0x44, 0xb8 ]; assert_eq( - [ + U256::from( + [ 0x57, 0xd1, 0x8a, 0xf7, 0x93, 0xd7, 0x30, 0x0c, 0x4b, 0xa4, 0x6d, 0x19, 0x2e, 0xc7, 0xaa, 0x09, 0x50, 0x70, 0xdd, 0xe6, 0xc5, 0x2c, 0x68, 0x7c, 0x6d, 0x0d, 0x92, 0xfb, 0x85, 0x32, 0xb3, 0x05 - ], mapping(slot, address_to_bytes32(address)) + ] + ), mapping(slot, address_to_bytes32(address)) ); } #[test] fn mapping_of_mapping() { - let slot = field_to_bytes32(1); + let slot = U256::from_field(1); let owner = [ 0x5d, 0x82, 0x72, 0x63, 0x05, 0x2a, 0x88, 0x64, 0x23, 0xdc, 0xb1, 0x75, 0xef, 0x9b, 0x74, 0x91, 0xcc, 0x92, 0xed, 0x24 ]; @@ -27,9 +29,11 @@ mod mapping { ]; assert_eq( - [ + U256::from( + [ 0x51, 0x5a, 0xd6, 0x04, 0x70, 0x94, 0xbd, 0x71, 0x0c, 0x10, 0x72, 0xcd, 0xa4, 0x7b, 0xc6, 0xcf, 0x43, 0x9c, 0x55, 0xdc, 0xf0, 0xb0, 0xd6, 0x0e, 0x8a, 0x9b, 0xe5, 0x57, 0xf1, 0x86, 0x81, 0x1c - ], mapping( + ] + ), mapping( mapping(slot, address_to_bytes32(owner)), address_to_bytes32(spender) ) @@ -38,11 +42,13 @@ mod mapping { #[test] fn uint_mapping() { - let slot = field_to_bytes32(10); + let slot = U256::from_field(10); let uint = 0; - let expected_slot = [ + let expected_slot = U256::from( + [ 0x13, 0xda, 0x86, 0x00, 0x8b, 0xa1, 0xc6, 0x92, 0x2d, 0xae, 0xe3, 0xe0, 0x7d, 0xb9, 0x53, 0x05, 0xef, 0x49, 0xeb, 0xce, 0xd9, 0xf5, 0x46, 0x7a, 0x0b, 0x86, 0x13, 0xfc, 0xc6, 0xb3, 0x43, 0xe3 - ]; + ] + ); assert_eq(mapping(slot, field_to_bytes32(uint)), expected_slot); } } @@ -50,28 +56,33 @@ mod mapping { mod dynamic_array { use crate::slot::dynamic_array; use dep::ethereum::misc::{bytes32_test::MAX_FIELD_VALUE, bytes32::field_to_bytes32}; + use dep::ethereum::uint256::U256; #[test] fn index_zero() { - let slot = field_to_bytes32(2); - let expected_slot = [ + let slot = U256::from_field(2); + let expected_slot = U256::from( + [ 0x40, 0x57, 0x87, 0xfa, 0x12, 0xa8, 0x23, 0xe0, 0xf2, 0xb7, 0x63, 0x1c, 0xc4, 0x1b, 0x3b, 0xa8, 0x82, 0x8b, 0x33, 0x21, 0xca, 0x81, 0x11, 0x11, 0xfa, 0x75, 0xcd, 0x3a, 0xa3, 0xbb, 0x5a, 0xce - ]; + ] + ); assert_eq(expected_slot, dynamic_array(slot, 2, 0)); } #[test] fn index_positive() { - let slot = field_to_bytes32(2); - let expected_slot = [ + let slot = U256::from_field(2); + let expected_slot = U256::from( + [ 0x40, 0x57, 0x87, 0xfa, 0x12, 0xa8, 0x23, 0xe0, 0xf2, 0xb7, 0x63, 0x1c, 0xc4, 0x1b, 0x3b, 0xa8, 0x82, 0x8b, 0x33, 0x21, 0xca, 0x81, 0x11, 0x11, 0xfa, 0x75, 0xcd, 0x3a, 0xa3, 0xbb, 0x5a, 0xdc - ]; + ] + ); assert_eq(expected_slot, dynamic_array(slot, 2, 7)); } - #[test(should_fail_with="Addition overflow")] + #[test(should_fail_with="attempt to add with overflow")] fn fail_overflow() { - let slot = field_to_bytes32(6); + let slot = U256::from_field(6); let _ = dynamic_array(slot, 2, MAX_FIELD_VALUE); } } @@ -79,32 +90,35 @@ mod dynamic_array { mod dynamic_array_with_precalculated_slot { use crate::slot::dynamic_array_with_precalculated_slot; use dep::ethereum::misc::{bytes32_test::MAX_FIELD_VALUE, bytes32::field_to_bytes32}; + use dep::ethereum::uint256::U256; #[test] fn index_zero() { - let slot = field_to_bytes32(2); + let slot = U256::from_field(2); assert_eq(slot, dynamic_array_with_precalculated_slot(slot, 2, 0)); } #[test] fn index_positive() { - let slot = field_to_bytes32(2); - let expected_slot = field_to_bytes32(2 + 2 * 7); + let slot = U256::from_field(2); + let expected_slot = U256::from_field(2 + 2 * 7); assert_eq(expected_slot, dynamic_array_with_precalculated_slot(slot, 2, 7)); } #[test] fn big_index() { - let slot = [0x09; 32]; - let expected_slot = [ + let slot = U256::from([0x09; 32]); + let expected_slot = U256::from( + [ 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x0b, 0x5d, 0x14, 0xed, 9 - ]; + ] + ); assert_eq(expected_slot, dynamic_array_with_precalculated_slot(slot, 10, 1_000_000_000)); } - #[test(should_fail_with="Addition overflow")] + #[test(should_fail_with="attempt to add with overflow")] fn fail_overflow() { - let slot = [0xfe; 32]; + let slot = U256::from([0xfe; 32]); let _ = dynamic_array_with_precalculated_slot(slot, 2, MAX_FIELD_VALUE); } } @@ -112,19 +126,22 @@ mod dynamic_array_with_precalculated_slot { mod struct_slot { use crate::slot::struct_slot; use dep::ethereum::misc::bytes32::field_to_bytes32; + use dep::ethereum::uint256::U256; #[test] fn success() { - let slot = field_to_bytes32(2); - let expected_slot = [ + let slot = U256::from_field(2); + let expected_slot = U256::from( + [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2 - ]; + ] + ); assert_eq(expected_slot, struct_slot(slot, 256)); } - #[test(should_fail_with="Addition overflow")] + #[test(should_fail_with="attempt to add with overflow")] fn overflow() { - let slot = [0xff; 32]; + let slot = U256::from([0xff; 32]); let _ = struct_slot(slot, 256); } } diff --git a/vlayer/ethereum/circuits/lib/src/token.nr b/vlayer/ethereum/circuits/lib/src/token.nr index 1ec16732..f6a64880 100644 --- a/vlayer/ethereum/circuits/lib/src/token.nr +++ b/vlayer/ethereum/circuits/lib/src/token.nr @@ -1,21 +1,22 @@ use dep::ethereum::{ - account_with_storage::get_account_with_storage, misc::types::{Address, Bytes32}, + account_with_storage::get_account_with_storage, misc::types::Address, misc::bytes32::address_to_bytes32 }; use dep::std::field::bytes32_to_field; use crate::slot::mapping; +use dep::ethereum::uint256::U256; global TOKEN_BALANCE_INDEX = 0; struct ERC20Token { address: Address, - balances_slot: Bytes32, - allowances_slot: Bytes32, + balances_slot: U256, + allowances_slot: U256, chain_id: Field } impl ERC20Token { - fn calculate_balance_storage_key(self, wallet_address: Address) -> Bytes32 { + fn calculate_balance_storage_key(self, wallet_address: Address) -> U256 { mapping(self.balances_slot, address_to_bytes32(wallet_address)) } } @@ -27,7 +28,7 @@ trait ERC20 { impl ERC20 for ERC20Token { fn get_balance(self, wallet_address: Address, block_number: u64) -> U128 { let storage_key = self.calculate_balance_storage_key(wallet_address); - let account = get_account_with_storage(self.chain_id, block_number, self.address, storage_key); + let account = get_account_with_storage(self.chain_id, block_number, self.address, U256::into(storage_key)); let balance = account.values[TOKEN_BALANCE_INDEX]; U128::from_integer(bytes32_to_field(balance)) diff --git a/vlayer/ethereum/circuits/lib/src/token_int_test.nr b/vlayer/ethereum/circuits/lib/src/token_int_test.nr index 00a6d8ca..402fc12b 100644 --- a/vlayer/ethereum/circuits/lib/src/token_int_test.nr +++ b/vlayer/ethereum/circuits/lib/src/token_int_test.nr @@ -8,6 +8,7 @@ mod test_ERC20Token { paris::usdc_circle::state_proof::proof_input_serialized as state_proof_input_serialized, paris::usdc_circle::storage_proof::proofs_serialized }; + use dep::ethereum::uint256::U256; use crate::chain_id::MAINNET; #[test] @@ -19,12 +20,8 @@ mod test_ERC20Token { address: [ 0xa0, 0xb8, 0x69, 0x91, 0xc6, 0x21, 0x8b, 0x36, 0xc1, 0xd1, 0x9d, 0x4a, 0x2e, 0x9e, 0xb0, 0xce, 0x36, 0x06, 0xeb, 0x48 ], - balances_slot: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9 - ], - allowances_slot: [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10 - ], + balances_slot: U256::from_field(9), + allowances_slot: U256::from_field(10), chain_id: MAINNET }; diff --git a/vlayer/ethereum/circuits/lib/src/token_list.nr b/vlayer/ethereum/circuits/lib/src/token_list.nr index 83d96180..43dae842 100644 --- a/vlayer/ethereum/circuits/lib/src/token_list.nr +++ b/vlayer/ethereum/circuits/lib/src/token_list.nr @@ -1,81 +1,82 @@ mod mainnet { use crate::token::ERC20Token; use crate::chain_id; + use dep::ethereum::uint256::U256; global USDC = ERC20Token { address: [0xa0, 0xb8, 0x69, 0x91, 0xc6, 0x21, 0x8b, 0x36, 0xc1, 0xd1, 0x9d, 0x4a, 0x2e, 0x9e, 0xb0, 0xce, 0x36, 0x06, 0xeb, 0x48], - balances_slot: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9], - allowances_slot: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10], + balances_slot: U256::from_field(9), + allowances_slot: U256::from_field(10), chain_id: chain_id::MAINNET }; global TETHER_USD = ERC20Token { address: [0xda, 0xc1, 0x7f, 0x95, 0x8d, 0x2e, 0xe5, 0x23, 0xa2, 0x20, 0x62, 0x06, 0x99, 0x45, 0x97, 0xc1, 0x3d, 0x83, 0x1e, 0xc7], - balances_slot: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2], - allowances_slot: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5], + balances_slot: U256::from_field(2), + allowances_slot: U256::from_field(5), chain_id: chain_id::MAINNET }; global UNISWAP = ERC20Token { address: [0x1f, 0x98, 0x40, 0xa8, 0x5d, 0x5a, 0xf5, 0xbf, 0x1d, 0x17, 0x62, 0xf9, 0x25, 0xbd, 0xad, 0xdc, 0x42, 0x01, 0xf9, 0x84], - balances_slot: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4], - allowances_slot: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3], + balances_slot: U256::from_field(4), + allowances_slot: U256::from_field(3), chain_id: chain_id::MAINNET }; global WBTC = ERC20Token { address: [0x22, 0x60, 0xfa, 0xc5, 0xe5, 0x54, 0x2a, 0x77, 0x3a, 0xa4, 0x4f, 0xbc, 0xfe, 0xdf, 0x7c, 0x19, 0x3b, 0xc2, 0xc5, 0x99], - balances_slot: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - allowances_slot: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2], + balances_slot: U256::from_field(0), + allowances_slot: U256::from_field(2), chain_id: chain_id::MAINNET }; global EZETH = ERC20Token { address: [0xbf, 0x54, 0x95, 0xef, 0xe5, 0xdb, 0x9c, 0xe0, 0x0f, 0x80, 0x36, 0x4c, 0x8b, 0x42, 0x35, 0x67, 0xe5, 0x8d, 0x21, 0x10], - balances_slot: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33], - allowances_slot: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34], + balances_slot: U256::from_field(33), + allowances_slot: U256::from_field(34), chain_id: chain_id::MAINNET }; global WEETH = ERC20Token { address: [0xcd, 0x5f, 0xe2, 0x3c, 0x85, 0x82, 0x0f, 0x7b, 0x72, 0xd0, 0x92, 0x6f, 0xc9, 0xb0, 0x5b, 0x43, 0xe3, 0x59, 0xb7, 0xee], - balances_slot: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65], - allowances_slot: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 66], + balances_slot: U256::from_field(65), + allowances_slot: U256::from_field(66), chain_id: chain_id::MAINNET }; global DAI = ERC20Token { address: [0x6b, 0x17, 0x54, 0x74, 0xe8, 0x90, 0x94, 0xc4, 0x4d, 0xa9, 0x8b, 0x95, 0x4e, 0xed, 0xea, 0xc4, 0x95, 0x27, 0x1d, 0x0f], - balances_slot: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2], - allowances_slot: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3], + balances_slot: U256::from_field(2), + allowances_slot: U256::from_field(3), chain_id: chain_id::MAINNET }; global WSTETH = ERC20Token { address: [0x7f, 0x39, 0xc5, 0x81, 0xf5, 0x95, 0xb5, 0x3c, 0x5c, 0xb1, 0x9b, 0xd0, 0xb3, 0xf8, 0xda, 0x6c, 0x93, 0x5e, 0x2c, 0xa0], - balances_slot: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - allowances_slot: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], + balances_slot: U256::from_field(0), + allowances_slot: U256::from_field(1), chain_id: chain_id::MAINNET }; global USDe = ERC20Token { address: [0x4c, 0x9e, 0xdd, 0x58, 0x52, 0xcd, 0x90, 0x5f, 0x08, 0x6c, 0x75, 0x9e, 0x83, 0x83, 0xe0, 0x9b, 0xff, 0x1e, 0x68, 0xb3], - balances_slot: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2], - allowances_slot: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3], + balances_slot: U256::from_field(2), + allowances_slot: U256::from_field(3), chain_id: chain_id::MAINNET }; global PEPE = ERC20Token { address: [0x69, 0x82, 0x50, 0x81, 0x45, 0x45, 0x4c, 0xe3, 0x25, 0xdd, 0xbe, 0x47, 0xa2, 0x5d, 0x4e, 0xc3, 0xd2, 0x31, 0x19, 0x33], - balances_slot: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], - allowances_slot: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2], + balances_slot: U256::from_field(1), + allowances_slot: U256::from_field(2), chain_id: chain_id::MAINNET }; global MKR = ERC20Token { address: [0x9f, 0x8f, 0x72, 0xaa, 0x93, 0x04, 0xc8, 0xb5, 0x93, 0xd5, 0x55, 0xf1, 0x2e, 0xf6, 0x58, 0x9c, 0xc3, 0xa5, 0x79, 0xa2], - balances_slot: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], - allowances_slot: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2], + balances_slot: U256::from_field(1), + allowances_slot: U256::from_field(2), chain_id: chain_id::MAINNET }; } @@ -83,12 +84,13 @@ mod mainnet { mod sepolia { use crate::token::ERC20Token; use crate::chain_id; + use dep::ethereum::uint256::U256; // free mint: https://sepolia.etherscan.io/token/0x4f657a53e27e83ee7d3df8452abfd57d658765d6 global FakePEPE = ERC20Token { address: [0x4f, 0x65, 0x7a, 0x53, 0xe2, 0x7e, 0x83, 0xee, 0x7d, 0x3d, 0xf8, 0x45, 0x2a, 0xbf, 0xd5, 0x7d, 0x65, 0x87, 0x65, 0xd6], - balances_slot: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], - allowances_slot: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2], + balances_slot: U256::from_field(1), + allowances_slot: U256::from_field(2), chain_id: chain_id::SEPOLIA }; }