Skip to content

Commit f40317a

Browse files
committed
fixes
1 parent 79c2ecf commit f40317a

File tree

6 files changed

+71
-55
lines changed

6 files changed

+71
-55
lines changed

ethereum/circuits/lib/src/misc.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ mod fragment_test;
99
mod fragment_int_test;
1010
pub mod types;
1111
pub(crate) mod option;
12-
pub(crate) mod bytes32;
12+
pub mod bytes32;
1313
mod bytes32_test;
1414
pub(crate) mod iterator;

ethereum/circuits/lib/src/transaction.nr

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ impl<let MAX_DATA_LEN: u32> Eq for TxPartial<MAX_DATA_LEN> {
4141
}
4242

4343
pub(crate) struct ForeignCallTransaction<let MAX_DATA_LEN: u32> {
44-
nonce: u64,
45-
gas_limit: u64,
46-
to: Address,
47-
to_is_some: bool,
48-
value_hi: u64,
49-
value_lo: u64,
50-
data: [u8; MAX_DATA_LEN],
51-
data_len: u32,
52-
v: u8, // ECDSA recovery id
53-
r: Bytes32, // ECDSA signature part
54-
s: Bytes32, // ECDSA signature part
44+
pub(crate) nonce: u64,
45+
pub(crate) gas_limit: u64,
46+
pub(crate) to: Address,
47+
pub(crate) to_is_some: bool,
48+
pub(crate) value_hi: u64,
49+
pub(crate) value_lo: u64,
50+
pub(crate) data: [u8; MAX_DATA_LEN],
51+
pub(crate) data_len: u32,
52+
pub(crate) v: u8, // ECDSA recovery id
53+
pub(crate) r: Bytes32, // ECDSA signature part
54+
pub(crate) s: Bytes32, // ECDSA signature part
5555
}
5656

5757
impl<let MAX_DATA_LEN: u32> From<TxPartial<MAX_DATA_LEN>> for ForeignCallTransaction<MAX_DATA_LEN> {
@@ -99,8 +99,8 @@ impl<let MAX_DATA_LEN: u32> From<ForeignCallTransaction<MAX_DATA_LEN>> for TxPar
9999
type ProofInputSerialized<let LEN: u32> = [Field; LEN];
100100

101101
pub struct TransactionWithinBlock<let MAX_DATA_LEN: u32> {
102-
transaction: TxPartial<MAX_DATA_LEN>,
103-
block_hash: Bytes32,
102+
pub(crate) transaction: TxPartial<MAX_DATA_LEN>,
103+
pub(crate) block_hash: Bytes32,
104104
}
105105

106106
pub fn get_transaction<let MAX_DATA_LEN: u32>(

ethereum/circuits/lib/src/transaction_int_test.nr

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::fixtures::mainnet::{
1717
transaction_proof::proof_input_serialized as another_proof_input_serialized,
1818
},
1919
};
20-
use crate::transaction::{get_transaction, TransactionWithinBlock};
20+
use crate::transaction::{get_transaction, TransactionWithinBlock, TxPartial};
2121
use dep::std::test::OracleMock;
2222

2323
global MAX_DATA_LEN: u32 = 1000;
@@ -37,7 +37,22 @@ fn get_transaction_success() {
3737
get_transaction(ETHEREUM_MAINNET_ID, number, tx_idx);
3838

3939
assert_eq(transaction_within_block.block_hash, block_header_partial.hash);
40-
assert_eq(transaction_within_block.transaction, foreign_call_transaction.into());
40+
// Convert transaction from TxPartial<68> to TxPartial<1000> by creating a new one with extended data
41+
let mut data_extended: BoundedVec<u8, MAX_DATA_LEN> = BoundedVec::new();
42+
for i in 0..transaction.data.len() {
43+
data_extended.push(transaction.data.get(i));
44+
}
45+
let transaction_1000 = TxPartial::<MAX_DATA_LEN> {
46+
nonce: transaction.nonce,
47+
gas_limit: transaction.gas_limit,
48+
to: transaction.to,
49+
value: transaction.value,
50+
data: data_extended,
51+
v: transaction.v,
52+
r: transaction.r,
53+
s: transaction.s,
54+
};
55+
assert_eq(transaction_within_block.transaction, transaction_1000);
4156
}
4257

4358
#[test(should_fail_with = "Block number does not match the argument")]

ethereum/circuits/lib/src/uint256.nr

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ impl From<Bytes32> for U256 {
3232
fn from(bytes: Bytes32) -> Self {
3333
let mut high_bytes = [0; 16];
3434
memcpy_up_to_length(&mut high_bytes, bytes, 16, 16);
35-
let high = from_le_bytes(high_bytes);
35+
let high = Field::from_le_bytes::<16>(high_bytes) as u128;
3636

3737
let mut low_bytes = [0; 16];
3838
memcpy_up_to_length(&mut low_bytes, bytes, 0, 16);
39-
let low = u256::from_le_bytes(low_bytes);
39+
let low = Field::from_le_bytes::<16>(low_bytes) as u128;
4040

4141
U256::new(high, low)
4242
}
@@ -45,9 +45,9 @@ impl From<Bytes32> for U256 {
4545
impl Into<Bytes32> for U256 {
4646
fn into(self) -> Bytes32 {
4747
let mut bytes = [0; 32];
48-
memcpy_up_to_length(&mut bytes, self.low.to_le_bytes(), 0, 16);
48+
memcpy_up_to_length(&mut bytes, (self.low as Field).to_le_bytes::<16>(), 0, 16);
4949

50-
let high_bytes = self.high.to_le_bytes();
50+
let high_bytes = (self.high as Field).to_le_bytes::<16>();
5151
for i in 0..16 {
5252
bytes[i + 16] = high_bytes[i];
5353
}
@@ -64,21 +64,22 @@ impl Eq for U256 {
6464

6565
impl Add for U256 {
6666
fn add(self, other: Self) -> Self {
67-
let lo: Field = self.low.to_integer() + other.low.to_integer();
67+
let lo: Field = self.low as Field + other.low as Field;
6868

69-
let mut low = U128::from_integer(0);
69+
let mut low = 0;
7070
let mut carry = 0;
7171
if (lo.lt(uint128_overflow_value)) {
72-
low = U128::from_integer(lo);
72+
low = lo;
7373
} else {
74-
low = U128::from_integer(lo - uint128_overflow_value);
74+
low = lo - uint128_overflow_value;
7575
carry = 1;
7676
}
7777

78-
let hi: Field = self.high.to_integer() + other.high.to_integer() + carry;
78+
let hi: Field = self.high as Field + other.high as Field + carry;
7979
assert(hi.lt(uint128_overflow_value), "attempt to add with overflow");
8080

8181
let high = hi as u128;
82+
let low = low as u128;
8283

8384
Self { high, low }
8485
}

ethereum/circuits/lib/src/uint256_test.nr

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use crate::uint256::U256;
22

3-
global high = U128::from_integer(0x10000000000000000000000000000000);
4-
global low = U128::zero();
5-
global limit = U128::from_integer(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
3+
global high: u128 = 0x10000000000000000000000000000000;
4+
global low: u128 = 0;
5+
global limit: u128 = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
66

7-
global big_number = U256 { high, low };
7+
global big_number: U256 = U256::new(high, low);
88

99
#[test]
1010
fn success() {
@@ -22,22 +22,22 @@ fn new() {
2222
#[test]
2323
fn zero_and_one() {
2424
let zero = U256::zero();
25-
assert_eq(zero.high, U128::zero());
26-
assert_eq(zero.low, U128::zero());
25+
assert_eq(zero.high, 0);
26+
assert_eq(zero.low, 0);
2727

2828
let one = U256::one();
29-
assert_eq(one.high, U128::zero());
30-
assert_eq(one.low, U128::one());
29+
assert_eq(one.high, 0);
30+
assert_eq(one.low, 0);
3131
}
3232

3333
mod from_bytes32 {
3434
use crate::uint256::U256;
35-
global high = U128::from_integer(0x10000000000000000000000000000000);
36-
global low = U128::zero();
37-
global limit = U128::from_integer(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
35+
global high: u128 = 0x10000000000000000000000000000000;
36+
global low: u128 = 0;
37+
global limit: u128 = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
3838

39-
global big_number = U256 { high, low };
40-
global limit_u256 = U256 { high: limit, low: limit };
39+
global big_number: U256 = U256::new(high, low);
40+
global limit_u256: U256 = U256::new(limit, limit);
4141

4242
#[test]
4343
fn zero() {
@@ -61,12 +61,12 @@ mod from_bytes32 {
6161

6262
mod into_bytes32 {
6363
use crate::uint256::U256;
64-
global high = U128::from_integer(0x10000000000000000000000000000000);
65-
global low = U128::zero();
66-
global limit = U128::from_integer(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
64+
global high: u128 = 0x10000000000000000000000000000000;
65+
global low: u128 = 0;
66+
global limit: u128 = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
6767

68-
global big_number = U256 { high, low };
69-
global limit_u256 = U256 { high: limit, low: limit };
68+
global big_number: U256 = U256::new(high, low);
69+
global limit_u256: U256 = U256::new(limit, limit);
7070

7171
#[test]
7272
fn zero() {
@@ -107,26 +107,26 @@ fn not_eq() {
107107

108108
mod trait_add {
109109
use crate::uint256::U256;
110-
global high = U128::from_integer(0x10000000000000000000000000000000);
111-
global low = U128::zero();
112-
global limit = U128::from_integer(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
110+
global high: u128 = 0x10000000000000000000000000000000;
111+
global low: u128 = 0;
112+
global limit: u128 = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
113113

114-
global big_number = U256 { high, low };
115-
global limit_u256 = U256 { high: limit, low: limit };
114+
global big_number: U256 = U256::new(high, low);
115+
global limit_u256: U256 = U256::new(limit, limit);
116116

117117
#[test]
118118
fn sum() {
119119
let sum = big_number + big_number;
120120

121-
assert_eq(sum, U256 { high: U128::from_integer(0x20000000000000000000000000000000), low });
121+
assert_eq(sum, U256 { high: 0x20000000000000000000000000000000, low });
122122
}
123123

124124
#[test]
125125
fn sum_with_carry() {
126126
let big_number = U256 { high, low: limit };
127127
let sum = big_number + U256::one();
128128

129-
assert_eq(sum, U256 { high: U128::from_integer(0x10000000000000000000000000000001), low });
129+
assert_eq(sum, U256 { high: 0x10000000000000000000000000000001, low });
130130
}
131131

132132
#[test(should_fail_with = "attempt to add with overflow")]
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
mod token;
1+
pub(crate) mod token;
22
mod token_int_test;
3-
mod slot;
3+
pub(crate) mod slot;
44
mod slot_test;
5-
mod token_list;
6-
mod chain_id;
7-
mod nft;
5+
pub(crate) mod token_list;
6+
pub(crate) mod chain_id;
7+
pub(crate) mod nft;
88
mod nft_list;

0 commit comments

Comments
 (0)