Skip to content

Commit

Permalink
Merge branch 'master' into spy/gas-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
spypsy committed Nov 14, 2024
2 parents 31449f7 + 7e587d6 commit 9af92ea
Show file tree
Hide file tree
Showing 1,177 changed files with 69,863 additions and 17,917 deletions.
9 changes: 1 addition & 8 deletions .github/ci-setup-action/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,11 @@ runs:
echo HOME=$RUN_HOME >> $GITHUB_ENV
mkdir -p $RUN_HOME
- name: Cache Submodules
id: cache-submodules
uses: actions/cache@v4
with:
path: .git/modules
key: submodules-${{ hashFiles('.gitmodules') }}-spot-ebs

- name: Checkout Submodules
shell: bash
run: |
git config --global --add safe.directory '*'
git submodule sync --recursive && git submodule update --init --recursive
git submodule update --init --recursive
# TODO reconsider how jq gets into image
- name: Setup jq
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -700,10 +700,9 @@ jobs:
values: 16-validators
runner_type: 16core-tester-x86
timeout: 60
# TODO(#9736)
# - test: transfer.test.ts
# values: 48-validators
# runner_type: 32core-tester-x86
- test: transfer.test.ts
values: 48-validators
runner_type: 32core-tester-x86
- test: reorg.test.ts
values: 16-validators
runner_type: 16core-tester-x86-high-memory
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/publish-aztec-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,11 @@ jobs:
working-directory: ./aztec-up/terraform
run: |
terraform init
TAG=${{ env.DEPLOY_TAG }}
if [ "${{ github.ref_name }}" == "master" ]; then
TAG=master
else
TAG=${{ env.DEPLOY_TAG }}
fi
export TF_VAR_VERSION=${TAG#aztec-packages-v}
terraform apply -auto-approve
Expand Down
20 changes: 10 additions & 10 deletions avm-transpiler/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 34 additions & 25 deletions avm-transpiler/src/transpile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,16 +306,12 @@ pub fn brillig_to_avm(brillig_bytecode: &[BrilligOpcode<FieldElement>]) -> (Vec<
}
BrilligOpcode::Return {} => avm_instrs
.push(AvmInstruction { opcode: AvmOpcode::INTERNALRETURN, ..Default::default() }),
BrilligOpcode::Stop { return_data_offset, return_data_size } => {
avm_instrs.push(AvmInstruction {
opcode: AvmOpcode::RETURN,
indirect: Some(AddressingModeBuilder::default().build()),
operands: vec![
AvmOperand::U16 { value: *return_data_offset as u16 },
AvmOperand::U16 { value: *return_data_size as u16 },
],
..Default::default()
});
BrilligOpcode::Stop { return_data } => {
generate_return_instruction(
&mut avm_instrs,
&return_data.pointer,
&return_data.size,
);
}
BrilligOpcode::Trap { revert_data } => {
generate_revert_instruction(
Expand Down Expand Up @@ -960,6 +956,28 @@ fn generate_revert_instruction(
});
}

/// Generates an AVM RETURN instruction.
fn generate_return_instruction(
avm_instrs: &mut Vec<AvmInstruction>,
return_data_pointer: &MemoryAddress,
return_data_size_offset: &MemoryAddress,
) {
avm_instrs.push(AvmInstruction {
opcode: AvmOpcode::RETURN,
indirect: Some(
AddressingModeBuilder::default()
.indirect_operand(return_data_pointer)
.direct_operand(return_data_size_offset)
.build(),
),
operands: vec![
AvmOperand::U16 { value: return_data_pointer.to_usize() as u16 },
AvmOperand::U16 { value: return_data_size_offset.to_usize() as u16 },
],
..Default::default()
});
}

/// Generates an AVM MOV instruction.
fn generate_mov_instruction(
indirect: Option<AvmOperand>,
Expand Down Expand Up @@ -1323,25 +1341,16 @@ fn handle_return(
destinations: &Vec<ValueOrArray>,
inputs: &Vec<ValueOrArray>,
) {
assert!(inputs.len() == 1);
assert!(inputs.len() == 2);
assert!(destinations.len() == 0);

let (return_data_offset, return_data_size) = match inputs[0] {
ValueOrArray::HeapArray(HeapArray { pointer, size }) => (pointer, size as u32),
_ => panic!("Return instruction's args input should be a HeapArray"),
// First arg is the size, which is ignored because it's redundant.
let (return_data_offset, return_data_size) = match inputs[1] {
ValueOrArray::HeapVector(HeapVector { pointer, size }) => (pointer, size),
_ => panic!("Revert instruction's args input should be a HeapVector"),
};

avm_instrs.push(AvmInstruction {
opcode: AvmOpcode::RETURN,
indirect: Some(
AddressingModeBuilder::default().indirect_operand(&return_data_offset).build(),
),
operands: vec![
AvmOperand::U16 { value: return_data_offset.to_usize() as u16 },
AvmOperand::U16 { value: return_data_size as u16 },
],
..Default::default()
});
generate_return_instruction(avm_instrs, &return_data_offset, &return_data_size);
}

// #[oracle(avmOpcodeRevert)]
Expand Down
2 changes: 1 addition & 1 deletion aztec-nargo/compile_then_postprocess.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fi
shift # remove the compile arg so we can inject --show-artifact-paths

# Forward all arguments to nargo, tee output to console
artifacts_to_process=$($NARGO compile --show-artifact-paths $@ | tee /dev/tty | grep -oP 'Saved contract artifact to: \K.*')
artifacts_to_process=$($NARGO compile --inliner-aggressiveness 0 --show-artifact-paths $@ | tee /dev/tty | grep -oP 'Saved contract artifact to: \K.*')

# NOTE: the output that is teed to /dev/tty will normally not be redirectable by the caller.
# If the script is run via docker, however, the user will see this output on stdout and will be able to redirect.
Expand Down
4 changes: 2 additions & 2 deletions barretenberg/.gitrepo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[subrepo]
remote = https://github.com/AztecProtocol/barretenberg
branch = master
commit = 1a334c80aa8d74abe81a216d7995b21dabef4dd3
parent = 23c122d36091b3b756084584ecba59b800196d58
commit = e13d72485ea6fc45715ce424b2e1a88f7d21376e
parent = 5997c823077d686107408caa8b4d148e115b62ac
method = merge
cmdver = 0.4.6
2 changes: 1 addition & 1 deletion barretenberg/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ option(DISABLE_AZTEC_VM "Don't build Aztec VM (acceptable if iterating on core p
option(MULTITHREADING "Enable multi-threading" ON)
option(OMP_MULTITHREADING "Enable OMP multi-threading" OFF)
option(FUZZING "Build ONLY fuzzing harnesses" OFF)
option(ENABLE_PAR_ALGOS "Enable parallel algorithms" ON)
option(ENABLE_PAR_ALGOS "Enable parallel algorithms" OFF)
option(COVERAGE "Enable collecting coverage from tests" OFF)
option(ENABLE_ASAN "Address sanitizer for debugging tricky memory corruption" OFF)
option(ENABLE_HEAVY_TESTS "Enable heavy tests when collecting coverage" OFF)
Expand Down
13 changes: 9 additions & 4 deletions barretenberg/cpp/pil/avm/alu.pil
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,21 @@ namespace alu(256);
pol commit cmp_gadget_input_b;
pol commit cmp_gadget_result;
pol commit cmp_gadget_gt;
pol commit cmp_gadget_non_ff_gt;

// We use the comparison gadget to test GT for the following operations
cmp_gadget_gt = op_lt + op_lte + op_div + op_shr + op_shl;
pol CMP_GADGET_GT = op_lt + op_lte + op_div + op_shr + op_shl;
cmp_gadget_gt = CMP_GADGET_GT * ff_tag;
cmp_gadget_non_ff_gt = CMP_GADGET_GT * (1 - ff_tag);

// The cmp gadget is on when we are either testing GT or EQ
cmp_gadget_sel - (cmp_gadget_gt + op_eq) = 0;
cmp_gadget_sel - (cmp_gadget_gt + op_eq + cmp_gadget_non_ff_gt) = 0;

// Permutation to the Comparison Gadget
#[PERM_CMP_ALU]
cmp.sel_cmp {cmp.clk, cmp.input_a, cmp.input_b, cmp.result, cmp.op_eq, cmp.op_gt}
cmp.sel_cmp {cmp.clk, cmp.input_a, cmp.input_b, cmp.result, cmp.op_eq, cmp.op_gt, cmp.op_non_ff_gt}
is
cmp_gadget_sel {clk, cmp_gadget_input_a, cmp_gadget_input_b, cmp_gadget_result, op_eq, cmp_gadget_gt };
cmp_gadget_sel {clk, cmp_gadget_input_a, cmp_gadget_input_b, cmp_gadget_result, op_eq, cmp_gadget_gt, cmp_gadget_non_ff_gt };


// =============== HELPER POLYNOMIAL RELATIONS =================================================
Expand Down Expand Up @@ -143,6 +147,7 @@ namespace alu(256);

// This holds the product over the integers
// (u1 multiplication only cares about a_lo and b_lo)
// TODO(9937): The following is not well constrained as this expression overflows the field.
pol PRODUCT = a_lo * b_lo + (1 - u1_tag) * (LIMB_BITS_POW * partial_prod_lo + MAX_BITS_POW * (partial_prod_hi + a_hi * b_hi));

// =============== ADDITION/SUBTRACTION Operation Constraints =================================================
Expand Down
21 changes: 20 additions & 1 deletion barretenberg/cpp/pil/avm/gadgets/cmp.pil
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,25 @@ namespace cmp(256);
pol commit input_b;
pol commit result;

// ========= NON FF GT Short-circuit computation ===============================
// If this is a non-ff check, we can short circuit (a > b) by checking
// 0 < a - b - 1 < 2**128 --> i.e. we just check we dont underlow which for "small" sized 128-bit number is just a
// single 128 bit range check
// This will be constrained by the calling function - maybe through instruction decomposition
pol commit op_non_ff_gt;
// Value of a - b
pol commit diff;

pol A_GT_B = input_a - input_b - 1;
pol B_GTE_A = input_b - input_a;
op_non_ff_gt * (diff - (A_GT_B * result) - (B_GTE_A * (1 - result))) = 0;

#[PERM_RNG_NON_FF_CMP]
range_check.cmp_non_ff_rng_chk {range_check.clk, range_check.value}
is
op_non_ff_gt {range_chk_clk, diff};

// ========= FF GT computation ===============================
// We range check two columns per row of the cmp gadget, the lo and hi bit ranges resp.
#[PERM_RNG_CMP_LO]
range_check.cmp_lo_bits_rng_chk {range_check.clk, range_check.value}
Expand All @@ -32,7 +51,7 @@ namespace cmp(256);
pol commit op_eq;
pol commit op_gt;

sel_cmp = op_eq + op_gt;
sel_cmp = op_eq + op_gt + op_non_ff_gt;

// There are some standardised constraints on this gadget
// The result is always a boolean
Expand Down
3 changes: 3 additions & 0 deletions barretenberg/cpp/pil/avm/gadgets/range_check.pil
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ namespace range_check(256);
// We range check 128 bits in the cmp trace
cmp_lo_bits_rng_chk * (rng_chk_bits - 128) = 0;
cmp_hi_bits_rng_chk * (rng_chk_bits - 128) = 0;
// For non FF
pol commit cmp_non_ff_rng_chk;
cmp_non_ff_rng_chk * (rng_chk_bits - 128) = 0;

// ==== ALU TRACE RANGE CHECKS ====
pol commit alu_rng_chk;
23 changes: 15 additions & 8 deletions barretenberg/cpp/pil/avm/gas.pil
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,20 @@ namespace main(256);

// ========= Initialize Range Check Gadget ===============================
// We range check that the absolute value of the differences between each row of l2 and da gas are 32 bits.
#[PERM_RNG_GAS_L2]
range_check.gas_l2_rng_chk {range_check.clk, range_check.value}
is
is_gas_accounted {main.clk, main.abs_l2_rem_gas };
pol commit l2_gas_u16_r0;
pol commit l2_gas_u16_r1;
main.abs_l2_rem_gas = l2_gas_u16_r0 + l2_gas_u16_r1 * 2**16;

#[PERM_RNG_GAS_DA]
range_check.gas_da_rng_chk {range_check.clk, range_check.value}
is
is_gas_accounted {main.clk, main.abs_da_rem_gas };
#[LOOKUP_L2_GAS_RNG_CHK_0]
is_gas_accounted { l2_gas_u16_r0 } in main.sel_rng_16 { main.clk };
#[LOOKUP_L2_GAS_RNG_CHK_1]
is_gas_accounted { l2_gas_u16_r1 } in main.sel_rng_16 { main.clk };

pol commit da_gas_u16_r0;
pol commit da_gas_u16_r1;
main.abs_da_rem_gas = da_gas_u16_r0 + da_gas_u16_r1 * 2**16;

#[LOOKUP_DA_GAS_RNG_CHK_0]
is_gas_accounted { da_gas_u16_r0 } in main.sel_rng_16 { main.clk };
#[LOOKUP_DA_GAS_RNG_CHK_1]
is_gas_accounted { da_gas_u16_r1 } in main.sel_rng_16 { main.clk };
2 changes: 1 addition & 1 deletion barretenberg/cpp/pil/avm/kernel.pil
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ namespace main(256);
+ sel_op_emit_nullifier + sel_op_l1_to_l2_msg_exists + sel_op_emit_unencrypted_log
+ sel_op_emit_l2_to_l1_msg + sel_op_sload + sel_op_sstore;
#[KERNEL_OUTPUT_ACTIVE_CHECK]
KERNEL_OUTPUT_SELECTORS * (1 - sel_q_kernel_output_lookup) = 0;
KERNEL_OUTPUT_SELECTORS * (1 - sel_q_kernel_output_lookup) * (1 - op_err) = 0;

// TODO(#8287): Reintroduce constraints
#[KERNEL_OUTPUT_LOOKUP]
Expand Down
Loading

0 comments on commit 9af92ea

Please sign in to comment.