Skip to content

Commit

Permalink
feat: get nested calls working
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyasRidhuan committed Dec 6, 2024
1 parent 75e4aa9 commit 8b11999
Show file tree
Hide file tree
Showing 11 changed files with 201 additions and 304 deletions.
34 changes: 17 additions & 17 deletions barretenberg/cpp/pil/avm/main.pil
Original file line number Diff line number Diff line change
Expand Up @@ -407,29 +407,29 @@ namespace main(256);
// - We then write the return location (pc + 5) into the call stack (in memory), whereby the constant 5
// corresponds to the size of the internal_call instruction in bytes.

#[RETURN_POINTER_INCREMENT]
sel_op_internal_call * (internal_return_ptr' - (internal_return_ptr + 1)) = 0;
sel_op_internal_call * (internal_return_ptr - mem_addr_b) = 0;
sel_op_internal_call * (pc' - ia) = 0;
sel_op_internal_call * ((pc + 5) - ib) = 0; // 5 = size in bytes of internal call instruction
//#[RETURN_POINTER_INCREMENT]
////sel_op_internal_call * (internal_return_ptr' - (internal_return_ptr + 1)) = 0;
//sel_op_internal_call * (internal_return_ptr - mem_addr_b) = 0;
//sel_op_internal_call * (pc' - ia) = 0;
//sel_op_internal_call * ((pc + 5) - ib) = 0; // 5 = size in bytes of internal call instruction

// TODO(md): Below relations may be removed through sub-op table lookup
sel_op_internal_call * (rwb - 1) = 0;
sel_op_internal_call * (sel_mem_op_b - 1) = 0;
//sel_op_internal_call * (rwb - 1) = 0;
//sel_op_internal_call * (sel_mem_op_b - 1) = 0;

//===== INTERNAL_RETURN ===================================================
// - We load the memory pointer to be the internal_return_ptr
// - Constrain then next program counter to be the loaded value
// - decrement the internal_return_ptr

#[RETURN_POINTER_DECREMENT]
sel_op_internal_return * (internal_return_ptr' - (internal_return_ptr - 1)) = 0;
sel_op_internal_return * ((internal_return_ptr - 1) - mem_addr_a) = 0;
sel_op_internal_return * (pc' - ia) = 0;
//#[RETURN_POINTER_DECREMENT]
//sel_op_internal_return * (internal_return_ptr' - (internal_return_ptr - 1)) = 0;
//sel_op_internal_return * ((internal_return_ptr - 1) - mem_addr_a) = 0;
//sel_op_internal_return * (pc' - ia) = 0;

// TODO(md): Below relations may be removed through sub-op table lookup
sel_op_internal_return * rwa = 0;
sel_op_internal_return * (sel_mem_op_a - 1) = 0;
//sel_op_internal_return * rwa = 0;
//sel_op_internal_return * (sel_mem_op_a - 1) = 0;

//===== CONTROL_FLOW_CONSISTENCY ============================================
pol SEL_ALL_CTRL_FLOW = sel_op_jump + sel_op_jumpi + sel_op_internal_call
Expand Down Expand Up @@ -468,17 +468,17 @@ namespace main(256);

// When considering two adjacent main trace rows,
// the internal return ptr must stay the same if not jumping or returning.
#[INTERNAL_RETURN_POINTER_CONSISTENCY]
CUR_AND_NEXT_ARE_MAIN * (1 - SEL_ALL_CTRL_FLOW) * (internal_return_ptr' - internal_return_ptr) = 0;
// #[INTERNAL_RETURN_POINTER_CONSISTENCY]
// CUR_AND_NEXT_ARE_MAIN * (1 - SEL_ALL_CTRL_FLOW) * (internal_return_ptr' - internal_return_ptr) = 0;
// TODO: for external_call and external_return the internal_return_ptr will
// actually have to be reset (to zero for an external call) or resumed
// (for an external return) and that the space_id/call_ptr will be incremented.

// TODO: we want to set an initial number for the reserved memory of the jump pointer

//====== SPACE ID CONSTRAINTS ===============================================
#[SPACE_ID_INTERNAL]
(sel_op_internal_call + sel_op_internal_return) * (space_id - constants_misc.INTERNAL_CALL_SPACE_ID) = 0;
//#[SPACE_ID_INTERNAL]
//(sel_op_internal_call + sel_op_internal_return) * (space_id - constants_misc.INTERNAL_CALL_SPACE_ID) = 0;

#[SPACE_ID_STANDARD_OPCODES]
(1 - sel_op_internal_call - sel_op_internal_return) * (call_ptr - space_id) = 0;
Expand Down
68 changes: 33 additions & 35 deletions barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -787,40 +787,39 @@ AvmFlavor::AllConstRefValues::AllConstRefValues(
, cmp_p_sub_b_lo_shift(il[779])
, cmp_sel_rng_chk_shift(il[780])
, main_da_gas_remaining_shift(il[781])
, main_internal_return_ptr_shift(il[782])
, main_l2_gas_remaining_shift(il[783])
, main_pc_shift(il[784])
, main_sel_execution_end_shift(il[785])
, main_sel_execution_row_shift(il[786])
, mem_glob_addr_shift(il[787])
, mem_rw_shift(il[788])
, mem_sel_mem_shift(il[789])
, mem_tag_shift(il[790])
, mem_tsp_shift(il[791])
, mem_val_shift(il[792])
, merkle_tree_leaf_index_shift(il[793])
, merkle_tree_leaf_value_shift(il[794])
, merkle_tree_path_len_shift(il[795])
, poseidon2_full_a_0_shift(il[796])
, poseidon2_full_a_1_shift(il[797])
, poseidon2_full_a_2_shift(il[798])
, poseidon2_full_a_3_shift(il[799])
, poseidon2_full_execute_poseidon_perm_shift(il[800])
, poseidon2_full_input_0_shift(il[801])
, poseidon2_full_input_1_shift(il[802])
, poseidon2_full_input_2_shift(il[803])
, poseidon2_full_num_perm_rounds_rem_shift(il[804])
, poseidon2_full_sel_poseidon_shift(il[805])
, poseidon2_full_start_poseidon_shift(il[806])
, slice_addr_shift(il[807])
, slice_clk_shift(il[808])
, slice_cnt_shift(il[809])
, slice_col_offset_shift(il[810])
, slice_sel_cd_cpy_shift(il[811])
, slice_sel_mem_active_shift(il[812])
, slice_sel_return_shift(il[813])
, slice_sel_start_shift(il[814])
, slice_space_id_shift(il[815])
, main_l2_gas_remaining_shift(il[782])
, main_pc_shift(il[783])
, main_sel_execution_end_shift(il[784])
, main_sel_execution_row_shift(il[785])
, mem_glob_addr_shift(il[786])
, mem_rw_shift(il[787])
, mem_sel_mem_shift(il[788])
, mem_tag_shift(il[789])
, mem_tsp_shift(il[790])
, mem_val_shift(il[791])
, merkle_tree_leaf_index_shift(il[792])
, merkle_tree_leaf_value_shift(il[793])
, merkle_tree_path_len_shift(il[794])
, poseidon2_full_a_0_shift(il[795])
, poseidon2_full_a_1_shift(il[796])
, poseidon2_full_a_2_shift(il[797])
, poseidon2_full_a_3_shift(il[798])
, poseidon2_full_execute_poseidon_perm_shift(il[799])
, poseidon2_full_input_0_shift(il[800])
, poseidon2_full_input_1_shift(il[801])
, poseidon2_full_input_2_shift(il[802])
, poseidon2_full_num_perm_rounds_rem_shift(il[803])
, poseidon2_full_sel_poseidon_shift(il[804])
, poseidon2_full_start_poseidon_shift(il[805])
, slice_addr_shift(il[806])
, slice_clk_shift(il[807])
, slice_cnt_shift(il[808])
, slice_col_offset_shift(il[809])
, slice_sel_cd_cpy_shift(il[810])
, slice_sel_mem_active_shift(il[811])
, slice_sel_return_shift(il[812])
, slice_sel_start_shift(il[813])
, slice_space_id_shift(il[814])
{}

AvmFlavor::ProverPolynomials::ProverPolynomials(ProvingKey& proving_key)
Expand Down Expand Up @@ -1619,7 +1618,6 @@ AvmFlavor::AllConstRefValues AvmFlavor::ProverPolynomials::get_row(size_t row_id
cmp_p_sub_b_lo_shift[row_idx],
cmp_sel_rng_chk_shift[row_idx],
main_da_gas_remaining_shift[row_idx],
main_internal_return_ptr_shift[row_idx],
main_l2_gas_remaining_shift[row_idx],
main_pc_shift[row_idx],
main_sel_execution_end_shift[row_idx],
Expand Down
Loading

0 comments on commit 8b11999

Please sign in to comment.