Răsfoiți Sursa

validator/verification: validate contract calls vector indexes

aggstam 2 ani în urmă
părinte
comite
d958bafdf4
2 a modificat fișierele cu 16 adăugiri și 1 ștergeri
  1. 11 0
      src/error.rs
  2. 5 1
      src/validator/verification.rs

+ 11 - 0
src/error.rs

@@ -469,6 +469,10 @@ pub enum Error {
     #[error("Contract execution failed")]
     #[error("Contract execution failed")]
     ContractError(darkfi_sdk::error::ContractError),
     ContractError(darkfi_sdk::error::ContractError),
 
 
+    #[cfg(feature = "darkfi-sdk")]
+    #[error("Invalid DarkTree")]
+    DarkTreeError(darkfi_sdk::error::DarkTreeError),
+
     #[cfg(feature = "blockchain")]
     #[cfg(feature = "blockchain")]
     #[error("contract wasm bincode not found")]
     #[error("contract wasm bincode not found")]
     WasmBincodeNotFound,
     WasmBincodeNotFound,
@@ -854,3 +858,10 @@ impl From<darkfi_sdk::error::ContractError> for Error {
         Self::ContractError(err)
         Self::ContractError(err)
     }
     }
 }
 }
+
+#[cfg(feature = "darkfi-sdk")]
+impl From<darkfi_sdk::error::DarkTreeError> for Error {
+    fn from(err: darkfi_sdk::error::DarkTreeError) -> Self {
+        Self::DarkTreeError(err)
+    }
+}

+ 5 - 1
src/validator/verification.rs

@@ -21,6 +21,7 @@ use std::{collections::HashMap, io::Cursor};
 use darkfi_sdk::{
 use darkfi_sdk::{
     blockchain::{block_version, expected_reward},
     blockchain::{block_version, expected_reward},
     crypto::{schnorr::SchnorrPublic, PublicKey, CONSENSUS_CONTRACT_ID, MONEY_CONTRACT_ID},
     crypto::{schnorr::SchnorrPublic, PublicKey, CONSENSUS_CONTRACT_ID, MONEY_CONTRACT_ID},
+    dark_tree::dark_leaf_vec_integrity_check,
     pasta::pallas,
     pasta::pallas,
 };
 };
 use darkfi_serial::{Decodable, Encodable, WriteExt};
 use darkfi_serial::{Decodable, Encodable, WriteExt};
@@ -30,7 +31,7 @@ use crate::{
     blockchain::{BlockInfo, BlockchainOverlayPtr},
     blockchain::{BlockInfo, BlockchainOverlayPtr},
     error::TxVerifyFailed,
     error::TxVerifyFailed,
     runtime::vm_runtime::Runtime,
     runtime::vm_runtime::Runtime,
-    tx::Transaction,
+    tx::{Transaction, MAX_TX_CALLS, MIN_TX_CALLS},
     util::time::TimeKeeper,
     util::time::TimeKeeper,
     validator::{
     validator::{
         consensus::{Consensus, Fork, Proposal, TXS_CAP},
         consensus::{Consensus, Fork, Proposal, TXS_CAP},
@@ -339,6 +340,9 @@ pub async fn verify_transaction(
     let tx_hash = tx.hash()?;
     let tx_hash = tx.hash()?;
     debug!(target: "validator::verification::verify_transaction", "Validating transaction {}", tx_hash);
     debug!(target: "validator::verification::verify_transaction", "Validating transaction {}", tx_hash);
 
 
+    // Verify calls indexes integrity
+    dark_leaf_vec_integrity_check(&tx.calls, Some(MIN_TX_CALLS), Some(MAX_TX_CALLS))?;
+
     // Table of public inputs used for ZK proof verification
     // Table of public inputs used for ZK proof verification
     let mut zkp_table = vec![];
     let mut zkp_table = vec![];
     // Table of public keys used for signature verification
     // Table of public keys used for signature verification