Skip to content

Commit

Permalink
refactor: DequeueNextAs always points to proof item's payload
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-ferdinand committed Feb 6, 2024
1 parent 9346159 commit d7ac0c3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
16 changes: 0 additions & 16 deletions tasm-lib/src/recufier/fri_verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,19 +639,6 @@ impl BasicSnippet for FriVerify {
}),
}));

// BEFORE: _ *xfe_list_size
// AFTER: _ *xfe_list
let verifiably_access_x_field_elements_lists = triton_asm! {
read_mem 1 // _ size *xfe_list_size-1
push 2 add // _ size *num_xfes
read_mem 1 // _ size num_elements *xfe_list_size
push 1 add // _ size num_elements *new_list
swap 2 swap 1 // _ *new_list size num_elements
push 3 mul // _ *new_list size num_elements*3 (<-- 3 BFEs per XFE)
push 1 add // _ *new_list size num_elements*3+1 (<-- +1 for length indicator)
eq assert // _ *new_list
};

triton_asm! {
// INVARIANT: _ *alphas current_tree_height *a_indices *a_elements *revealed_indices_and_leafs current_domain_length r half_domain_length *b_indices *b_elements *fri_verify current_tree_height-1 half_domain_length *c_indices *c_values i
{compute_c_values_loop}:
Expand Down Expand Up @@ -861,7 +848,6 @@ impl BasicSnippet for FriVerify {
call {proof_stream_dequeue_next_as_fri_codeword}
hint last_fri_codeword: ListPointer = stack[0]
// _ *proof_stream *fri_verify num_rounds last_round_max_degree 0 *roots *alphas *last_codeword
{&verifiably_access_x_field_elements_lists}
dup 7 swap 1 // _ *proof_stream *fri_verify num_rounds last_round_max_degree 0 *roots *alphas *proof_iter *last_codeword

// clone last codeword for later use
Expand Down Expand Up @@ -956,7 +942,6 @@ impl BasicSnippet for FriVerify {

// assert correct length of number of leafs
{&revealed_leafs} // _ *proof_stream *fri_verify num_rounds last_round_max_degree *last_codeword' *roots *alphas tree_height *indices *a_elements
{&verifiably_access_x_field_elements_lists}
dup 1 dup 1 // _ *proof_stream *fri_verify num_rounds last_round_max_degree *last_codeword' *roots *alphas tree_height *indices *a_elements *indices *a_elements
call {length_of_list_of_xfes}
// _ *proof_stream *fri_verify num_rounds last_round_max_degree *last_codeword' *roots *alphas tree_height *indices *a_elements *indices num_leafs
Expand Down Expand Up @@ -1052,7 +1037,6 @@ impl BasicSnippet for FriVerify {
call {proof_stream_dequeue_next_as_fri_response}
// _ *proof_stream *fri_verify num_rounds last_round_max_degree *last_codeword' *roots *alphas current_tree_height *a_indices *a_elements *revealed_indices_and_leafs current_domain_length r half_domain_length *b_indices *fri_response
{&revealed_leafs} // _ *proof_stream *fri_verify num_rounds last_round_max_degree *last_codeword' *roots *alphas current_tree_height *a_indices *a_elements *revealed_indices_and_leafs current_domain_length r half_domain_length *b_indices *b_elements
{&verifiably_access_x_field_elements_lists}
hint b_elements: Pointer = stack[0]

// if in first round (r==0), populate second half of return vector
Expand Down
33 changes: 29 additions & 4 deletions tasm-lib/src/recufier/proof_stream/dequeue_next_as.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,23 @@ impl DequeueNextAs {
push 2 add add // _ *next_proof_item_size
}
}

/// ```text
/// BEFORE: _ *proof_item_size
/// AFTER: _ *proof_item_payload
/// ```
fn advance_list_element_pointer_to_proof_item_payload(&self) -> Vec<LabelledInstruction> {
let payload_length_indicator_size = match self.proof_item.payload_static_length() {
Some(_) => 0,
None => 1,
};
let list_item_length_indicator_size = 1;
let discriminant_size = 1;
let bookkeeping_offset =
payload_length_indicator_size + list_item_length_indicator_size + discriminant_size;

triton_asm! { push {bookkeeping_offset} hint bookkeeping_offset = stack[0] add }
}
}

impl BasicSnippet for DequeueNextAs {
Expand Down Expand Up @@ -150,9 +167,8 @@ impl BasicSnippet for DequeueNextAs {
{&self.update_proof_item_iter_to_next_proof_item()}
// _ *proof_item_size

push 2 add // _ *proof_item_payload
{final_hint}

{&self.advance_list_element_pointer_to_proof_item_payload()}
{final_hint} // _ *proof_item_payload
return
}
}
Expand Down Expand Up @@ -243,7 +259,16 @@ mod test {
}

fn proof_item_payload_pointer(&self) -> BFieldElement {
self.discriminant_pointer() + BFieldElement::one()
self.discriminant_pointer()
+ BFieldElement::one()
+ self.proof_item_payload_size_indicator_length()
}

fn proof_item_payload_size_indicator_length(&self) -> BFieldElement {
match self.dequeue_next_as.proof_item.payload_static_length() {
Some(_) => BFieldElement::zero(),
None => BFieldElement::one(),
}
}

fn assert_correct_discriminant(&self) {
Expand Down

0 comments on commit d7ac0c3

Please sign in to comment.