Skip to content

Commit 4eabe3f

Browse files
committed
fix u128 tests
1 parent 62f0c4e commit 4eabe3f

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

.github/workflows/circuits_e2e.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ jobs:
7676
7777
- name: Generate Proofs
7878
run: |
79+
export PATH="$HOME/.bb:$PATH"
7980
bb prove -b ./ethereum/circuits/get_header/target/get_header.json -w ./ethereum/circuits/get_header/target/get_header.gz -o ./ethereum/circuits/get_header/target/proof
8081
bb prove -b ./ethereum/circuits/get_account/target/get_account.json -w ./ethereum/circuits/get_account/target/get_account.gz -o ./ethereum/circuits/get_account/target/proof
8182
bb prove -b ./ethereum/circuits/get_storage/target/get_storage.json -w ./ethereum/circuits/get_storage/target/get_storage.gz -o ./ethereum/circuits/get_storage/target/proof
@@ -98,10 +99,12 @@ jobs:
9899
99100
- name: Generate Recursive Proof
100101
run: |
102+
export PATH="$HOME/.bb:$PATH"
101103
bb prove -b ./vlayer/examples/circuits/is_dao_worthy_recursive/target/is_dao_worthy_recursive.json -w ./vlayer/examples/circuits/is_dao_worthy_recursive/target/is_dao_worthy_recursive.gz -o ./vlayer/examples/circuits/is_dao_worthy_recursive/target/proof
102104
103105
- name: Generate Verification Keys
104106
run: |
107+
export PATH="$HOME/.bb:$PATH"
105108
bb write_vk -b ./ethereum/circuits/get_header/target/get_header.json -o ./ethereum/circuits/get_header/target/vk
106109
bb write_vk -b ./ethereum/circuits/get_account/target/get_account.json -o ./ethereum/circuits/get_account/target/vk
107110
bb write_vk -b ./ethereum/circuits/get_storage/target/get_storage.json -o ./ethereum/circuits/get_storage/target/vk
@@ -113,6 +116,7 @@ jobs:
113116
114117
- name: Verify Proofs
115118
run: |
119+
export PATH="$HOME/.bb:$PATH"
116120
bb verify -k ./ethereum/circuits/get_header/target/vk -p ./ethereum/circuits/get_header/target/proof
117121
bb verify -k ./ethereum/circuits/get_account/target/vk -p ./ethereum/circuits/get_account/target/proof
118122
bb verify -k ./ethereum/circuits/get_storage/target/vk -p ./ethereum/circuits/get_storage/target/proof

ethereum/oracles/src/noir/oracles/common/encode.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,16 @@ describe('encodeField', () => {
6060

6161
describe('encodeU128', () => {
6262
it('should encode 1 correctly', () => {
63-
expect(encodeU128(1n)).toStrictEqual(['0x', '0x01']);
63+
expect(encodeU128(1n)).toStrictEqual('0x01');
6464
});
6565
it('should encode 255 correctly', () => {
66-
expect(encodeU128(255n)).toStrictEqual(['0x', '0xff']);
66+
expect(encodeU128(255n)).toStrictEqual('0xff');
6767
});
6868
it('should encode large values correctly', () => {
69-
expect(encodeU128(100500n)).toStrictEqual(['0x', '0x018894']);
69+
expect(encodeU128(100500n)).toStrictEqual('0x018894');
7070
});
7171
it('should encode values over 64 bits correctly', () => {
72-
expect(encodeU128(2n ** 64n)).toStrictEqual(['0x01', '0x']);
72+
expect(encodeU128(2n ** 64n)).toStrictEqual('0x010000000000000000');
7373
});
7474
});
7575

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use dep::bignum::U256;
2-
use dep::ethereum::{misc::types::Bytes32, uint256::{from, from_field, into}};
2+
use dep::ethereum::{misc::types::Bytes32, uint256::{from, into}};
33
use dep::keccak256::keccak256;
44

55
global STORAGE_KEY_HASH_INPUT_LENGTH: u32 = 64;
@@ -16,15 +16,28 @@ pub(crate) fn dynamic_array(slot: U256, size: Field, index: Field) -> U256 {
1616
dynamic_array_with_precalculated_slot(start, size, index)
1717
}
1818

19+
// Convert Field to U256 without using from_field to avoid independent subgraph issues
20+
fn field_to_u256(f: Field) -> U256 {
21+
let bytes = f.to_be_bytes();
22+
from(bytes)
23+
}
24+
1925
pub(crate) fn dynamic_array_with_precalculated_slot(slot: U256, size: Field, index: Field) -> U256 {
20-
let product = from_field(size * index);
26+
let product = field_to_u256(size * index);
2127
let sum = slot + product;
22-
assert(sum >= slot, "Attempt to add with overflow");
28+
// Check no overflow by verifying: sum - slot == product
29+
// This constrains the overflow check to the circuit by using field arithmetic
30+
let diff = sum - slot;
31+
assert(diff == product, "Attempt to add with overflow");
2332
sum
2433
}
2534

2635
pub(crate) fn struct_slot(slot: U256, offset: Field) -> U256 {
27-
let sum = slot + from_field(offset);
28-
assert(sum >= slot, "Attempt to add with overflow");
36+
let offset_u256 = field_to_u256(offset);
37+
let sum = slot + offset_u256;
38+
// Check no overflow by verifying: sum - slot == offset
39+
// This constrains the overflow check to the circuit by using field arithmetic
40+
let diff = sum - slot;
41+
assert(diff == offset_u256, "Attempt to add with overflow");
2942
sum
3043
}

0 commit comments

Comments
 (0)