From d958bafdf4b08e558dbc3783c49b2ee7226d08c0 Mon Sep 17 00:00:00 2001 From: aggstam Date: Mon, 18 Dec 2023 14:28:34 +0200 Subject: [PATCH] validator/verification: validate contract calls vector indexes --- src/error.rs | 11 +++++++++++ src/validator/verification.rs | 6 +++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/error.rs b/src/error.rs index f461b5812..eb5167c54 100644 --- a/src/error.rs +++ b/src/error.rs @@ -469,6 +469,10 @@ pub enum Error { #[error("Contract execution failed")] ContractError(darkfi_sdk::error::ContractError), + #[cfg(feature = "darkfi-sdk")] + #[error("Invalid DarkTree")] + DarkTreeError(darkfi_sdk::error::DarkTreeError), + #[cfg(feature = "blockchain")] #[error("contract wasm bincode not found")] WasmBincodeNotFound, @@ -854,3 +858,10 @@ impl From for Error { Self::ContractError(err) } } + +#[cfg(feature = "darkfi-sdk")] +impl From for Error { + fn from(err: darkfi_sdk::error::DarkTreeError) -> Self { + Self::DarkTreeError(err) + } +} diff --git a/src/validator/verification.rs b/src/validator/verification.rs index 98d4c60c9..45b227b1d 100644 --- a/src/validator/verification.rs +++ b/src/validator/verification.rs @@ -21,6 +21,7 @@ use std::{collections::HashMap, io::Cursor}; use darkfi_sdk::{ blockchain::{block_version, expected_reward}, crypto::{schnorr::SchnorrPublic, PublicKey, CONSENSUS_CONTRACT_ID, MONEY_CONTRACT_ID}, + dark_tree::dark_leaf_vec_integrity_check, pasta::pallas, }; use darkfi_serial::{Decodable, Encodable, WriteExt}; @@ -30,7 +31,7 @@ use crate::{ blockchain::{BlockInfo, BlockchainOverlayPtr}, error::TxVerifyFailed, runtime::vm_runtime::Runtime, - tx::Transaction, + tx::{Transaction, MAX_TX_CALLS, MIN_TX_CALLS}, util::time::TimeKeeper, validator::{ consensus::{Consensus, Fork, Proposal, TXS_CAP}, @@ -339,6 +340,9 @@ pub async fn verify_transaction( let tx_hash = 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 let mut zkp_table = vec![]; // Table of public keys used for signature verification