runtime/smt: return early with SUCCESS (but give a warning) if the nullifiers list for changing the tree is empty.

This commit is contained in:
zero
2024-03-19 10:26:01 +01:00
parent 309157e0ba
commit fd1d154b15
2 changed files with 11 additions and 2 deletions

View File

@@ -24,7 +24,7 @@ use darkfi_sdk::crypto::{
}; };
use darkfi_serial::Decodable; use darkfi_serial::Decodable;
use halo2_proofs::pasta::pallas; use halo2_proofs::pasta::pallas;
use log::error; use log::{error, warn};
use num_bigint::BigUint; use num_bigint::BigUint;
use wasmer::{FunctionEnvMut, WasmPtr}; use wasmer::{FunctionEnvMut, WasmPtr};
@@ -158,6 +158,15 @@ pub(crate) fn sparse_merkle_insert_batch(
} }
}; };
// Nothing to do so just return here
if nullifiers.is_empty() {
warn!(
target: "runtime::smt::sparse_merkle_insert_batch",
"[WASM] [{}] sparse_merkle_insert_batch(): Nothing to add! Returning.", cid
);
return darkfi_sdk::entrypoint::SUCCESS
}
// Make sure we've read the entire buffer // Make sure we've read the entire buffer
if buf_reader.position() != (len as u64) { if buf_reader.position() != (len as u64) {
error!( error!(

View File

@@ -44,7 +44,7 @@ fn zkvm_smt() -> Result<()> {
// Use the leaf value as its position in the SMT // Use the leaf value as its position in the SMT
// Therefore we need an additional constraint that leaf == pos // Therefore we need an additional constraint that leaf == pos
let leaves: Vec<_> = leaves.into_iter().map(|l| (l, l)).collect(); let leaves: Vec<_> = leaves.into_iter().map(|l| (l, l)).collect();
smt.insert_batch(leaves.clone()); smt.insert_batch(leaves.clone()).unwrap();
let (pos, leaf) = leaves[2]; let (pos, leaf) = leaves[2];
assert_eq!(pos, leaf); assert_eq!(pos, leaf);