-
Notifications
You must be signed in to change notification settings - Fork 234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: honk flows exposed through wasm #6096
Changes from 7 commits
d1fdb40
2b4046e
c39f6d5
0010866
39e9cde
f2914cf
204fed0
18ce5cb
6a718a0
a105ace
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,9 @@ ENV VERBOSE=1 | |
# Run double_verify_proof through bb.js on node to check 512k support. | ||
RUN BIN=../ts/dest/node/main.js FLOW=prove_then_verify ./run_acir_tests.sh double_verify_proof | ||
# Run a single arbitrary test not involving recursion through bb.js for UltraHonk | ||
RUN BIN=../ts/dest/node/main.js FLOW=prove_and_verify_ultra_honk ./run_acir_tests.sh 6_array | ||
RUN BIN=../ts/dest/node/main.js FLOW=prove_and_verify_ultra_honk ./run_acir_tests.sh | ||
# RUn a single arbitrary test for separate prove and verify for UltraHonk | ||
RUN BIN=../ts/dest/node/main.js FLOW=prove_then_verify_ultra_honk ./run_acir_tests.sh | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. currently runs all for safety. Can change to not |
||
# Run a single arbitrary test not involving recursion through bb.js for GoblinUltraHonk | ||
RUN BIN=../ts/dest/node/main.js FLOW=prove_and_verify_goblin_ultra_honk ./run_acir_tests.sh 6_array | ||
# Run a single arbitrary test not involving recursion through bb.js for full Goblin | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,3 +191,43 @@ WASM_EXPORT void acir_serialize_verification_key_into_fields(in_ptr acir_compose | |
*out_vkey = to_heap_buffer(vkey_as_fields); | ||
write(out_key_hash, vk_hash); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. core changes: adding functions that are callable by js that expose honk functionality |
||
WASM_EXPORT void acir_prove_ultra_honk(uint8_t const* acir_vec, uint8_t const* witness_vec, uint8_t** out) | ||
{ | ||
auto constraint_system = acir_format::circuit_buf_to_acir_format(from_buffer<std::vector<uint8_t>>(acir_vec)); | ||
auto witness = acir_format::witness_buf_to_witness_data(from_buffer<std::vector<uint8_t>>(witness_vec)); | ||
|
||
auto builder = acir_format::create_circuit<UltraCircuitBuilder>(constraint_system, 0, witness); | ||
|
||
UltraProver prover{ builder }; | ||
auto proof = prover.construct_proof(); | ||
*out = to_heap_buffer(to_buffer</*include_size=*/true>(proof)); | ||
} | ||
|
||
WASM_EXPORT void acir_verify_ultra_honk(uint8_t const* proof_buf, uint8_t const* vk_buf, bool* result) | ||
{ | ||
using VerificationKey = UltraFlavor::VerificationKey; | ||
using VerifierCommitmentKey = bb::VerifierCommitmentKey<curve::BN254>; | ||
using Verifier = UltraVerifier_<UltraFlavor>; | ||
|
||
auto proof = from_buffer<std::vector<bb::fr>>(from_buffer<std::vector<uint8_t>>(proof_buf)); | ||
auto verification_key = std::make_shared<VerificationKey>(from_buffer<VerificationKey>(vk_buf)); | ||
verification_key->pcs_verification_key = std::make_shared<VerifierCommitmentKey>(); | ||
|
||
Verifier verifier{ verification_key }; | ||
|
||
*result = verifier.verify_proof(proof); | ||
} | ||
|
||
WASM_EXPORT void acir_write_vk_ultra_honk(uint8_t const* acir_vec, uint8_t** out) | ||
{ | ||
using ProverInstance = ProverInstance_<UltraFlavor>; | ||
using VerificationKey = UltraFlavor::VerificationKey; | ||
|
||
auto constraint_system = acir_format::circuit_buf_to_acir_format(from_buffer<std::vector<uint8_t>>(acir_vec)); | ||
auto builder = acir_format::create_circuit<UltraCircuitBuilder>(constraint_system, 0, {}); | ||
|
||
ProverInstance prover_inst(builder); | ||
VerificationKey vk(prover_inst.proving_key); | ||
*out = to_heap_buffer(to_buffer(vk)); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,4 +84,6 @@ WASM_EXPORT void acir_serialize_proof_into_fields(in_ptr acir_composer_ptr, | |
|
||
WASM_EXPORT void acir_serialize_verification_key_into_fields(in_ptr acir_composer_ptr, | ||
fr::vec_out_buf out_vkey, | ||
fr::out_buf out_key_hash); | ||
fr::out_buf out_key_hash); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure why I don't have to add the other 2 functions in the hpp, but there aren't any errors from missing them |
||
WASM_EXPORT void acir_prove_ultra_honk(uint8_t const* acir_vec, uint8_t const* witness_vec, uint8_t** out); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,9 +85,9 @@ namespace bb { | |
*/ | ||
class PrecomputedEntitiesBase { | ||
public: | ||
size_t circuit_size; | ||
size_t log_circuit_size; | ||
size_t num_public_inputs; | ||
uint64_t circuit_size; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. had to change these to serializable types (uint64_t), but this led to many compile errors relating to implicit conversions losing precision, so I had to add many static_casts as a temporary fix. The long term fix should be using uint32_t/uint64_t instead of size_t by default in most places that aren't accessing memory |
||
uint64_t log_circuit_size; | ||
uint64_t num_public_inputs; | ||
CircuitType circuit_type; // TODO(#392) | ||
}; | ||
|
||
|
@@ -181,7 +181,7 @@ template <typename PrecomputedCommitments, typename VerifierCommitmentKey> | |
class VerificationKey_ : public PrecomputedCommitments { | ||
public: | ||
std::shared_ptr<VerifierCommitmentKey> pcs_verification_key; | ||
size_t pub_inputs_offset = 0; | ||
uint64_t pub_inputs_offset = 0; | ||
|
||
VerificationKey_() = default; | ||
VerificationKey_(const size_t circuit_size, const size_t num_public_inputs) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ void ProtoGalaxyVerifier_<VerifierInstances>::prepare_for_folding(const std::vec | |
if (!inst->is_accumulator) { | ||
receive_and_finalise_instance(inst, domain_separator); | ||
inst->target_sum = 0; | ||
inst->gate_challenges = std::vector<FF>(inst->verification_key->log_circuit_size, 0); | ||
inst->gate_challenges = std::vector<FF>(static_cast<size_t>(inst->verification_key->log_circuit_size), 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. adding static_cast<size_t> to fix compile errors |
||
} | ||
index++; | ||
|
||
|
@@ -45,11 +45,12 @@ std::shared_ptr<typename VerifierInstances::Instance> ProtoGalaxyVerifier_<Verif | |
|
||
auto delta = transcript->template get_challenge<FF>("delta"); | ||
auto accumulator = get_accumulator(); | ||
auto deltas = compute_round_challenge_pows(accumulator->verification_key->log_circuit_size, delta); | ||
auto deltas = | ||
compute_round_challenge_pows(static_cast<size_t>(accumulator->verification_key->log_circuit_size), delta); | ||
|
||
std::vector<FF> perturbator_coeffs(accumulator->verification_key->log_circuit_size + 1, 0); | ||
std::vector<FF> perturbator_coeffs(static_cast<size_t>(accumulator->verification_key->log_circuit_size) + 1, 0); | ||
if (accumulator->is_accumulator) { | ||
for (size_t idx = 1; idx <= accumulator->verification_key->log_circuit_size; idx++) { | ||
for (size_t idx = 1; idx <= static_cast<size_t>(accumulator->verification_key->log_circuit_size); idx++) { | ||
perturbator_coeffs[idx] = | ||
transcript->template receive_from_prover<FF>("perturbator_" + std::to_string(idx)); | ||
} | ||
|
@@ -112,7 +113,8 @@ std::shared_ptr<typename VerifierInstances::Instance> ProtoGalaxyVerifier_<Verif | |
vk_idx++; | ||
} | ||
next_accumulator->verification_key->num_public_inputs = accumulator->verification_key->num_public_inputs; | ||
next_accumulator->public_inputs = std::vector<FF>(next_accumulator->verification_key->num_public_inputs, 0); | ||
next_accumulator->public_inputs = | ||
std::vector<FF>(static_cast<size_t>(next_accumulator->verification_key->num_public_inputs), 0); | ||
size_t public_input_idx = 0; | ||
for (auto& public_input : next_accumulator->public_inputs) { | ||
size_t inst = 0; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -567,6 +567,42 @@ export class BarretenbergApi { | |
const out = result.map((r, i) => outTypes[i].fromBuffer(r)); | ||
return out as any; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. core change: adding the functions to the bb api |
||
async acirProveUltraHonk(constraintSystemBuf: Uint8Array, witnessBuf: Uint8Array): Promise<Uint8Array> { | ||
const inArgs = [constraintSystemBuf, witnessBuf].map(serializeBufferable); | ||
const outTypes: OutputType[] = [BufferDeserializer()]; | ||
const result = await this.wasm.callWasmExport( | ||
'acir_prove_ultra_honk', | ||
inArgs, | ||
outTypes.map(t => t.SIZE_IN_BYTES), | ||
); | ||
const out = result.map((r, i) => outTypes[i].fromBuffer(r)); | ||
return out[0]; | ||
} | ||
|
||
async acirVerifyUltraHonk(proofBuf: Uint8Array, vkBuf: Uint8Array): Promise<boolean> { | ||
const inArgs = [proofBuf, vkBuf].map(serializeBufferable); | ||
const outTypes: OutputType[] = [BoolDeserializer()]; | ||
const result = await this.wasm.callWasmExport( | ||
'acir_verify_ultra_honk', | ||
inArgs, | ||
outTypes.map(t => t.SIZE_IN_BYTES), | ||
); | ||
const out = result.map((r, i) => outTypes[i].fromBuffer(r)); | ||
return out[0]; | ||
} | ||
|
||
async acirWriteVkUltraHonk(constraintSystemBuf: Uint8Array): Promise<Uint8Array> { | ||
const inArgs = [constraintSystemBuf].map(serializeBufferable); | ||
const outTypes: OutputType[] = [BufferDeserializer()]; | ||
const result = await this.wasm.callWasmExport( | ||
'acir_write_vk_ultra_honk', | ||
inArgs, | ||
outTypes.map(t => t.SIZE_IN_BYTES), | ||
); | ||
const out = result.map((r, i) => outTypes[i].fromBuffer(r)); | ||
return out[0]; | ||
} | ||
} | ||
export class BarretenbergApiSync { | ||
constructor(protected wasm: BarretenbergWasm) {} | ||
|
@@ -1111,4 +1147,40 @@ export class BarretenbergApiSync { | |
const out = result.map((r, i) => outTypes[i].fromBuffer(r)); | ||
return out as any; | ||
} | ||
|
||
acirUltraHonkProve(constraintSystemBuf: Uint8Array, witnessBuf: Uint8Array): Uint8Array { | ||
const inArgs = [constraintSystemBuf, witnessBuf].map(serializeBufferable); | ||
const outTypes: OutputType[] = [BufferDeserializer()]; | ||
const result = this.wasm.callWasmExport( | ||
'acir_prove_ultra_honk', | ||
inArgs, | ||
outTypes.map(t => t.SIZE_IN_BYTES), | ||
); | ||
const out = result.map((r, i) => outTypes[i].fromBuffer(r)); | ||
return out[0]; | ||
} | ||
|
||
acirVerifyUltraHonk(proofBuf: Uint8Array, vkBuf: Uint8Array): boolean { | ||
const inArgs = [proofBuf, vkBuf].map(serializeBufferable); | ||
const outTypes: OutputType[] = [BoolDeserializer()]; | ||
const result = this.wasm.callWasmExport( | ||
'acir_verify_ultra_honk', | ||
inArgs, | ||
outTypes.map(t => t.SIZE_IN_BYTES), | ||
); | ||
const out = result.map((r, i) => outTypes[i].fromBuffer(r)); | ||
return out[0]; | ||
} | ||
|
||
acirWriteVkUltraHonk(constraintSystemBuf: Uint8Array): Uint8Array { | ||
const inArgs = [constraintSystemBuf].map(serializeBufferable); | ||
const outTypes: OutputType[] = [BufferDeserializer()]; | ||
const result = this.wasm.callWasmExport( | ||
'acir_write_vk_ultra_honk', | ||
inArgs, | ||
outTypes.map(t => t.SIZE_IN_BYTES), | ||
); | ||
const out = result.map((r, i) => outTypes[i].fromBuffer(r)); | ||
return out[0]; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RUn -> Run