coinbase signature length 2-100 enforce
This commit is contained in:
parent
bd4383d814
commit
dedad2de55
|
@ -352,6 +352,7 @@ impl<F> TransactionInputBuilder<F> where F: Invoke<chain::TransactionInput> {
|
||||||
|
|
||||||
pub fn coinbase(mut self) -> Self {
|
pub fn coinbase(mut self) -> Self {
|
||||||
self.output = Some(chain::OutPoint { hash: H256::from(0), index: 0xffffffff });
|
self.output = Some(chain::OutPoint { hash: H256::from(0), index: 0xffffffff });
|
||||||
|
self.signature = vec![0u8; 2].into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -172,6 +172,15 @@ impl Verify for ChainVerifier {
|
||||||
if !block.transactions()[0].is_coinbase() {
|
if !block.transactions()[0].is_coinbase() {
|
||||||
return Err(Error::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)
|
// verify transactions (except coinbase)
|
||||||
let mut block_sigops = try!(
|
let mut block_sigops = try!(
|
||||||
|
@ -261,6 +270,9 @@ mod tests {
|
||||||
fn verify_smoky() {
|
fn verify_smoky() {
|
||||||
let storage = TestStorage::with_blocks(&vec![test_data::genesis()]);
|
let storage = TestStorage::with_blocks(&vec![test_data::genesis()]);
|
||||||
let b1 = test_data::block_h1();
|
let b1 = test_data::block_h1();
|
||||||
|
|
||||||
|
println!("{:?}", b1.transactions()[0].inputs[0].script_sig());
|
||||||
|
|
||||||
let verifier = ChainVerifier::new(Arc::new(storage));
|
let verifier = ChainVerifier::new(Arc::new(storage));
|
||||||
assert_eq!(Chain::Main, verifier.verify(&b1).unwrap());
|
assert_eq!(Chain::Main, verifier.verify(&b1).unwrap());
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,8 @@ pub enum Error {
|
||||||
/// Maximum sigops operations exceeded - will not provide how much it was in total
|
/// Maximum sigops operations exceeded - will not provide how much it was in total
|
||||||
/// since it stops counting once `MAX_BLOCK_SIGOPS` is reached
|
/// since it stops counting once `MAX_BLOCK_SIGOPS` is reached
|
||||||
MaximumSigops,
|
MaximumSigops,
|
||||||
|
/// Coinbase signature is not in the range 2-100
|
||||||
|
CoinbaseSignatureLength(usize),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
|
|
Loading…
Reference in New Issue