Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor get_storage_value
Browse files Browse the repository at this point in the history
Pasifaee committed May 28, 2024
1 parent f869f18 commit fca07e1
Showing 2 changed files with 18 additions and 11 deletions.
28 changes: 18 additions & 10 deletions ethereum/circuits/lib/src/account_with_storage.nr
Original file line number Diff line number Diff line change
@@ -75,17 +75,25 @@ fn assert_storage_key_equals(
);
}

fn get_fragment<N>(left_padded_value: [u8; N]) -> Fragment<N, u8> {
let value_len = right_pad(left_padded_value).len();
let value_offset = N - value_len;
Fragment::new(value_offset, value_len, left_padded_value)
}

fn get_storage_value(rlp_encoded_value: [u8; MAX_STORAGE_VALUE_LEN]) -> [u8; MAX_STORAGE_VALUE_LEN] {
let mut storage_value = rlp_encoded_value;
let rlp_value_len = right_pad(rlp_encoded_value).len();
let left_pad_len = MAX_STORAGE_VALUE_LEN - rlp_value_len;
let rlp_fragment = decode_string(Fragment::new(left_pad_len, rlp_value_len, rlp_encoded_value));
if rlp_fragment.offset > 0 {
assert_eq(rlp_fragment.offset, 1, "Expected RLP header to be maximum 1 byte long");
storage_value[left_pad_len] = 0;
let mut storage_value = get_fragment(rlp_encoded_value);
let rlp_fragment = decode_string(storage_value);
let rlp_header_len = rlp_fragment.offset;

// Storage value is maximum 32 bytes long, so its RLP-encoding's header is maximum 1 byte long.
assert(rlp_header_len <= 1, "Expected RLP header to be maximum 1 byte long");
if rlp_fragment.offset == 1 {
let rlp_header_position = storage_value.offset;
storage_value.data[rlp_header_position] = 0;
}

storage_value
storage_value.data
}

pub fn get_account_with_storage(
@@ -120,8 +128,8 @@ unconstrained fn get_proof_unconstrained(
storage_key: Bytes32
) -> StateAndStorageProofInput {
let (account, state_proof_input, storage_proof_input) = get_proof_oracle(chain_id, block_no, address, storage_key);
let state_proof_input: ProofInput<MAX_PREFIXED_KEY_NIBBLE_LEN, MAX_ACCOUNT_STATE_LEN, MAX_ACCOUNT_DEPTH_NO_LEAF_M, MAX_ACCOUNT_LEAF_LEN> = Serde::deserialize(state_proof_input);
let storage_proof_input: ProofInput<MAX_PREFIXED_KEY_NIBBLE_LEN, MAX_STORAGE_VALUE_LEN, MAX_STORAGE_DEPTH_NO_LEAF_M, MAX_STORAGE_LEAF_LEN> = Serde::deserialize(storage_proof_input);
let state_proof_input = Serde::deserialize(state_proof_input);
let storage_proof_input = Serde::deserialize(storage_proof_input);

StateAndStorageProofInput { account, state_proof_input, storage_proof_input }
}
1 change: 0 additions & 1 deletion ethereum/circuits/lib/src/verifiers/storage.nr
Original file line number Diff line number Diff line change
@@ -8,7 +8,6 @@ pub fn verify_storage_values<N, MAX_STORAGE_DEPTH_NO_LEAF>(
storage_root: Bytes32
) {
for i in 0..N {
// verify_storage_value(storage_root, proofs[i]);
let proof_input = proof_inputs[i];
verify_merkle_proof(
proof_input.key,

0 comments on commit fca07e1

Please sign in to comment.