Skip to content

Commit

Permalink
Merge branch 'master' into sync-noir
Browse files Browse the repository at this point in the history
  • Loading branch information
ludamad authored Sep 23, 2024
2 parents 328d61b + 4121ef3 commit a04ab7b
Show file tree
Hide file tree
Showing 58 changed files with 1,557 additions and 2,847 deletions.
31 changes: 2 additions & 29 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 @@ -138,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
56 changes: 38 additions & 18 deletions avm-transpiler/src/transpile.rs
Original file line number Diff line number Diff line change
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
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
1 change: 1 addition & 0 deletions barretenberg/cpp/src/barretenberg/bb/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1494,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
Loading

0 comments on commit a04ab7b

Please sign in to comment.