validator/verification: validate contract calls vector indexes

This commit is contained in:
aggstam
2023-12-18 14:28:34 +02:00
parent bd86ce5678
commit d958bafdf4
2 changed files with 16 additions and 1 deletions

View File

@@ -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<darkfi_sdk::error::ContractError> for Error {
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)
}
}

View File

@@ -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