Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
fix: use Barretenberg.call to query circuit size from wasm (#121)
Browse files Browse the repository at this point in the history
* fix: use proper method of calling into wasm for getting circuit size

* chore: remove unnecessary conversion into bytes

* fix: remove addition of rounding up on `get_exact_circuit_size`
  • Loading branch information
TomAFrench authored Apr 18, 2023
1 parent 279c817 commit a775af1
Showing 1 changed file with 18 additions and 36 deletions.
54 changes: 18 additions & 36 deletions barretenberg_wasm/src/composer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,15 @@ impl StandardComposer {
let cs_buf = constraint_system.to_bytes();
let cs_ptr = barretenberg.allocate(&cs_buf);

let func = barretenberg
.instance
.exports
.get_function("acir_proofs_get_total_circuit_size")
.unwrap();

let params: Vec<_> = vec![cs_ptr.clone()];
match func.call(&params) {
Ok(vals) => {
let i32_bytes = vals.first().cloned().unwrap().unwrap_i32().to_be_bytes();
let u32_val = u32::from_be_bytes(i32_bytes);
barretenberg.free(cs_ptr);
pow2ceil(u32_val + StandardComposer::NUM_RESERVED_GATES)
}
Err(_) => {
unreachable!("failed on acir_proofs_get_total_circuit_size call");
}
}
let circuit_size = barretenberg
.call("acir_proofs_get_total_circuit_size", &cs_ptr)
.into_i32();
let circuit_size =
u32::try_from(circuit_size).expect("circuit cannot have negative number of gates");

barretenberg.free(cs_ptr);

pow2ceil(circuit_size + StandardComposer::NUM_RESERVED_GATES)
}

pub fn get_exact_circuit_size(
Expand All @@ -79,24 +70,15 @@ impl StandardComposer {
let cs_buf = constraint_system.to_bytes();
let cs_ptr = barretenberg.allocate(&cs_buf);

let func = barretenberg
.instance
.exports
.get_function("acir_proofs_get_exact_circuit_size")
.unwrap();

let params: Vec<_> = vec![cs_ptr.clone()];
match func.call(&params) {
Ok(vals) => {
let i32_bytes = vals.first().cloned().unwrap().unwrap_i32().to_be_bytes();
let u32_val = u32::from_be_bytes(i32_bytes);
barretenberg.free(cs_ptr);
u32_val
}
Err(_) => {
unreachable!("failed on acir_proofs_get_exact_circuit_size call");
}
}
let circuit_size = barretenberg
.call("acir_proofs_get_exact_circuit_size", &cs_ptr)
.into_i32();
let circuit_size =
u32::try_from(circuit_size).expect("circuit cannot have negative number of gates");

barretenberg.free(cs_ptr);

circuit_size
}

pub fn compute_proving_key(&mut self) -> Vec<u8> {
Expand Down

0 comments on commit a775af1

Please sign in to comment.