Skip to content

Commit 112f08f

Browse files
committed
fix
1 parent d681289 commit 112f08f

File tree

5 files changed

+16
-22
lines changed

5 files changed

+16
-22
lines changed

ethereum/circuits/lib/src/uint256.nr

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
use crate::misc::arrays::memcpy_up_to_length;
2-
use crate::misc::bytes32::field_to_bytes32;
31
use crate::misc::types::Bytes32;
42
use dep::bignum::bignum::BigNum;
53
use dep::bignum::U256 as u256;
6-
use dep::std::ops::Add;
7-
8-
global uint128_overflow_value: Field = 340282366920938463463374607431768211456; // 2^128
94

105
pub fn from(bytes: Bytes32) -> u256 {
116
let mut bytes33 = [0; 33];

ethereum/circuits/lib/src/uint256_test.nr

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
mod from_bytes32 {
2-
use crate::uint256::{from, from_field};
2+
use crate::uint256::from;
33
use dep::bignum::bignum::BigNum;
44
use dep::bignum::U256;
55

6-
global high: u128 = 0x10000000000000000000000000000000;
7-
global low: u128 = 0;
86
global limit_u256: U256 = U256::zero() - U256::one();
97

10-
global big_number: U256 = from_field(0x10000000000000000000000000000000);
8+
global big_number: U256 = U256::modulus().udiv(U256::from(16));
119

1210
#[test]
1311
fn zero() {
@@ -18,7 +16,7 @@ mod from_bytes32 {
1816
#[test]
1917
fn success() {
2018
let mut bytes = [0x00; 32];
21-
bytes[31] = 0x10;
19+
bytes[0] = 0x10;
2220
assert_eq(from(bytes), big_number);
2321
}
2422

@@ -30,13 +28,11 @@ mod from_bytes32 {
3028
}
3129

3230
mod into_bytes32 {
33-
use crate::uint256::{from_field, into};
31+
use crate::uint256::into;
3432
use dep::bignum::bignum::BigNum;
3533
use dep::bignum::U256;
36-
global high: u128 = 0x10000000000000000000000000000000;
37-
global low: u128 = 0;
3834

39-
global big_number: U256 = from_field(0x10000000000000000000000000000000);
35+
global big_number: U256 = U256::modulus().udiv(U256::from(16));
4036
global limit_u256: U256 = U256::zero() - U256::one();
4137

4238
#[test]
@@ -48,7 +44,7 @@ mod into_bytes32 {
4844
#[test]
4945
fn success() {
5046
let mut bytes = [0x00; 32];
51-
bytes[31] = 0x10;
47+
bytes[0] = 0x10;
5248
assert_eq(into(big_number), bytes);
5349
}
5450

ethereum/circuits/lib/src/verifiers/receipt/rlp.nr

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@ pub(crate) fn assert_receipt_rlp_equals<let MAX_ENCODED_LEN: u32>(
1414
receipt_rlp: Fragment<MAX_ENCODED_LEN, u8>,
1515
receipt: TxReceiptPartial,
1616
) {
17-
println(f"receipt_rlp: {receipt_rlp}");
1817
let receipt_rlp_list: RlpList<RECEIPT_FIELDS_COUNT> = decode_list(receipt_rlp);
1918
assert(
2019
receipt_rlp_list.len() == RECEIPT_FIELDS_COUNT,
2120
"Invalid number of fields in receipt RLP",
2221
);
23-
//println(f"receipt_rlp_list: {receipt_rlp_list}");
2422
if (is_pre_byzantium) {
2523
receipt_rlp_list.get(STATE_ROOT_INDEX).assert_eq_bytes32(
2624
"State root",

vlayer/ethereum/circuits/lib/src/slot.nr

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@ pub(crate) fn dynamic_array(slot: U256, size: Field, index: Field) -> U256 {
1717
}
1818

1919
pub(crate) fn dynamic_array_with_precalculated_slot(slot: U256, size: Field, index: Field) -> U256 {
20-
slot + from_field(size * index)
20+
let product = from_field(size * index);
21+
let sum = slot + product;
22+
assert(sum >= slot, "Attempt to add with overflow");
23+
sum
2124
}
2225

2326
pub(crate) fn struct_slot(slot: U256, offset: Field) -> U256 {
24-
slot + from_field(offset)
27+
let sum = slot + from_field(offset);
28+
assert(sum >= slot, "Attempt to add with overflow");
29+
sum
2530
}

vlayer/ethereum/circuits/lib/src/slot_test.nr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ mod dynamic_array {
8787
assert_eq(expected_slot, dynamic_array(slot, 2, 7));
8888
}
8989

90-
#[test(should_fail_with = "attempt to add with overflow")]
90+
#[test(should_fail_with = "Attempt to add with overflow")]
9191
fn fail_overflow() {
9292
let slot = from_field(6);
9393
let _ = dynamic_array(slot, 2, MAX_FIELD_VALUE);
@@ -121,7 +121,7 @@ mod dynamic_array_with_precalculated_slot {
121121
assert_eq(expected_slot, dynamic_array_with_precalculated_slot(slot, 10, 1_000_000_000));
122122
}
123123

124-
#[test(should_fail_with = "attempt to add with overflow")]
124+
#[test(should_fail_with = "Attempt to add with overflow")]
125125
fn fail_overflow() {
126126
let slot = from([0xfe; 32]);
127127
let _ = dynamic_array_with_precalculated_slot(slot, 2, MAX_FIELD_VALUE);
@@ -142,7 +142,7 @@ mod struct_slot {
142142
assert_eq(expected_slot, struct_slot(slot, 256));
143143
}
144144

145-
#[test(should_fail_with = "attempt to add with overflow")]
145+
#[test(should_fail_with = "Attempt to add with overflow")]
146146
fn overflow() {
147147
let slot = from([0xff; 32]);
148148
let _ = struct_slot(slot, 256);

0 commit comments

Comments
 (0)