Skip to content

Commit

Permalink
Merge branch 'master' into tf/remove-unnecessary-casts
Browse files Browse the repository at this point in the history
  • Loading branch information
Maddiaa0 authored Mar 4, 2024
2 parents ebde0cf + 15df3c0 commit 5a6afb3
Show file tree
Hide file tree
Showing 18 changed files with 124 additions and 70 deletions.
38 changes: 19 additions & 19 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ jobs:

noir-ecr-manifest:
machine:
image: ubuntu-2204:2023.07.2
image: default
resource_class: medium
steps:
- *checkout
Expand Down Expand Up @@ -259,7 +259,7 @@ jobs:

barretenberg-docs:
machine:
image: ubuntu-2204:2023.07.2
image: default
resource_class: large
steps:
- *checkout
Expand Down Expand Up @@ -313,7 +313,7 @@ jobs:
machine:
# NOTE: we usually use alpine build image when making spot images, but
# we are not able to upload to S3 with it
image: ubuntu-2204:2023.07.2
image: default
resource_class: medium
steps:
- *checkout
Expand Down Expand Up @@ -377,7 +377,7 @@ jobs:

bb-js:
machine:
image: ubuntu-2204:2023.07.2
image: default
resource_class: large
steps:
- *checkout
Expand Down Expand Up @@ -413,7 +413,7 @@ jobs:

l1-contracts:
machine:
image: ubuntu-2204:2023.07.2
image: default
resource_class: large
steps:
- *checkout
Expand All @@ -425,7 +425,7 @@ jobs:

noir-projects:
machine:
image: ubuntu-2204:2023.07.2
image: default
resource_class: large
steps:
- *checkout
Expand All @@ -437,7 +437,7 @@ jobs:

boxes-files:
machine:
image: ubuntu-2204:2023.07.2
image: default
resource_class: medium
steps:
- *checkout
Expand All @@ -449,7 +449,7 @@ jobs:

yarn-project-base:
machine:
image: ubuntu-2204:2023.07.2
image: default
resource_class: large
steps:
- *checkout
Expand All @@ -461,7 +461,7 @@ jobs:

yarn-project:
machine:
image: ubuntu-2204:2023.07.2
image: default
resource_class: large
steps:
- *checkout
Expand All @@ -473,7 +473,7 @@ jobs:

yarn-project-prod:
machine:
image: ubuntu-2204:2023.07.2
image: default
resource_class: large
steps:
- *checkout
Expand Down Expand Up @@ -509,7 +509,7 @@ jobs:

aztec-package:
machine:
image: ubuntu-2204:2023.07.2
image: default
resource_class: large
steps:
- *checkout
Expand All @@ -521,7 +521,7 @@ jobs:

cli:
machine:
image: ubuntu-2204:2023.07.2
image: default
resource_class: large
steps:
- *checkout
Expand All @@ -533,7 +533,7 @@ jobs:

mainnet-fork:
machine:
image: ubuntu-2204:2023.07.2
image: default
resource_class: large
steps:
- *checkout
Expand All @@ -545,7 +545,7 @@ jobs:

aztec-faucet:
machine:
image: ubuntu-2204:2023.07.2
image: default
resource_class: large
steps:
- *checkout
Expand Down Expand Up @@ -593,7 +593,7 @@ jobs:

end-to-end:
machine:
image: ubuntu-2204:2023.07.2
image: default
resource_class: large
steps:
- *checkout
Expand Down Expand Up @@ -1135,7 +1135,7 @@ jobs:

build-docs:
machine:
image: ubuntu-2204:2023.07.2
image: default
resource_class: large
steps:
- *checkout
Expand Down Expand Up @@ -1165,7 +1165,7 @@ jobs:
yellow-paper:
machine:
image: ubuntu-2204:2023.07.2
image: default
resource_class: large
steps:
- *checkout
Expand Down Expand Up @@ -1195,7 +1195,7 @@ jobs:

bench-summary:
machine:
image: ubuntu-2204:2023.07.2
image: default
steps:
- *checkout
- *setup_env
Expand All @@ -1206,7 +1206,7 @@ jobs:
# Deploy & release jobs.
deploy-and-release:
machine:
image: ubuntu-2204:2023.07.2
image: default
resource_class: medium
steps:
- *checkout
Expand Down
30 changes: 20 additions & 10 deletions avm-transpiler/src/transpile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,14 @@ pub fn brillig_to_avm(brillig: &Brillig) -> Vec<u8> {
/// - TODO: support for avm external calls through this function
fn handle_foreign_call(
avm_instrs: &mut Vec<AvmInstruction>,
function: &String,
function: &str,
destinations: &Vec<ValueOrArray>,
inputs: &Vec<ValueOrArray>,
) {
match function.as_str() {
match function {
"avmOpcodeNoteHashExists" => handle_note_hash_exists(avm_instrs, destinations, inputs),
"emitNoteHash" | "emitNullifier" => handle_emit_note_hash_or_nullifier(
function.as_str() == "emitNullifier",
function == "emitNullifier",
avm_instrs,
destinations,
inputs,
Expand All @@ -252,7 +252,15 @@ fn handle_foreign_call(
"poseidon" => {
handle_single_field_hash_instruction(avm_instrs, function, destinations, inputs)
}
_ => handle_getter_instruction(avm_instrs, function, destinations, inputs),
// Getters.
_ if inputs.len() == 0 && destinations.len() == 1 => {
handle_getter_instruction(avm_instrs, function, destinations, inputs)
}
// Anything else.
_ => panic!(
"Transpiler doesn't know how to process ForeignCall function {}",
function
),
}
}

Expand Down Expand Up @@ -384,7 +392,7 @@ fn handle_nullifier_exists(
/// to reason about. In order to decrease user friction we will use two field outputs.
fn handle_2_field_hash_instruction(
avm_instrs: &mut Vec<AvmInstruction>,
function: &String,
function: &str,
destinations: &[ValueOrArray],
inputs: &[ValueOrArray],
) {
Expand All @@ -405,7 +413,7 @@ fn handle_2_field_hash_instruction(
_ => panic!("Keccak | Poseidon address destination should be a single value"),
};

let opcode = match function.as_str() {
let opcode = match function {
"keccak256" => AvmOpcode::KECCAK,
"sha256" => AvmOpcode::SHA256,
_ => panic!(
Expand Down Expand Up @@ -443,7 +451,7 @@ fn handle_2_field_hash_instruction(
/// representation.
fn handle_single_field_hash_instruction(
avm_instrs: &mut Vec<AvmInstruction>,
function: &String,
function: &str,
destinations: &[ValueOrArray],
inputs: &[ValueOrArray],
) {
Expand All @@ -461,7 +469,7 @@ fn handle_single_field_hash_instruction(
_ => panic!("Poseidon address destination should be a single value"),
};

let opcode = match function.as_str() {
let opcode = match function {
"poseidon" => AvmOpcode::POSEIDON,
_ => panic!(
"Transpiler doesn't know how to process ForeignCall function {:?}",
Expand Down Expand Up @@ -497,20 +505,21 @@ fn handle_single_field_hash_instruction(
/// - ...
fn handle_getter_instruction(
avm_instrs: &mut Vec<AvmInstruction>,
function: &String,
function: &str,
destinations: &Vec<ValueOrArray>,
inputs: &Vec<ValueOrArray>,
) {
// 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);

let dest_offset_maybe = destinations[0];
let dest_offset = match dest_offset_maybe {
ValueOrArray::MemoryAddress(dest_offset) => dest_offset.0,
_ => panic!("ForeignCall address destination should be a single value"),
};

let opcode = match function.as_str() {
let opcode = match function {
"address" => AvmOpcode::ADDRESS,
"storageAddress" => AvmOpcode::STORAGEADDRESS,
"origin" => AvmOpcode::ORIGIN,
Expand All @@ -529,6 +538,7 @@ fn handle_getter_instruction(
function
),
};

avm_instrs.push(AvmInstruction {
opcode,
indirect: Some(ALL_DIRECT),
Expand Down
9 changes: 5 additions & 4 deletions barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,14 @@ HonkProof ClientIVC::decider_prove() const
void ClientIVC::precompute_folding_verification_keys()
{
using VerifierInstance = VerifierInstance_<GoblinUltraFlavor>;
using VerificationKey = Flavor::VerificationKey;

ClientCircuit initial_function_circuit{ goblin.op_queue };
GoblinMockCircuits::construct_mock_function_circuit(initial_function_circuit);

// Initialise both the first prover and verifier accumulator from the inital function circuit
initialize(initial_function_circuit);
vks.first_func_vk = prover_fold_output.accumulator->verification_key;
vks.first_func_vk = std::make_shared<VerificationKey>(prover_fold_output.accumulator->proving_key);
auto initial_verifier_acc = std::make_shared<VerifierInstance>(vks.first_func_vk);

// Accumulate the next function circuit
Expand All @@ -106,14 +107,14 @@ void ClientIVC::precompute_folding_verification_keys()
auto function_fold_proof = accumulate(function_circuit);

// Create its verification key (we have called accumulate so it includes the recursive merge verifier)
vks.func_vk = prover_instance->verification_key;
vks.func_vk = std::make_shared<VerificationKey>(prover_instance->proving_key);

// Create the initial kernel iteration and precompute its verification key
ClientCircuit kernel_circuit{ goblin.op_queue };
auto kernel_acc = GoblinMockCircuits::construct_mock_folding_kernel(
kernel_circuit, { function_fold_proof, vks.func_vk }, {}, initial_verifier_acc);
auto kernel_fold_proof = accumulate(kernel_circuit);
vks.first_kernel_vk = prover_instance->verification_key;
vks.first_kernel_vk = std::make_shared<VerificationKey>(prover_instance->proving_key);

// Create another mock function circuit to run the full kernel
function_circuit = ClientCircuit{ goblin.op_queue };
Expand All @@ -126,7 +127,7 @@ void ClientIVC::precompute_folding_verification_keys()
kernel_circuit, { function_fold_proof, vks.func_vk }, { kernel_fold_proof, vks.first_kernel_vk }, kernel_acc);
kernel_fold_proof = accumulate(kernel_circuit);

vks.kernel_vk = prover_instance->verification_key;
vks.kernel_vk = std::make_shared<VerificationKey>(prover_instance->proving_key);

// Clean the ivc state
goblin.op_queue = std::make_shared<Goblin::OpQueue>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,20 @@ class ClientIVCTests : public ::testing::Test {
*/
TEST_F(ClientIVCTests, Full)
{
using VerificationKey = Flavor::VerificationKey;

ClientIVC ivc;
// Initialize IVC with function circuit
Builder function_circuit = create_mock_circuit(ivc);
ivc.initialize(function_circuit);

auto function_vk = ivc.prover_fold_output.accumulator->verification_key;
auto function_vk = std::make_shared<VerificationKey>(ivc.prover_fold_output.accumulator->proving_key);
auto foo_verifier_instance = std::make_shared<VerifierInstance>(function_vk);
// Accumulate kernel circuit (first kernel mocked as simple circuit since no folding proofs yet)
Builder kernel_circuit = create_mock_circuit(ivc);
FoldProof kernel_fold_proof = ivc.accumulate(kernel_circuit);
// This will have a different verification key because we added the recursive merge verification to the circuit
auto function_vk_with_merge = ivc.prover_instance->verification_key;
auto function_vk_with_merge = std::make_shared<VerificationKey>(ivc.prover_instance->proving_key);
auto kernel_vk = function_vk_with_merge;
auto intermediary_acc = update_accumulator_and_decide_native(
ivc.prover_fold_output.accumulator, kernel_fold_proof, foo_verifier_instance, kernel_vk);
Expand All @@ -137,7 +139,7 @@ TEST_F(ClientIVCTests, Full)
foo_verifier_instance = construct_mock_folding_kernel(
kernel_circuit, kernel_fold_output, function_fold_output, foo_verifier_instance);
FoldProof kernel_fold_proof = ivc.accumulate(kernel_circuit);
kernel_vk = ivc.prover_instance->verification_key;
kernel_vk = std::make_shared<VerificationKey>(ivc.prover_instance->proving_key);

intermediary_acc = update_accumulator_and_decide_native(
ivc.prover_fold_output.accumulator, kernel_fold_proof, intermediary_acc, kernel_vk);
Expand Down
7 changes: 5 additions & 2 deletions barretenberg/cpp/src/barretenberg/goblin/goblin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Goblin {
using RecursiveMergeVerifier = bb::stdlib::recursion::goblin::MergeRecursiveVerifier_<GoblinUltraCircuitBuilder>;
using MergeProver = bb::MergeProver_<GoblinUltraFlavor>;
using MergeVerifier = bb::MergeVerifier_<GoblinUltraFlavor>;
using VerificationKey = GoblinUltraFlavor::VerificationKey;
/**
* @brief Output of goblin::accumulate; an Ultra proof and the corresponding verification key
*
Expand Down Expand Up @@ -105,6 +106,7 @@ class Goblin {
// Construct a Honk proof for the main circuit
GoblinUltraComposer composer;
auto instance = composer.create_prover_instance(circuit_builder);
auto verification_key = std::make_shared<VerificationKey>(instance->proving_key);
auto prover = composer.create_prover(instance);
auto ultra_proof = prover.construct_proof();

Expand All @@ -116,7 +118,7 @@ class Goblin {
merge_proof_exists = true;
}

return { ultra_proof, instance->verification_key };
return { ultra_proof, verification_key };
};

/**
Expand Down Expand Up @@ -231,10 +233,11 @@ class Goblin {
// Construct a Honk proof for the main circuit
GoblinUltraComposer composer;
auto instance = composer.create_prover_instance(circuit_builder);
auto verification_key = std::make_shared<VerificationKey>(instance->proving_key);
auto prover = composer.create_prover(instance);
auto ultra_proof = prover.construct_proof();

accumulator = { ultra_proof, instance->verification_key };
accumulator = { ultra_proof, verification_key };

// TODO(https://github.com/AztecProtocol/barretenberg/issues/811): no merge prover for now since we're not
// mocking the first set of ecc ops
Expand Down
Loading

0 comments on commit 5a6afb3

Please sign in to comment.