Skip to content

Commit

Permalink
Adding respective validations for block heights and hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerson2102 committed Sep 18, 2024
1 parent e60940a commit 4b86ef2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
25 changes: 24 additions & 1 deletion packages/consensus/src/validation/block.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(())
}
4 changes: 4 additions & 0 deletions packages/consensus/src/validation/coinbase.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
7 changes: 7 additions & 0 deletions packages/consensus/src/validation/transaction.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 4b86ef2

Please sign in to comment.