Skip to content

Commit

Permalink
Merge branch 'master' into gd/unsafe_ec_add
Browse files Browse the repository at this point in the history
  • Loading branch information
guipublic authored Sep 24, 2024
2 parents ccfcaac + 4641004 commit 43f6a23
Show file tree
Hide file tree
Showing 1,747 changed files with 4,824 additions and 131,279 deletions.
2 changes: 1 addition & 1 deletion .noir-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0864e7c945089cc06f8cc9e5c7d933c465d8c892
5598059576c6cbc72474aff4b18bc5e4bb9f08e1
1 change: 1 addition & 0 deletions avm-transpiler/src/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub const ALL_DIRECT: u8 = 0b00000000;
pub const ZEROTH_OPERAND_INDIRECT: u8 = 0b00000001;
pub const FIRST_OPERAND_INDIRECT: u8 = 0b00000010;
pub const SECOND_OPERAND_INDIRECT: u8 = 0b00000100;
pub const THIRD_OPERAND_INDIRECT: u8 = 0b00001000;

/// A simple representation of an AVM instruction for the purpose
/// of generating an AVM bytecode from Brillig.
Expand Down
43 changes: 6 additions & 37 deletions avm-transpiler/src/opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,8 @@ pub enum AvmOpcode {
CAST_8,
CAST_16,
// Execution environment
ADDRESS,
STORAGEADDRESS,
SENDER,
FUNCTIONSELECTOR,
TRANSACTIONFEE,
CHAINID,
VERSION,
BLOCKNUMBER,
TIMESTAMP,
FEEPERL2GAS,
FEEPERDAGAS,
GETENVVAR_16,
CALLDATACOPY,
// Gas
L2GASLEFT,
DAGASLEFT,
// Control flow
JUMP_16,
JUMPI_16,
Expand Down Expand Up @@ -88,16 +75,14 @@ pub enum AvmOpcode {
// Gadgets
KECCAK,
POSEIDON2,
SHA256, // temp - may be removed, but alot of contracts rely on it
SHA256COMPRESSION,
KECCAKF1600,
PEDERSEN, // temp - may be removed, but alot of contracts rely on it
ECADD,
MSM,
PEDERSENCOMMITMENT, // temp
// Conversions
TORADIXLE,
// Other
SHA256COMPRESSION,
KECCAKF1600,
}

impl AvmOpcode {
Expand Down Expand Up @@ -140,25 +125,11 @@ impl AvmOpcode {
AvmOpcode::CAST_16 => "CAST_16",

// Execution Environment
AvmOpcode::ADDRESS => "ADDRESS",
AvmOpcode::STORAGEADDRESS => "STORAGEADDRESS",
AvmOpcode::SENDER => "SENDER",
AvmOpcode::FUNCTIONSELECTOR => "FUNCTIONSELECTOR",
AvmOpcode::TRANSACTIONFEE => "TRANSACTIONFEE",
// Execution Environment - Globals
AvmOpcode::CHAINID => "CHAINID",
AvmOpcode::VERSION => "VERSION",
AvmOpcode::BLOCKNUMBER => "BLOCKNUMBER",
AvmOpcode::TIMESTAMP => "TIMESTAMP",
AvmOpcode::FEEPERL2GAS => "FEEPERL2GAS",
AvmOpcode::FEEPERDAGAS => "FEEPERDAGAS",
AvmOpcode::GETENVVAR_16 => "GETENVVAR_16",
// Execution Environment - Calldata
AvmOpcode::CALLDATACOPY => "CALLDATACOPY",

// Machine State
// Machine State - Gas
AvmOpcode::L2GASLEFT => "L2GASLEFT",
AvmOpcode::DAGASLEFT => "DAGASLEFT",
// Machine State - Internal Control Flow
AvmOpcode::JUMP_16 => "JUMP_16",
AvmOpcode::JUMPI_16 => "JUMPI_16",
Expand Down Expand Up @@ -202,17 +173,15 @@ impl AvmOpcode {

// Gadgets
AvmOpcode::KECCAK => "KECCAK",
AvmOpcode::KECCAKF1600 => "KECCAKF1600",
AvmOpcode::POSEIDON2 => "POSEIDON2",
AvmOpcode::SHA256 => "SHA256 ",
AvmOpcode::SHA256COMPRESSION => "SHA256COMPRESSION",
AvmOpcode::PEDERSEN => "PEDERSEN",
AvmOpcode::ECADD => "ECADD",
AvmOpcode::MSM => "MSM",
AvmOpcode::PEDERSENCOMMITMENT => "PEDERSENCOMMITMENT",
// Conversions
AvmOpcode::TORADIXLE => "TORADIXLE",
// Other
AvmOpcode::SHA256COMPRESSION => "SHA256COMPRESSION",
AvmOpcode::KECCAKF1600 => "KECCAKF1600",
}
}
}
83 changes: 54 additions & 29 deletions avm-transpiler/src/transpile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use noirc_errors::debug_info::DebugInfo;
use crate::bit_traits::bits_needed_for;
use crate::instructions::{
AvmInstruction, AvmOperand, AvmTypeTag, ALL_DIRECT, FIRST_OPERAND_INDIRECT,
SECOND_OPERAND_INDIRECT, ZEROTH_OPERAND_INDIRECT,
SECOND_OPERAND_INDIRECT, THIRD_OPERAND_INDIRECT, ZEROTH_OPERAND_INDIRECT,
};
use crate::opcodes::AvmOpcode;
use crate::utils::{dbg_print_avm_program, dbg_print_brillig_program, make_operand};
Expand Down Expand Up @@ -732,6 +732,23 @@ fn handle_getter_instruction(
destinations: &Vec<ValueOrArray>,
inputs: &Vec<ValueOrArray>,
) {
enum EnvironmentVariable {
ADDRESS,
STORAGEADDRESS,
SENDER,
FUNCTIONSELECTOR,
TRANSACTIONFEE,
CHAINID,
VERSION,
BLOCKNUMBER,
TIMESTAMP,
FEEPERL2GAS,
FEEPERDAGAS,
ISSTATICCALL,
L2GASLEFT,
DAGASLEFT,
}

// For the foreign calls we want to handle, we do not want inputs, as they are getters
assert!(inputs.is_empty());
assert!(destinations.len() == 1);
Expand All @@ -742,28 +759,31 @@ fn handle_getter_instruction(
_ => panic!("ForeignCall address destination should be a single value"),
};

let opcode = match function {
"avmOpcodeAddress" => AvmOpcode::ADDRESS,
"avmOpcodeStorageAddress" => AvmOpcode::STORAGEADDRESS,
"avmOpcodeSender" => AvmOpcode::SENDER,
"avmOpcodeFeePerL2Gas" => AvmOpcode::FEEPERL2GAS,
"avmOpcodeFeePerDaGas" => AvmOpcode::FEEPERDAGAS,
"avmOpcodeTransactionFee" => AvmOpcode::TRANSACTIONFEE,
"avmOpcodeChainId" => AvmOpcode::CHAINID,
"avmOpcodeVersion" => AvmOpcode::VERSION,
"avmOpcodeBlockNumber" => AvmOpcode::BLOCKNUMBER,
"avmOpcodeTimestamp" => AvmOpcode::TIMESTAMP,
"avmOpcodeL2GasLeft" => AvmOpcode::L2GASLEFT,
"avmOpcodeDaGasLeft" => AvmOpcode::DAGASLEFT,
"avmOpcodeFunctionSelector" => AvmOpcode::FUNCTIONSELECTOR,
// "callStackDepth" => AvmOpcode::CallStackDepth,
_ => panic!("Transpiler doesn't know how to process ForeignCall function {:?}", function),
let var_idx = match function {
"avmOpcodeAddress" => EnvironmentVariable::ADDRESS,
"avmOpcodeStorageAddress" => EnvironmentVariable::STORAGEADDRESS,
"avmOpcodeSender" => EnvironmentVariable::SENDER,
"avmOpcodeFeePerL2Gas" => EnvironmentVariable::FEEPERL2GAS,
"avmOpcodeFeePerDaGas" => EnvironmentVariable::FEEPERDAGAS,
"avmOpcodeTransactionFee" => EnvironmentVariable::TRANSACTIONFEE,
"avmOpcodeChainId" => EnvironmentVariable::CHAINID,
"avmOpcodeVersion" => EnvironmentVariable::VERSION,
"avmOpcodeBlockNumber" => EnvironmentVariable::BLOCKNUMBER,
"avmOpcodeTimestamp" => EnvironmentVariable::TIMESTAMP,
"avmOpcodeL2GasLeft" => EnvironmentVariable::L2GASLEFT,
"avmOpcodeDaGasLeft" => EnvironmentVariable::DAGASLEFT,
"avmOpcodeFunctionSelector" => EnvironmentVariable::FUNCTIONSELECTOR,
"avmOpcodeIsStaticCall" => EnvironmentVariable::ISSTATICCALL,
_ => panic!("Transpiler doesn't know how to process getter {:?}", function),
};

avm_instrs.push(AvmInstruction {
opcode,
opcode: AvmOpcode::GETENVVAR_16,
indirect: Some(ALL_DIRECT),
operands: vec![AvmOperand::U32 { value: dest_offset as u32 }],
operands: vec![
AvmOperand::U8 { value: var_idx as u8 },
AvmOperand::U16 { value: dest_offset as u16 },
],
..Default::default()
});
}
Expand Down Expand Up @@ -865,19 +885,24 @@ fn generate_mov_instruction(indirect: Option<u8>, source: u32, dest: u32) -> Avm
/// (array goes in -> field element comes out)
fn handle_black_box_function(avm_instrs: &mut Vec<AvmInstruction>, operation: &BlackBoxOp) {
match operation {
BlackBoxOp::Sha256 { message, output } => {
let message_offset = message.pointer.0;
let message_size_offset = message.size.0;
let dest_offset = output.pointer.0;
assert_eq!(output.size, 32, "SHA256 output size must be 32!");
BlackBoxOp::Sha256Compression { input, hash_values, output } => {
let inputs_offset = input.pointer.0;
let inputs_size_offset = input.size.0;
let state_offset = hash_values.pointer.0;
let state_size_offset = hash_values.size.0;
let output_offset = output.pointer.0;

avm_instrs.push(AvmInstruction {
opcode: AvmOpcode::SHA256,
indirect: Some(ZEROTH_OPERAND_INDIRECT | FIRST_OPERAND_INDIRECT),
opcode: AvmOpcode::SHA256COMPRESSION,
indirect: Some(
ZEROTH_OPERAND_INDIRECT | FIRST_OPERAND_INDIRECT | THIRD_OPERAND_INDIRECT,
),
operands: vec![
AvmOperand::U32 { value: dest_offset as u32 },
AvmOperand::U32 { value: message_offset as u32 },
AvmOperand::U32 { value: message_size_offset as u32 },
AvmOperand::U32 { value: output_offset as u32 },
AvmOperand::U32 { value: state_offset as u32 },
AvmOperand::U32 { value: state_size_offset as u32 },
AvmOperand::U32 { value: inputs_offset as u32 },
AvmOperand::U32 { value: inputs_size_offset as u32 },
],
..Default::default()
});
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 = 26f856196b7bdb8f5106808626969f155170d7e9
parent = 7247ddba274e691a7c5220848caf1fa9d6aa911e
commit = 6f32e058e0db185d0b267736dea89c06451829ad
parent = 982a04e8021ec88b178ea05fdebb7193998cde38
method = merge
cmdver = 0.4.6
3 changes: 2 additions & 1 deletion barretenberg/acir_tests/run_acir_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ SKIP_ARRAY=(diamond_deps_0 workspace workspace_default_member)
# if HONK is false, we should skip verify_honk_proof
if [ "$HONK" = false ]; then
# Insert the new item into the array
SKIP_ARRAY+=(verify_honk_proof)
# TODO https://github.com/AztecProtocol/barretenberg/issues/1108
SKIP_ARRAY+=(verify_honk_proof regression_5045)
fi

function test() {
Expand Down
1 change: 1 addition & 0 deletions barretenberg/cpp/pil/avm/constants_gen.pil
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace constants(256);
pol ADDRESS_SELECTOR = 1;
pol STORAGE_ADDRESS_SELECTOR = 1;
pol FUNCTION_SELECTOR_SELECTOR = 2;
pol IS_STATIC_CALL_SELECTOR = 4;
pol START_GLOBAL_VARIABLES = 29;
pol CHAIN_ID_SELECTOR = 29;
pol VERSION_SELECTOR = 30;
Expand Down
11 changes: 7 additions & 4 deletions barretenberg/cpp/pil/avm/kernel.pil
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ namespace main(256);
pol commit sel_kernel_out;

// Kernel Outputs
//
//
// The current implementation of kernel outputs is described within https://hackmd.io/zP1oMXF6Rf-L-ZZLXWmfHg

// Global side effect counter; incremented after each side effect is produced.
pol commit side_effect_counter;

Expand Down Expand Up @@ -98,6 +98,9 @@ namespace main(256);
#[FEE_TRANSACTION_FEE_KERNEL]
sel_op_transaction_fee * (kernel_in_offset - constants.TRANSACTION_FEE_SELECTOR) = 0;

#[IS_STATIC_CALL_KERNEL]
sel_op_is_static_call * (kernel_in_offset - constants.IS_STATIC_CALL_SELECTOR) = 0;

// CONTEXT - ENVIRONMENT - GLOBALS
#[CHAIN_ID_KERNEL]
sel_op_chain_id * (kernel_in_offset - constants.CHAIN_ID_SELECTOR) = 0;
Expand All @@ -123,7 +126,7 @@ namespace main(256);
#[NOTE_HASH_KERNEL_OUTPUT]
sel_op_note_hash_exists * (kernel_out_offset - (constants.START_NOTE_HASH_EXISTS_WRITE_OFFSET + note_hash_exist_write_offset)) = 0;
sel_first * note_hash_exist_write_offset = 0;

#[EMIT_NOTE_HASH_KERNEL_OUTPUT]
sel_op_emit_note_hash * (kernel_out_offset - (constants.START_EMIT_NOTE_HASH_WRITE_OFFSET + emit_note_hash_write_offset)) = 0;
sel_first * emit_note_hash_write_offset = 0;
Expand Down Expand Up @@ -168,7 +171,7 @@ namespace main(256);
pol KERNEL_INPUT_SELECTORS = sel_op_address + sel_op_storage_address + sel_op_sender
+ sel_op_function_selector + sel_op_transaction_fee + sel_op_chain_id
+ sel_op_version + sel_op_block_number + sel_op_timestamp
+ sel_op_fee_per_l2_gas + sel_op_fee_per_da_gas;
+ sel_op_fee_per_l2_gas + sel_op_fee_per_da_gas + sel_op_is_static_call;
// Ensure that only one kernel lookup is active when the kernel_in_offset is active
#[KERNEL_INPUT_ACTIVE_CHECK]
KERNEL_INPUT_SELECTORS * (1 - sel_q_kernel_lookup) = 0;
Expand Down
2 changes: 2 additions & 0 deletions barretenberg/cpp/pil/avm/main.pil
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ namespace main(256);
pol commit sel_op_sender;
pol commit sel_op_function_selector;
pol commit sel_op_transaction_fee;
pol commit sel_op_is_static_call;

// CONTEXT - ENVIRONMENT - GLOBALS
pol commit sel_op_chain_id;
Expand Down Expand Up @@ -227,6 +228,7 @@ namespace main(256);
sel_op_timestamp * (1 - sel_op_timestamp) = 0;
sel_op_fee_per_l2_gas * (1 - sel_op_fee_per_l2_gas) = 0;
sel_op_fee_per_da_gas * (1 - sel_op_fee_per_da_gas) = 0;
sel_op_is_static_call * (1 - sel_op_is_static_call) = 0;

// MACHINE STATE - GAS
sel_op_l2gasleft * (1 - sel_op_l2gasleft) = 0;
Expand Down
2 changes: 1 addition & 1 deletion barretenberg/cpp/scripts/analyze_client_ivc_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

print('\nBreakdown of ProtogalaxyProver::prove:')
protogalaxy_round_labels = [
"ProtogalaxyProver_::preparation_round(t)",
"ProtogalaxyProver_::run_oink_prover_on_each_incomplete_key(t)",
"ProtogalaxyProver_::perturbator_round(t)",
"ProtogalaxyProver_::combiner_quotient_round(t)",
"ProtogalaxyProver_::update_target_sum_and_fold(t)"
Expand Down
2 changes: 1 addition & 1 deletion barretenberg/cpp/scripts/analyze_protogalaxy_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

print('\nBreakdown of ProtogalaxyProver::prove:')
protogalaxy_round_labels = [
"ProtogalaxyProver_::preparation_round(t)",
"ProtogalaxyProver_::run_oink_prover_on_each_incomplete_key(t)",
"ProtogalaxyProver_::perturbator_round(t)",
"ProtogalaxyProver_::combiner_quotient_round(t)",
"ProtogalaxyProver_::update_target_sum_and_fold(t)"
Expand Down
8 changes: 1 addition & 7 deletions barretenberg/cpp/src/barretenberg/bb/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1209,13 +1209,6 @@ void write_recursion_inputs_honk(const std::string& bytecodePath,
// Write all components to the TOML file
std::string toml_path = outputPath + "/Prover.toml";
write_file(toml_path, { toml_content.begin(), toml_content.end() });

// Write to additional dir for noir-sync purposes
std::string part_to_remove = "/noir-repo/test_programs/execution_success";
size_t pos = toml_path.find(part_to_remove);
std::string toml_path_2 = toml_path; // define path here
toml_path_2.erase(pos, part_to_remove.length());
write_file(toml_path_2, { toml_content.begin(), toml_content.end() });
}

/**
Expand Down Expand Up @@ -1501,6 +1494,7 @@ int main(int argc, char* argv[])
std::string output_path = get_option(args, "-o", "./target/contract.sol");
contract(output_path, vk_path);
} else if (command == "contract_ultra_honk") {
vinfo("Warning: Contract incomplete. Do not use in production!");
std::string output_path = get_option(args, "-o", "./target/contract.sol");
contract_honk(output_path, vk_path);
} else if (command == "write_vk") {
Expand Down
1 change: 1 addition & 0 deletions barretenberg/cpp/src/barretenberg/bb/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ Barretenberg UltraHonk comes with the capability to verify proofs in Solidity, i
```
4. Generate Solidity verifier
**WARNING:** Contract incomplete, do not use in production!
```bash
bb contract_ultra_honk -k ./target/vk -c $CRS_PATH -b ./target/hello_world.json -o ./target/Verifier.sol
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
barretenberg_module(
protogalaxy_bench
stdlib_protogalaxy_verifier
protogalaxy
)
Loading

0 comments on commit 43f6a23

Please sign in to comment.