Эх сурвалжийг харах

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

zero 2 жил өмнө
parent
commit
fd1d154b15

+ 10 - 1
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!(

+ 1 - 1
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);