Skip to content

Commit 8130404

Browse files
committed
fixes
1 parent f40317a commit 8130404

File tree

8 files changed

+44
-48
lines changed

8 files changed

+44
-48
lines changed

ethereum/circuits/lib/src/fixtures/mainnet/cancun/approve/transaction.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ global storage_data: [u8; 1000] = [
198198
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
199199
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
200200
];
201-
global transaction: TxPartial<1000> = TxPartial {
201+
pub(crate) global transaction: TxPartial<1000> = TxPartial {
202202
nonce: 0,
203203
gas_limit: 48948,
204204
to: Option::some([

ethereum/circuits/lib/src/fixtures/mainnet/london/vitalik_balance/header.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{header::BlockHeaderPartial, misc::types::Bytes32};
22

33
global number: u64 = 12965000;
4-
global hash: Bytes32 = [
4+
pub(crate) global hash: Bytes32 = [
55
0x9b, 0x83, 0xc1, 0x2c, 0x69, 0xed, 0xb7, 0x4f, 0x6c, 0x8d, 0xd5, 0xd0, 0x52, 0x76, 0x5c, 0x1a,
66
0xdf, 0x94, 0x0e, 0x32, 0x0b, 0xd1, 0x29, 0x16, 0x96, 0xe6, 0xfa, 0x07, 0x82, 0x9e, 0xee, 0x71,
77
];

ethereum/circuits/lib/src/receipt.nr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ impl From<TxReceiptPartial> for ForeignCallTxReceiptPartial {
7676
type ProofInputSerialized<let LEN: u32> = [Field; LEN];
7777

7878
pub struct TxReceiptWithinBlock {
79-
receipt: TxReceiptPartial,
80-
block_hash: Bytes32,
79+
pub(crate) receipt: TxReceiptPartial,
80+
pub(crate) block_hash: Bytes32,
8181
}
8282

8383
pub fn get_receipt(chain_id: u32, block_number: u64, tx_idx: Field) -> TxReceiptWithinBlock {

ethereum/circuits/lib/src/serde.nr

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,27 @@ pub(crate) trait Serde<let LEN: u32> {
2323
fn deserialize(data: [Field; LEN]) -> Self;
2424
}
2525

26-
pub(crate) global U128_SERIALIZED_LEN: u32 = 2;
26+
pub(crate) global U128_SERIALIZED_LEN: u32 = 1;
2727

2828
impl Serde<U128_SERIALIZED_LEN> for u128 {
2929
fn serialize(self) -> [Field; U128_SERIALIZED_LEN] {
30-
[self.lo, self.hi]
30+
[self as Field]
3131
}
3232

3333
fn deserialize(data: [Field; U128_SERIALIZED_LEN]) -> Self {
34-
U128 { lo: data[0], hi: data[1] }
34+
data[0] as u128
3535
}
3636
}
3737

38-
pub(crate) global U256_SERIALIZED_LEN: u32 = 4;
38+
pub(crate) global U256_SERIALIZED_LEN: u32 = 2;
3939

4040
impl Serde<U256_SERIALIZED_LEN> for U256 {
4141
fn serialize(self) -> [Field; U256_SERIALIZED_LEN] {
42-
[self.low.lo, self.low.hi, self.high.lo, self.high.hi]
42+
[self.low as Field, self.high as Field]
4343
}
4444

4545
fn deserialize(data: [Field; U256_SERIALIZED_LEN]) -> Self {
46-
U256 { low: U128 { lo: data[0], hi: data[1] }, high: U128 { lo: data[2], hi: data[3] } }
46+
U256 { low: data[0] as u128, high: data[1] as u128 }
4747
}
4848
}
4949

@@ -105,7 +105,7 @@ impl Serde<STORAGE_BLOCK_LEN> for StorageWithinBlock<1> {
105105
data.extend_from_array(self.block_hash.serialize());
106106
data.extend_from_array(self.account.serialize());
107107
data.extend_from_array(self.values[0].serialize());
108-
data.storage
108+
data.storage()
109109
}
110110

111111
fn deserialize(data: [Field; STORAGE_BLOCK_LEN]) -> Self {
@@ -128,7 +128,7 @@ pub fn serialize_state_nodes(
128128
for i in 0..MAX_ACCOUNT_DEPTH_NO_LEAF_M {
129129
data.extend_from_array(nodes[i].serialize());
130130
}
131-
data.storage
131+
data.storage()
132132
}
133133

134134
pub fn deserialize_state_nodes(
@@ -151,7 +151,7 @@ impl Serde<STATE_PROOF_LEN_M> for Proof<MAX_ACCOUNT_DEPTH_NO_LEAF_M, MAX_ACCOUNT
151151
data.extend_from_array(serialize_state_nodes(self.nodes));
152152
data.extend_from_array(self.leaf.serialize());
153153
data.push(self.depth as Field);
154-
data.storage
154+
data.storage()
155155
}
156156

157157
fn deserialize(data: [Field; STATE_PROOF_LEN_M]) -> Self {
@@ -195,7 +195,7 @@ pub fn serialize_storage_nodes(
195195
for i in 0..MAX_STORAGE_DEPTH_NO_LEAF_M {
196196
data.extend_from_array(nodes[i].serialize());
197197
}
198-
data.storage
198+
data.storage()
199199
}
200200

201201
pub fn deserialize_storage_nodes(
@@ -218,7 +218,7 @@ impl Serde<STORAGE_PROOF_LEN_M> for Proof<MAX_STORAGE_DEPTH_NO_LEAF_M, MAX_STORA
218218
data.extend_from_array(serialize_storage_nodes(self.nodes));
219219
data.extend_from_array(self.leaf.serialize());
220220
data.push(self.depth as Field);
221-
data.storage
221+
data.storage()
222222
}
223223

224224
fn deserialize(data: [Field; STORAGE_PROOF_LEN_M]) -> Self {
@@ -239,7 +239,7 @@ impl Serde<STORAGE_PROOF_INPUT_LEN_M> for ProofInput<STORAGE_MAX_PREFIXED_KEY_NI
239239
data.extend_from_array(self.key.serialize());
240240
data.extend_from_array(self.value.serialize());
241241
data.extend_from_array(self.proof.serialize());
242-
data.storage
242+
data.storage()
243243
}
244244

245245
fn deserialize(data: [Field; STORAGE_PROOF_INPUT_LEN_M]) -> Self {
@@ -262,7 +262,7 @@ pub fn serialize_receipt_nodes(
262262
for i in 0..RECEIPT_MAX_DEPTH_NO_LEAF {
263263
data.extend_from_array(nodes[i].serialize());
264264
}
265-
data.storage
265+
data.storage()
266266
}
267267

268268
pub fn deserialize_receipt_nodes(
@@ -285,7 +285,7 @@ impl Serde<RECEIPT_PROOF_LEN_M> for Proof<RECEIPT_MAX_DEPTH_NO_LEAF, RECEIPT_MAX
285285
data.extend_from_array(serialize_receipt_nodes(self.nodes));
286286
data.extend_from_array(self.leaf.serialize());
287287
data.push(self.depth as Field);
288-
data.storage
288+
data.storage()
289289
}
290290

291291
fn deserialize(data: [Field; RECEIPT_PROOF_LEN_M]) -> Self {
@@ -308,7 +308,7 @@ impl Serde<RECEIPT_PROOF_INPUT_LEN_M> for ProofInput<RECEIPT_MAX_PREFIXED_KEY_NI
308308
data.extend_from_array(self.key.serialize());
309309
data.extend_from_array(self.value.serialize());
310310
data.extend_from_array(self.proof.serialize());
311-
data.storage
311+
data.storage()
312312
}
313313

314314
fn deserialize(data: [Field; RECEIPT_PROOF_INPUT_LEN_M]) -> Self {

ethereum/circuits/lib/src/serde_test.nr

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,37 @@
11
mod U128_ {
22

3-
use crate::serde::U128_SERIALIZED_LEN;
3+
use crate::serde::{Serde, U128_SERIALIZED_LEN};
44

55
#[test]
66
fn simple() {
77
let value: u128 = 100;
88
let serialized: [Field; U128_SERIALIZED_LEN] = value.serialize();
99

10-
assert_eq(serialized[0], value.lo);
11-
assert_eq(serialized[1], value.hi);
12-
assert_eq(U128::deserialize(serialized), value);
10+
assert_eq(serialized[0] as u128, value);
11+
assert_eq(u128::deserialize(serialized), value);
1312
}
1413
}
1514

1615
mod U256 {
16+
use crate::serde::Serde;
1717
use crate::serde::U256_SERIALIZED_LEN;
1818
use crate::uint256::U256;
1919

20-
global u128_number = 0x10000000000000000000000000000000;
21-
global u64_value = 0x1000000000000000;
20+
global u128_number: u128 = 0x10000000000000000000000000000000;
2221

2322
#[test]
2423
fn simple() {
25-
let value = U256::new(
26-
U128::from_integer(u128_number),
27-
U128::from_integer(u128_number),
28-
);
24+
let value = U256::new(u128_number, u128_number);
2925
let serialized: [Field; U256_SERIALIZED_LEN] = value.serialize();
3026

31-
assert_eq(serialized[0], 0);
32-
assert_eq(serialized[1], u64_value);
33-
assert_eq(serialized[2], 0);
34-
assert_eq(serialized[3], u64_value);
27+
assert_eq(serialized[0] as u128, u128_number);
28+
assert_eq(serialized[1] as u128, u128_number);
3529
assert_eq(U256::deserialize(serialized), value);
3630
}
3731
}
3832

3933
mod u8_array {
40-
use crate::misc::types::{Address, ADDRESS_LENGTH, Bytes32, BYTES32_LENGTH};
34+
use crate::{misc::types::{Address, ADDRESS_LENGTH, Bytes32, BYTES32_LENGTH}, serde::Serde};
4135

4236
#[test]
4337
fn bytes32() {
@@ -63,6 +57,7 @@ mod account {
6357
use crate::fixtures::mainnet::london::vitalik_balance::account::account;
6458
use crate::misc::arrays::sub_array_equals;
6559
use crate::serde::ACCOUNT_LEN;
60+
use crate::serde::Serde;
6661

6762
#[test]
6863
fn simple() {
@@ -81,6 +76,7 @@ mod account_within_block {
8176
use crate::fixtures::mainnet::london::vitalik_balance::{account::account, header::hash};
8277
use crate::misc::arrays::sub_array_equals;
8378
use crate::serde::{ACCOUNT_BLOCK_LEN, ACCOUNT_LEN};
79+
use crate::serde::Serde;
8480

8581
#[test]
8682
fn simple() {
@@ -104,6 +100,7 @@ mod storage_within_block {
104100
};
105101
use crate::misc::{arrays::sub_array_equals, types::BYTES32_LENGTH};
106102
use crate::serde::{ACCOUNT_LEN, STORAGE_BLOCK_LEN};
103+
use crate::serde::Serde;
107104

108105
#[test]
109106
fn simple() {
@@ -130,6 +127,7 @@ mod nodes {
130127
use crate::merkle_patricia_proofs::proof::MAX_NODE_LEN;
131128
use crate::misc::arrays::sub_array_equals;
132129
use crate::serde::{deserialize_receipt_nodes, serialize_receipt_nodes};
130+
use crate::serde::Serde;
133131

134132
#[test]
135133
fn simple() {
@@ -151,7 +149,8 @@ mod proof {
151149
use crate::merkle_patricia_proofs::proof::Proof;
152150
use crate::misc::arrays::sub_array_equals;
153151
use crate::receipt::MAX_DEPTH_NO_LEAF as RECEIPT_MAX_DEPTH_NO_LEAF;
154-
use crate::serde::{RECEIPT_MAX_LEAF_LEN_M, RECEIPT_NODES_LEN, Serde, serialize_receipt_nodes};
152+
use crate::receipt::MAX_LEAF_LEN_M as RECEIPT_MAX_LEAF_LEN_M;
153+
use crate::serde::{RECEIPT_NODES_LEN, Serde, serialize_receipt_nodes};
155154

156155
#[test]
157156
fn simple() {

ethereum/circuits/lib/src/transaction.nr

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ pub(crate) struct ForeignCallTransaction<let MAX_DATA_LEN: u32> {
4545
pub(crate) gas_limit: u64,
4646
pub(crate) to: Address,
4747
pub(crate) to_is_some: bool,
48-
pub(crate) value_hi: u64,
49-
pub(crate) value_lo: u64,
48+
pub(crate) value: u128,
5049
pub(crate) data: [u8; MAX_DATA_LEN],
5150
pub(crate) data_len: u32,
5251
pub(crate) v: u8, // ECDSA recovery id
@@ -68,8 +67,7 @@ impl<let MAX_DATA_LEN: u32> From<TxPartial<MAX_DATA_LEN>> for ForeignCallTransac
6867
gas_limit: tx.gas_limit,
6968
to: tx.to.unwrap_or(std::mem::zeroed()),
7069
to_is_some: tx.to.is_some(),
71-
value_hi: tx.value.hi as u64,
72-
value_lo: tx.value.lo as u64,
70+
value: tx.value,
7371
data,
7472
data_len: tx.data.len(),
7573
v: tx.v,
@@ -87,7 +85,7 @@ impl<let MAX_DATA_LEN: u32> From<ForeignCallTransaction<MAX_DATA_LEN>> for TxPar
8785
nonce: tx.nonce,
8886
gas_limit: tx.gas_limit,
8987
to: make_option(tx.to, tx.to_is_some),
90-
value: U128::from_u64s_be(tx.value_hi as u64, tx.value_lo as u64),
88+
value: tx.value,
9189
data,
9290
v: tx.v,
9391
r: tx.r,

ethereum/circuits/lib/src/transaction_test.nr

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ fn into_foreign_call_transaction_test() {
2222
assert_eq(foreign_call_transaction.to_is_some, true);
2323
assert_eq(foreign_call_transaction.to, transaction.to.expect(f"To is missing"));
2424

25-
assert_eq(foreign_call_transaction.value_hi, transaction.value.hi as u64);
26-
assert_eq(foreign_call_transaction.value_lo, transaction.value.lo as u64);
25+
assert_eq(foreign_call_transaction.value, transaction.value);
2726

2827
assert_eq(foreign_call_transaction.data, [1, 2, 3, 4, 5, 0, 0, 0]);
2928
assert_eq(foreign_call_transaction.data_len, 5);

ethereum/circuits/lib/src/uint256.nr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@ use dep::std::ops::Add;
66
global uint128_overflow_value: Field = 340282366920938463463374607431768211456; // 2^128
77

88
pub(crate) struct U256 {
9-
high: u128,
10-
low: u128,
9+
pub(crate) high: u128,
10+
pub(crate) low: u128,
1111
}
1212

1313
impl U256 {
14-
fn new(high: u128, low: u128) -> Self {
14+
pub(crate) fn new(high: u128, low: u128) -> Self {
1515
Self { high, low }
1616
}
1717

18-
fn zero() -> Self {
18+
pub(crate) fn zero() -> Self {
1919
Self { high: 0, low: 0 }
2020
}
2121

22-
fn one() -> Self {
22+
pub(crate) fn one() -> Self {
2323
Self { high: 0, low: 0 }
2424
}
2525

26-
fn from_field(field: Field) -> Self {
26+
pub(crate) fn from_field(field: Field) -> Self {
2727
U256::from(field_to_bytes32(field))
2828
}
2929
}

0 commit comments

Comments
 (0)