diff --git a/packages/consensus/src/validation/block.cairo b/packages/consensus/src/validation/block.cairo index 7a94cde6..9fe74de2 100644 --- a/packages/consensus/src/validation/block.cairo +++ b/packages/consensus/src/validation/block.cairo @@ -2,7 +2,10 @@ use crate::types::utxo_set::UtxoSet; use crate::types::transaction::Transaction; use crate::codec::{Encode, TransactionCodec}; -use utils::{hash::Digest, merkle_tree::merkle_root, double_sha256::double_sha256_byte_array}; +use utils::{ + hash::Digest, merkle_tree::merkle_root, double_sha256::double_sha256_byte_array, + hex::hex_to_hash_rev +}; use super::transaction::validate_transaction; use core::num::traits::zero::Zero; @@ -93,3 +96,23 @@ pub fn compute_and_validate_tx_data( Result::Ok((total_fee, merkle_root(ref txids), wtxid_root)) } + + +pub fn validate_bip30_block_hash(block_height: u32, block_hash: @Digest) -> Result<(), ByteArray> { + if block_height == 91722 { + let expected_hash: Digest = hex_to_hash_rev( + "00000000000271a2dc26e7667f8419f2e15416dc6955e5a6c6cdf3f2574dd08e" + ); + if *block_hash != expected_hash { + return Result::Err("Block hash mismatch for BIP-30 exception at height 91722"); + } + } else if block_height == 91812 { + let expected_hash: Digest = hex_to_hash_rev( + "00000000000af0aed4792b1acee3d966af36cf5def14935db8de83d6f9306f2f" + ); + if *block_hash != expected_hash { + return Result::Err("Block hash mismatch for BIP-30 exception at height 91812"); + } + } + Result::Ok(()) +} diff --git a/packages/consensus/src/validation/coinbase.cairo b/packages/consensus/src/validation/coinbase.cairo index 6c4bc1a4..30380db1 100644 --- a/packages/consensus/src/validation/coinbase.cairo +++ b/packages/consensus/src/validation/coinbase.cairo @@ -168,6 +168,10 @@ fn validate_coinbase_outputs( Result::Ok(()) } +pub fn is_bip30_unspendable(block_height: u32) -> bool { + block_height == 91722 || block_height == 91812 +} + #[cfg(test)] mod tests { use crate::types::transaction::{TxIn, TxOut, Transaction, OutPoint}; diff --git a/packages/consensus/src/validation/transaction.cairo b/packages/consensus/src/validation/transaction.cairo index 6ea16fe7..d91f1ff4 100644 --- a/packages/consensus/src/validation/transaction.cairo +++ b/packages/consensus/src/validation/transaction.cairo @@ -7,6 +7,9 @@ use crate::validation::locktime::{ }; use utils::hash::Digest; +const OP_RETURN: u32 = 0x6a; +const MAX_SCRIPT_SIZE: u32 = 10000; + /// Validate transaction and return transaction fee. /// /// This does not include script checks and outpoint inclusion verification. @@ -120,6 +123,10 @@ fn validate_coinbase_maturity(output_height: u32, block_height: u32) -> Result<( } } +fn is_pubscript_unspendable(pubscript: @ByteArray) -> bool { + pubscript[0].into() == OP_RETURN || pubscript.len() > MAX_SCRIPT_SIZE +} + #[cfg(test)] mod tests { use core::dict::Felt252Dict;