From 689e2b8181e005e0cf2fbb42d1bdd4f20ff24cae Mon Sep 17 00:00:00 2001 From: 0xOsiris Date: Fri, 25 Oct 2024 09:18:58 -0700 Subject: [PATCH 1/2] more robust tx validation --- world-chain-builder/src/pool/validator.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/world-chain-builder/src/pool/validator.rs b/world-chain-builder/src/pool/validator.rs index 5c23e312..86f79620 100644 --- a/world-chain-builder/src/pool/validator.rs +++ b/world-chain-builder/src/pool/validator.rs @@ -131,6 +131,10 @@ where transaction: &Tx, payload: &PbhPayload, ) -> Result<(), TransactionValidationError> { + // Validate the root first to prevent invalidating a valid transaction with a root that has + // not landed on chain yet + self.validate_root(payload)?; + // Create db transaction and insert the nullifier hash // We do this first to prevent repeatedly validating the same transaction let db_tx = self.pbh_db.tx_mut()?; @@ -138,7 +142,6 @@ where cursor.insert(payload.nullifier_hash.to_be_bytes().into(), EmptyValue)?; let date = chrono::Utc::now(); - self.validate_root(payload)?; self.validate_external_nullifier(date, payload)?; let res = verify_proof( From 64bde60b42cc81c6661db305ce59568efd58ac17 Mon Sep 17 00:00:00 2001 From: 0xOsiris Date: Mon, 28 Oct 2024 08:52:59 -0700 Subject: [PATCH 2/2] chore: change order of ops on nullifier validation --- world-chain-builder/src/pool/validator.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/world-chain-builder/src/pool/validator.rs b/world-chain-builder/src/pool/validator.rs index 86f79620..332de204 100644 --- a/world-chain-builder/src/pool/validator.rs +++ b/world-chain-builder/src/pool/validator.rs @@ -131,9 +131,9 @@ where transaction: &Tx, payload: &PbhPayload, ) -> Result<(), TransactionValidationError> { - // Validate the root first to prevent invalidating a valid transaction with a root that has - // not landed on chain yet self.validate_root(payload)?; + let date = chrono::Utc::now(); + self.validate_external_nullifier(date, payload)?; // Create db transaction and insert the nullifier hash // We do this first to prevent repeatedly validating the same transaction @@ -141,9 +141,6 @@ where let mut cursor = db_tx.cursor_write::()?; cursor.insert(payload.nullifier_hash.to_be_bytes().into(), EmptyValue)?; - let date = chrono::Utc::now(); - self.validate_external_nullifier(date, payload)?; - let res = verify_proof( payload.root, payload.nullifier_hash,