Skip to content

Commit

Permalink
Merge pull request #2322 from dusk-network/fix-double-spend
Browse files Browse the repository at this point in the history
transfer-contract: check for repeated nullifiers in the same TX
  • Loading branch information
Eduardo Leegwater Simões authored Sep 9, 2024
2 parents 7a259e9 + 6bddb66 commit 07dcc61
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions contracts/transfer/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,14 +498,14 @@ impl TransferState {
panic!("Root not found in the state!");
}

// panic if any of the given nullifiers already exist
if self.any_nullifier_exists(phoenix_tx.nullifiers()) {
panic!("A provided nullifier already exists!");
// append the nullifiers to the set, and panic if an equal one has
// already been inserted
for nullifier in phoenix_tx.nullifiers() {
if !self.nullifiers.insert(*nullifier) {
panic!("A provided nullifier has already been spent");
}
}

// append the nullifiers to the nullifiers set
self.nullifiers.extend(phoenix_tx.nullifiers());

// verify the phoenix-circuit
if !verify_tx_proof(phoenix_tx) {
panic!("Invalid transaction proof!");
Expand Down Expand Up @@ -816,16 +816,6 @@ impl TransferState {
}
}

fn any_nullifier_exists(&self, nullifiers: &[BlsScalar]) -> bool {
for nullifier in nullifiers {
if self.nullifiers.contains(nullifier) {
return true;
}
}

false
}

fn root_exists(&self, root: &BlsScalar) -> bool {
self.roots.contains(root)
}
Expand Down

0 comments on commit 07dcc61

Please sign in to comment.