From fd1d154b15051a6b9491fc8d4346bf178aaf24a9 Mon Sep 17 00:00:00 2001 From: zero Date: Tue, 19 Mar 2024 10:26:01 +0100 Subject: [PATCH] runtime/smt: return early with SUCCESS (but give a warning) if the nullifiers list for changing the tree is empty. --- src/runtime/import/smt.rs | 11 ++++++++++- tests/smt.rs | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/runtime/import/smt.rs b/src/runtime/import/smt.rs index 85a2fbee1..a993a21f1 100644 --- a/src/runtime/import/smt.rs +++ b/src/runtime/import/smt.rs @@ -24,7 +24,7 @@ use darkfi_sdk::crypto::{ }; use darkfi_serial::Decodable; use halo2_proofs::pasta::pallas; -use log::error; +use log::{error, warn}; use num_bigint::BigUint; 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 if buf_reader.position() != (len as u64) { error!( diff --git a/tests/smt.rs b/tests/smt.rs index f10803e95..3c4c83240 100644 --- a/tests/smt.rs +++ b/tests/smt.rs @@ -44,7 +44,7 @@ fn zkvm_smt() -> Result<()> { // Use the leaf value as its position in the SMT // Therefore we need an additional constraint that leaf == pos 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]; assert_eq!(pos, leaf);