Skip to content

Commit

Permalink
chore: push unwraps one level higher
Browse files Browse the repository at this point in the history
  • Loading branch information
kevaundray committed May 29, 2024
1 parent 5ddda30 commit 7b7c634
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
4 changes: 2 additions & 2 deletions bindings/c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub extern "C" fn blob_to_kzg_commitment(ctx: *const ProverContext, blob: *const
(blob_slice, ctx_ref)
};

let commitment = ctx.0.blob_to_kzg_commitment(blob);
let commitment = ctx.0.blob_to_kzg_commitment(blob).unwrap();

unsafe {
let commitment_data_slice = std::slice::from_raw_parts_mut(out, BYTES_PER_COMMITMENT);
Expand Down Expand Up @@ -87,7 +87,7 @@ pub extern "C" fn compute_cells_and_kzg_proofs(
(blob_slice, ctx_ref)
};

let (cells, proofs) = ctx.0.compute_cells_and_kzg_proofs(blob);
let (cells, proofs) = ctx.0.compute_cells_and_kzg_proofs(blob).unwrap();
// TODO: This is not consistent with the node way of returning cells and proofs.
// TODO: This may be fine, because node lives at a higher level and has richer features due to napi
let cells_flattened: Vec<_> = cells
Expand Down
17 changes: 8 additions & 9 deletions bindings/java/rust_code/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub unsafe extern "system" fn Java_ethereum_cryptography_LibPeerDASKZG_computeCe
) -> JByteArray<'local> {
let prover_ctx = &mut *(prover_ptr as *mut ProverContext);
let blob = env.convert_byte_array(blob).unwrap();
let cells = prover_ctx.compute_cells(&blob);
let cells = prover_ctx.compute_cells(&blob).unwrap();

let flattened_cells = cells
.iter()
Expand All @@ -58,7 +58,7 @@ pub unsafe extern "system" fn Java_ethereum_cryptography_LibPeerDASKZG_computeCe

let blob = env.convert_byte_array(blob).unwrap();

let (cells, proofs) = prover_ctx.compute_cells_and_kzg_proofs(&blob);
let (cells, proofs) = prover_ctx.compute_cells_and_kzg_proofs(&blob).unwrap();

let flattened_proofs_and_cells: Vec<u8> = cells
.into_iter()
Expand All @@ -82,7 +82,7 @@ pub unsafe extern "system" fn Java_ethereum_cryptography_LibPeerDASKZG_blobToKZG
) -> JByteArray<'local> {
let prover_ctx = &mut *(prover_ptr as *mut ProverContext);
let blob = env.convert_byte_array(blob).unwrap();
let commitment = prover_ctx.blob_to_kzg_commitment(&blob);
let commitment = prover_ctx.blob_to_kzg_commitment(&blob).unwrap();

return env.byte_array_from_slice(&commitment).unwrap();
}
Expand Down Expand Up @@ -124,10 +124,9 @@ pub unsafe extern "system" fn Java_ethereum_cryptography_LibPeerDASKZG_verifyCel
let cell = env.convert_byte_array(&cell).unwrap();
let proof_bytes = env.convert_byte_array(&proof_bytes).unwrap();

return jboolean::from(verifier_ctx.verify_cell_kzg_proof(
&commitment_bytes,
cell_id,
&cell,
&proof_bytes,
));
return jboolean::from(
verifier_ctx
.verify_cell_kzg_proof(&commitment_bytes, cell_id, &cell, &proof_bytes)
.is_ok(),
);
}
24 changes: 16 additions & 8 deletions bindings/node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl Task for AsyncBlobToKzgCommitment {
.prover_context
.read()
.map_err(|_| napi::Error::from_reason("Failed to acquire lock"))?;
let commitment = prover_context.blob_to_kzg_commitment(blob);
let commitment = prover_context.blob_to_kzg_commitment(blob).unwrap();
Ok(commitment)
}

Expand Down Expand Up @@ -76,7 +76,7 @@ impl Task for AsyncComputeCellsAndKzgProofs {
.prover_context
.read()
.map_err(|_| Error::from_reason("Failed to acquire lock"))?;
let (cells, proofs) = prover_context.compute_cells_and_kzg_proofs(blob);
let (cells, proofs) = prover_context.compute_cells_and_kzg_proofs(blob).unwrap();

Ok(NativeCellsAndProofs { cells, proofs })
}
Expand Down Expand Up @@ -112,7 +112,7 @@ impl Task for AsyncComputeCells {
.prover_context
.read()
.map_err(|_| Error::from_reason("Failed to acquire lock"))?;
let cells = prover_context.compute_cells(blob);
let cells = prover_context.compute_cells(blob).unwrap();
Ok(cells)
}

Expand Down Expand Up @@ -146,7 +146,7 @@ impl ProverContextJs {
.inner
.read()
.map_err(|_| Error::from_reason("Failed to acquire lock"))?;
let commitment = prover_context.blob_to_kzg_commitment(blob);
let commitment = prover_context.blob_to_kzg_commitment(blob).unwrap();
Ok(Uint8Array::from(&commitment))
}

Expand All @@ -168,7 +168,7 @@ impl ProverContextJs {
.inner
.read()
.map_err(|_| Error::from_reason("Failed to acquire lock"))?;
let (cells, proofs) = prover_context.compute_cells_and_kzg_proofs(blob);
let (cells, proofs) = prover_context.compute_cells_and_kzg_proofs(blob).unwrap();

let cells_uint8array = cells
.into_iter()
Expand Down Expand Up @@ -203,7 +203,7 @@ impl ProverContextJs {
.inner
.read()
.map_err(|_| Error::from_reason("Failed to acquire lock"))?;
let cells = prover_context.compute_cells(blob);
let cells = prover_context.compute_cells(blob).unwrap();

let cells_uint8array = cells
.into_iter()
Expand Down Expand Up @@ -243,7 +243,11 @@ impl Task for AsyncVerifyCellKzgProof {
.verifier_context
.read()
.map_err(|_| Error::from_reason("Failed to acquire lock"))?;
Ok(verifier_context.verify_cell_kzg_proof(commitment, self.cell_id, cell, proof))
Ok(
verifier_context
.verify_cell_kzg_proof(commitment, self.cell_id, cell, proof)
.is_ok(),
)
}

fn resolve(&mut self, _env: Env, output: Self::Output) -> Result<Self::JsValue> {
Expand Down Expand Up @@ -286,7 +290,11 @@ impl VerifierContextJs {
.map_err(|_| Error::from_reason("Failed to acquire lock"))?;

let cell_id_u64 = cell_id_value as u64;
Ok(verifier_context.verify_cell_kzg_proof(commitment, cell_id_u64, cell, proof))
Ok(
verifier_context
.verify_cell_kzg_proof(commitment, cell_id_u64, cell, proof)
.is_ok(),
)
}

#[napi]
Expand Down

0 comments on commit 7b7c634

Please sign in to comment.