Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion barretenberg/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ bb write_vk --scheme ultra_honk -b ./target/hello_world.json -o ./target/vk
You can now use the verification key to generate a Solidity verifier contract:

```bash
bb write_contract --scheme ultra_honk -k ./target/vk -c $CRS_PATH -b ./target/hello_world.json -o ./target/Verifier.sol
bb write_solidity_verifier --scheme ultra_honk -k ./target/vk -c $CRS_PATH -b ./target/hello_world.json -o ./target/Verifier.sol
```

> [!CAUTION]
Expand Down
2 changes: 1 addition & 1 deletion barretenberg/acir_tests/flows/sol_honk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export VERIFIER_CONTRACT="$outdir/Verifier.sol"
# Create a proof, write the solidity contract, write the proof as fields in order to extract the public inputs
$BIN prove $PROVE_FLAGS -o $outdir
$BIN verify $VERIFY_FLAGS -k $VK -p $PROOF
$BIN write_contract $FLAGS -k $VK -o $VERIFIER_CONTRACT
$BIN write_solidity_verifier $FLAGS -k $VK -o $VERIFIER_CONTRACT

# Export the paths to the environment variables for the js test runner
export VERIFIER_PATH="$outdir/Verifier.sol"
Expand Down
2 changes: 1 addition & 1 deletion barretenberg/acir_tests/flows/sol_honk_zk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export VERIFIER_CONTRACT="$outdir/Verifier.sol"
# Create a proof, write the solidity contract, write the proof as fields in order to extract the public inputs
$BIN prove -o $outdir $FLAGS $BFLAG $PROTOCOL_FLAGS --output_format bytes_and_fields --write_vk
$BIN verify -k $VK -p $PROOF $FLAGS $PROTOCOL_FLAGS
$BIN write_contract $FLAGS -k $VK -o $VERIFIER_CONTRACT --zk
$BIN write_solidity_verifier $FLAGS -k $VK -o $VERIFIER_CONTRACT --zk

# Export the paths to the environment variables for the js test runner
export VERIFIER_PATH="$outdir/Verifier.sol"
Expand Down
6 changes: 3 additions & 3 deletions barretenberg/cpp/src/barretenberg/api/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ class API {

virtual void gates(const Flags& flags, const std::filesystem::path& bytecode_path) = 0;

virtual void write_contract(const Flags& flags,
const std::filesystem::path& output_path,
const std::filesystem::path& vk_path) = 0;
virtual void write_solidity_verifier(const Flags& flags,
const std::filesystem::path& output_path,
const std::filesystem::path& vk_path) = 0;
};
} // namespace bb
6 changes: 3 additions & 3 deletions barretenberg/cpp/src/barretenberg/api/api_client_ivc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,9 @@ void ClientIVCAPI::gates([[maybe_unused]] const Flags& flags,
throw_or_abort("API function gates not implemented");
}

void ClientIVCAPI::write_contract([[maybe_unused]] const Flags& flags,
[[maybe_unused]] const std::filesystem::path& output_path,
[[maybe_unused]] const std::filesystem::path& vk_path)
void ClientIVCAPI::write_solidity_verifier([[maybe_unused]] const Flags& flags,
[[maybe_unused]] const std::filesystem::path& output_path,
[[maybe_unused]] const std::filesystem::path& vk_path)
{
throw_or_abort("API function contract not implemented");
}
Expand Down
6 changes: 3 additions & 3 deletions barretenberg/cpp/src/barretenberg/api/api_client_ivc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ class ClientIVCAPI : public API {

void gates(const Flags& flags, const std::filesystem::path& bytecode_path) override;

void write_contract(const Flags& flags,
const std::filesystem::path& output_path,
const std::filesystem::path& vk_path) override;
void write_solidity_verifier(const Flags& flags,
const std::filesystem::path& output_path,
const std::filesystem::path& vk_path) override;

void write_vk(const Flags& flags,
const std::filesystem::path& bytecode_path,
Expand Down
22 changes: 14 additions & 8 deletions barretenberg/cpp/src/barretenberg/api/api_ultra_honk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ bool _verify(const bool honk_recursion_2, const std::filesystem::path& proof_pat
verified = verifier.verify_proof(proof);
}

verified ? info("Proof verified successfully") : info("Proof verification failed");

return verified;
}

Expand Down Expand Up @@ -150,19 +152,22 @@ bool UltraHonkAPI::verify(const Flags& flags,
const std::filesystem::path& vk_path)
{
const bool ipa_accumulation = flags.ipa_accumulation;
bool verified = false;
if (ipa_accumulation) {
return _verify<UltraRollupFlavor>(ipa_accumulation, proof_path, vk_path);
verified = _verify<UltraRollupFlavor>(ipa_accumulation, proof_path, vk_path);
}
if (flags.zk) {
return _verify<UltraKeccakZKFlavor>(ipa_accumulation, proof_path, vk_path);
verified = _verify<UltraKeccakZKFlavor>(ipa_accumulation, proof_path, vk_path);
}
if (flags.oracle_hash_type == "poseidon2") {
return _verify<UltraFlavor>(ipa_accumulation, proof_path, vk_path);
verified = _verify<UltraFlavor>(ipa_accumulation, proof_path, vk_path);
}
if (flags.oracle_hash_type == "keccak") {
return _verify<UltraKeccakFlavor>(ipa_accumulation, proof_path, vk_path);
verified = _verify<UltraKeccakFlavor>(ipa_accumulation, proof_path, vk_path);
}
return false;

verified ? info("Proof verified successfully") : info("Proof verification failed");
return verified;
}

bool UltraHonkAPI::prove_and_verify([[maybe_unused]] const Flags& flags,
Expand Down Expand Up @@ -200,9 +205,9 @@ void UltraHonkAPI::gates([[maybe_unused]] const Flags& flags,
gate_count(bytecode_path, flags.recursive, flags.honk_recursion);
}

void UltraHonkAPI::write_contract(const Flags& flags,
const std::filesystem::path& output_path,
const std::filesystem::path& vk_path)
void UltraHonkAPI::write_solidity_verifier(const Flags& flags,
const std::filesystem::path& output_path,
const std::filesystem::path& vk_path)
{
using VK = UltraKeccakFlavor::VerificationKey;
auto vk = std::make_shared<VK>(from_buffer<VK>(read_file(vk_path)));
Expand All @@ -212,6 +217,7 @@ void UltraHonkAPI::write_contract(const Flags& flags,
std::cout << contract;
} else {
write_file(output_path, { contract.begin(), contract.end() });
info("Solidity verifier saved to ", output_path);
}
}

Expand Down
6 changes: 3 additions & 3 deletions barretenberg/cpp/src/barretenberg/api/api_ultra_honk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class UltraHonkAPI : public API {

void gates(const Flags& flags, const std::filesystem::path& bytecode_path) override;

void write_contract(const Flags& flags,
const std::filesystem::path& output_path,
const std::filesystem::path& vk_path) override;
void write_solidity_verifier(const Flags& flags,
const std::filesystem::path& output_path,
const std::filesystem::path& vk_path) override;
};

template <typename Flavor>
Expand Down
4 changes: 4 additions & 0 deletions barretenberg/cpp/src/barretenberg/api/write_prover_output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ void write(const ProverOutput& prover_output,
write_bytes_to_stdout(buf);
} else {
write_file(output_dir / "proof", buf);
info("Proof saved to ", output_dir / "proof");
}
break;
}
Expand All @@ -43,6 +44,7 @@ void write(const ProverOutput& prover_output,
write_bytes_to_stdout(buf);
} else {
write_file(output_dir / "vk", buf);
info("VK saved to ", output_dir / "vk");
}
break;
}
Expand All @@ -57,6 +59,7 @@ void write(const ProverOutput& prover_output,
std::cout << proof_json;
} else {
write_file(output_dir / "proof_fields.json", { proof_json.begin(), proof_json.end() });
info("Proof fields saved to ", output_dir / "proof_fields.json");
}
break;
}
Expand All @@ -66,6 +69,7 @@ void write(const ProverOutput& prover_output,
std::cout << vk_json;
} else {
write_file(output_dir / "vk_fields.json", { vk_json.begin(), vk_json.end() });
info("VK fields saved to ", output_dir / "vk_fields.json");
}
break;
}
Expand Down
24 changes: 12 additions & 12 deletions barretenberg/cpp/src/barretenberg/bb/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,21 +318,21 @@ int main(int argc, char* argv[])
add_recursive_flag(verify);

/***************************************************************************************************************
* Subcommand: write_contract
* Subcommand: write_solidity_verifier
***************************************************************************************************************/
CLI::App* write_contract =
app.add_subcommand("write_contract",
"Write a smart contract suitable for verifying proofs of circuit "
CLI::App* write_solidity_verifier =
app.add_subcommand("write_solidity_verifier",
"Write a Solidity smart contract suitable for verifying proofs of circuit "
"satisfiability for the circuit with verification key at vk_path. Not all "
"hash types are implemented due to efficiency concerns.");

add_scheme_option(write_contract);
add_vk_path_option(write_contract);
add_output_path_option(write_contract, output_path);
add_scheme_option(write_solidity_verifier);
add_vk_path_option(write_solidity_verifier);
add_output_path_option(write_solidity_verifier, output_path);

add_verbose_flag(write_contract);
add_zk_option(write_contract);
add_crs_path_option(write_contract);
add_verbose_flag(write_solidity_verifier);
add_zk_option(write_solidity_verifier);
add_crs_path_option(write_solidity_verifier);

/***************************************************************************************************************
* Subcommand: OLD_API
Expand Down Expand Up @@ -668,8 +668,8 @@ int main(int argc, char* argv[])
if (verify->parsed()) {
return api.verify(flags, proof_path, vk_path) ? 0 : 1;
}
if (write_contract->parsed()) {
api.write_contract(flags, output_path, vk_path);
if (write_solidity_verifier->parsed()) {
api.write_solidity_verifier(flags, output_path, vk_path);
return 0;
}
auto subcommands = app.get_subcommands();
Expand Down
2 changes: 1 addition & 1 deletion barretenberg/cpp/src/barretenberg/bb/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Barretenberg UltraHonk comes with the capability to verify proofs in Solidity, i
**WARNING:** Contract incomplete, do not use in production!

```bash
bb write_contract --scheme ultra_honk -k ./target/vk -b ./target/hello_world.json -o ./target/Verifier.sol
bb write_solidity_verifier --scheme ultra_honk -k ./target/vk -b ./target/hello_world.json -o ./target/Verifier.sol
```

#### Usage with MegaHonk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ template <IsUltraFlavor Flavor> class DeciderProvingKey_ {
}
}

info("Finalized circuit size: ",
circuit.num_gates,
". Log dyadic circuit size: ",
numeric::get_msb(dyadic_circuit_size),
".");
vinfo("Finalized circuit size: ",
circuit.num_gates,
". Log dyadic circuit size: ",
numeric::get_msb(dyadic_circuit_size),
".");
circuit.blocks.compute_offsets(is_structured); // compute offset of each block within the trace

// Find index of last non-trivial wire value in the trace
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/noir-protocol-circuits/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function compile {
local verifier_path="$key_dir/${name}_verifier.sol"
SECONDS=0
# Generate solidity verifier for this contract.
echo "$vk_bytes" | xxd -r -p | $BB write_contract --scheme ultra_honk -k - -o $verifier_path
echo "$vk_bytes" | xxd -r -p | $BB write_solidity_verifier --scheme ultra_honk -k - -o $verifier_path
echo_stderr "VK output at: $verifier_path (${SECONDS}s)"
# Include the verifier path if we create it.
cache_upload vk-$hash.tar.gz $key_path $verifier_path &> /dev/null
Expand Down