Skip to content

Commit 79c2ecf

Browse files
committed
fix
1 parent f2aaf16 commit 79c2ecf

33 files changed

+262
-206
lines changed

ethereum/circuits/lib/src/account.nr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ type AccountWithStateProofM = (Account, ProofInput<MAX_PREFIXED_KEY_NIBBLE_LEN,
2828
type ProofInputSerialized<let LEN: u32> = [Field; LEN];
2929

3030
pub fn get_account(chain_id: u32, block_no: u64, address: Address) -> AccountWithinBlock {
31-
let (account, state_proof) = get_account_unconstrained_M(chain_id, block_no, address);
31+
// Safety: verification done separately
32+
let (account, state_proof) =
33+
unsafe { get_account_unconstrained_M(chain_id, block_no, address) };
3234
let header = get_header(chain_id, block_no);
3335
verify_account(address, account, state_proof, header.state_root);
3436
AccountWithinBlock { account, block_hash: header.hash }

ethereum/circuits/lib/src/account_int_test.nr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ use dep::std::test::OracleMock;
1818

1919
#[test]
2020
fn test_get_account_success() {
21-
// Unsafe: test
21+
// Safety: test
2222
let _ =
2323
unsafe { OracleMock::mock("get_header").returns((block_header_partial, block_header_rlp)) };
24-
// Unsafe: test
24+
// Safety: test
2525
let _ =
2626
unsafe { OracleMock::mock("get_account").returns((account, state_proof_input_serialized)) };
2727

@@ -37,10 +37,10 @@ fn test_get_account_success() {
3737

3838
#[test(should_fail)]
3939
fn test_get_account_wrong_state_root() {
40-
// Unsafe: test
40+
// Safety: test
4141
let _ =
4242
unsafe { OracleMock::mock("get_header").returns((block_header_partial, block_header_rlp)) };
43-
// Unsafe: test
43+
// Safety: test
4444
let _ = unsafe {
4545
OracleMock::mock("get_account").returns((
4646
account_from_different_header, state_proof_input_from_different_header_serialized,

ethereum/circuits/lib/src/account_with_storage.nr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,9 @@ pub fn get_account_with_storage(
108108
) -> StorageWithinBlock<1> {
109109
let BlockHeaderPartial { number: _, hash, state_root, transactions_root: _, receipts_root: _ }
110110
= get_header(chain_id, block_number);
111+
// Safety: veirfication done separately
111112
let StateAndStorageProofInput { account, state_proof_input, storage_proof_input } =
112-
get_proof_unconstrained(chain_id, block_number, address, storage_key);
113+
unsafe { get_proof_unconstrained(chain_id, block_number, address, storage_key) };
113114

114115
verify_account(address, account, state_proof_input, state_root);
115116
verify_storage_values([storage_proof_input], account.storage_root);

ethereum/circuits/lib/src/account_with_storage_int_test.nr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ use dep::std::test::OracleMock;
2525

2626
#[test]
2727
fn test_get_account_with_storage_success() {
28-
// Unsafe: test
28+
// Safety: test
2929
let _ =
3030
unsafe { OracleMock::mock("get_header").returns((block_header_partial, block_header_rlp)) };
31-
// Unsafe: test
31+
// Safety: test
3232
let _ = unsafe {
3333
OracleMock::mock("get_proof").returns((
3434
account, state_proof_input_serialized, proofs_serialized[0],
@@ -50,13 +50,13 @@ fn test_get_account_with_storage_success() {
5050

5151
#[test(should_fail_with = "Invalid node hash")]
5252
fn test_get_account_with_storage_invalid_state_root() {
53-
// Unsafe: test
53+
// Safety: test
5454
let _ = unsafe {
5555
OracleMock::mock("get_header").returns((
5656
crypto_punks_block_header_partial, crypto_punks_block_header_rlp,
5757
))
5858
};
59-
// Unsafe: test
59+
// Safety: test
6060
let _ = unsafe {
6161
OracleMock::mock("get_proof").returns((
6262
account, state_proof_input_serialized, proofs_serialized[0],
@@ -78,7 +78,7 @@ fn test_get_account_with_storage_invalid_storage_root() {
7878
crypto_punks_block_header_partial, crypto_punks_block_header_rlp,
7979
))
8080
};
81-
// Unsafe: test
81+
// Safety: test
8282
let _ = unsafe {
8383
OracleMock::mock("get_proof").returns((
8484
crypto_punks_account, crypto_punks_state_proof_input_serialized, proofs_serialized[0],
@@ -95,10 +95,10 @@ fn test_get_account_with_storage_invalid_storage_root() {
9595

9696
#[test(should_fail_with = "Storage key does not match the argument")]
9797
fn test_get_account_with_storage_storage_key_does_not_match_the_argument() {
98-
// Unsafe: test
98+
// Safety: test
9999
let _ =
100100
unsafe { OracleMock::mock("get_header").returns((block_header_partial, block_header_rlp)) };
101-
// Unsafe: test
101+
// Safety: test
102102
let _ = unsafe {
103103
OracleMock::mock("get_proof").returns((
104104
account, state_proof_input_serialized, proofs_serialized[0],

ethereum/circuits/lib/src/account_with_storage_recursive.nr

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use crate::account_with_storage::StorageWithinBlock;
22
use crate::misc::{fragment::Fragment, types::{Address, ADDRESS_LENGTH, Bytes32, BYTES32_LENGTH}};
3+
use crate::serde::Serde;
34
use crate::serde::STORAGE_BLOCK_LEN;
4-
use dep::std::verify_proof;
5+
use dep::std::verify_proof_with_type;
56

67
pub struct RecursiveProof {
78
key_hash: Field,
@@ -17,12 +18,14 @@ pub fn get_account_with_storage_recursive(
1718
address: Address,
1819
storage_key: Bytes32,
1920
) -> StorageWithinBlock<1> {
20-
let (storage_within_block, RecursiveProof { key_hash, verification_key, proof }) = get_account_with_storage_recursive_unconstrained(
21-
chain_id,
22-
block_number,
23-
address,
24-
storage_key,
25-
);
21+
let (storage_within_block, RecursiveProof { key_hash, verification_key, proof }) = unsafe {
22+
get_account_with_storage_recursive_unconstrained(
23+
chain_id,
24+
block_number,
25+
address,
26+
storage_key,
27+
)
28+
};
2629

2730
let mut public_inputs: Fragment<NUM_PUBLIC_INPUTS, Field> = Fragment::empty();
2831
public_inputs.push_back(chain_id as Field);
@@ -31,11 +34,12 @@ pub fn get_account_with_storage_recursive(
3134
public_inputs.extend_back(storage_key.serialize());
3235
public_inputs.extend_back(storage_within_block.serialize());
3336

34-
verify_proof(
37+
verify_proof_with_type(
3538
verification_key,
3639
proof,
3740
public_inputs.to_array::<NUM_PUBLIC_INPUTS>(),
3841
key_hash,
42+
1, // TODO: Need to confirm it's meant to non zk honk proof
3943
);
4044

4145
storage_within_block
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
mod header;
1+
pub(crate) mod header;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::misc::fragment::Fragment;
22
use crate::receipt::{ForeignCallTxReceiptPartial, TxReceiptPartial};
33
use crate::receipt::TxType;
44

5-
global tx_type: TxType = 2;
5+
pub(crate) global tx_type: TxType = 2;
66
global receipt_rlp: [u8; 999] = [
77
0xf9, 0x01, 0xa7, 0x01, 0x83, 0x80, 0x9b, 0x29, 0xb9, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
88
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,

0 commit comments

Comments
 (0)