coinbase signature length 2-100 enforce

This commit is contained in:
NikVolf 2016-11-15 22:39:56 +03:00
parent bd4383d814
commit dedad2de55
3 changed files with 15 additions and 0 deletions

View File

@ -352,6 +352,7 @@ impl<F> TransactionInputBuilder<F> where F: Invoke<chain::TransactionInput> {
pub fn coinbase(mut self) -> Self {
self.output = Some(chain::OutPoint { hash: H256::from(0), index: 0xffffffff });
self.signature = vec![0u8; 2].into();
self
}

View File

@ -172,6 +172,15 @@ impl Verify for ChainVerifier {
if !block.transactions()[0].is_coinbase() {
return Err(Error::Coinbase)
}
else {
// check that coinbase does not have a signature
let coinbase = &block.transactions()[0];
// is_coinbase() = true above guarantees that there is at least one input
let coinbase_script_len = coinbase.inputs[0].script_sig().len();
if coinbase_script_len < 2 || coinbase_script_len > 100 {
return Err(Error::CoinbaseSignatureLength(coinbase_script_len));
}
}
// verify transactions (except coinbase)
let mut block_sigops = try!(
@ -261,6 +270,9 @@ mod tests {
fn verify_smoky() {
let storage = TestStorage::with_blocks(&vec![test_data::genesis()]);
let b1 = test_data::block_h1();
println!("{:?}", b1.transactions()[0].inputs[0].script_sig());
let verifier = ChainVerifier::new(Arc::new(storage));
assert_eq!(Chain::Main, verifier.verify(&b1).unwrap());
}

View File

@ -50,6 +50,8 @@ pub enum Error {
/// Maximum sigops operations exceeded - will not provide how much it was in total
/// since it stops counting once `MAX_BLOCK_SIGOPS` is reached
MaximumSigops,
/// Coinbase signature is not in the range 2-100
CoinbaseSignatureLength(usize),
}
#[derive(Debug, PartialEq)]