Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
hduoc2003 committed Sep 19, 2024
1 parent 554399c commit a210e3f
Show file tree
Hide file tree
Showing 7 changed files with 18,486 additions and 2,016 deletions.
6 changes: 6 additions & 0 deletions libs/sources/bytes.move
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ module lib_addr::bytes {
vector::reverse(&mut bytes);
to_u256(bytes)
}

public fun merge_num_offset_8(a: u256, b: u256): u256 {
a = a & ((1 << 192) - 1);
b = b >> 192;
(a << 64) | b
}
}

#[test_only]
Expand Down
6 changes: 2 additions & 4 deletions verifier/sources/cpu/layout7/stark_verifier.move
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ module verifier_addr::stark_verifier_7 {
use std::signer::address_of;
use std::vector::{append, borrow, length, slice, borrow_mut};
use aptos_std::aptos_hash::keccak256;
use aptos_std::debug::print;
use cpu_constraint_poly_addr::cpu_constraint_poly;

use cpu_addr::cpu_oods_7;
Expand All @@ -12,7 +11,7 @@ module verifier_addr::stark_verifier_7 {
get_offset_page_size, get_public_input_length
};

use lib_addr::bytes::{bytes32_to_u256, num_to_bytes_le, vec_to_bytes_le};
use lib_addr::bytes::{bytes32_to_u256, num_to_bytes_le, vec_to_bytes_le, merge_num_offset_8};
use lib_addr::prime_field_element_0::{fadd, fmul, fpow, fsub, inverse};
use lib_addr::vector::{append_vector, assign, set_el, trim_only};
use verifier_addr::fact_registry::is_valid;
Expand Down Expand Up @@ -418,7 +417,7 @@ module verifier_addr::stark_verifier_7 {
// This array will be sent to the OODS contract.
let proof_data_chunk_end = proof_ptr + row_size;
while (proof_ptr < proof_data_chunk_end) {
set_el(ctx, proof_data_ptr, proof_ptr_offset_val);
set_el(ctx, proof_data_ptr, merge_num_offset_8(*borrow(proof, proof_ptr), *borrow(proof, proof_ptr + 1)));
proof_data_ptr = proof_data_ptr + 1;
proof_ptr = proof_ptr + 1;
};
Expand Down Expand Up @@ -885,7 +884,6 @@ module verifier_addr::stark_verifier_7 {
page_addr
])));

print(&num_to_bytes_le(&fact_hash));
assert!(is_valid(signer_addr, fact_hash), EMEMORY_PAGE_FACT_NOT_REGISTERED);
};
}
Expand Down
44 changes: 43 additions & 1 deletion verifier/sources/fri_statement_contract.move
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ module verifier_addr::fri_statement_contract {
use verifier_addr::fact_registry::register_fact;
use verifier_addr::fri::{get_fri, new_fri, update_fri};

#[test_only]
use verifier_addr::fri_layer;
#[test_only]
use verifier_addr::merkle_verifier;

// This line is used for generating constants DO NOT REMOVE!
// 3
const EFRI_QUEUE_MUST_BE_COMPOSED_OF_TRIPLETS_PLUS_ONE_DELIMITER_CELL: u64 = 0x3;
Expand Down Expand Up @@ -40,7 +45,7 @@ module verifier_addr::fri_statement_contract {
}

#[event]
struct ComputeNextLayer has store, drop {
struct ComputeNextLayer has store, drop, copy {
channel_ptr: u64,
fri_queue_ptr: u64,
merkle_queue_ptr: u64,
Expand Down Expand Up @@ -182,4 +187,41 @@ module verifier_addr::fri_statement_contract {
EINVALID_QUERIES_RANGE
);
}

#[test_only]
public fun init_fri_group_test(signer: &signer, data: FriCtx) {
fri_layer::init_fri_group(signer, data.fri_ctx);
}

#[test_only]
public fun compute_next_layer_test(signer: &signer, data: ComputeNextLayer) {
fri_layer::compute_next_layer(signer,
data.channel_ptr,
data.fri_queue_ptr,
data.merkle_queue_ptr,
data.n_queries,
data.fri_ctx,
data.evaluation_point,
data.fri_coset_size
);
}

#[test_only]
public fun merkle_verifier_verify_merkle_test(signer: &signer, data: ComputeNextLayer, expected_root: u256) {
merkle_verifier::verify_merkle(signer,
data.channel_ptr,
data.merkle_queue_ptr,
expected_root,
data.n_queries,
);
}

#[test_only]
public fun register_fact_verify_fri_test(signer: &signer, data: RegisterFactVerifyFri, data2: ComputeNextLayer) {
register_fact_verify_fri(signer,
data.data_to_hash,
data.fri_queue_ptr,
data2.n_queries
);
}
}
Loading

0 comments on commit a210e3f

Please sign in to comment.