Merge pull request #129 from ethcore/verification

Some missing checks for verification
This commit is contained in:
Svyatoslav Nikolsky 2016-11-16 08:59:08 +03:00 committed by GitHub
commit d25215634e
3 changed files with 20 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

@ -10,6 +10,7 @@ use utils;
const BLOCK_MAX_FUTURE: i64 = 2 * 60 * 60; // 2 hours
const COINBASE_MATURITY: u32 = 100; // 2 hours
const MAX_BLOCK_SIGOPS: usize = 20000;
const MAX_BLOCK_SIZE: usize = 1000000;
pub struct ChainVerifier {
store: Arc<db::Store>,
@ -176,6 +177,12 @@ impl Verify for ChainVerifier {
return Err(Error::Timestamp);
}
// todo: serialized_size function is at least suboptimal
let size = ::serialization::Serializable::serialized_size(block);
if size > MAX_BLOCK_SIZE {
return Err(Error::Size(size))
}
// verify merkle root
if block.merkle_root() != block.header().merkle_root_hash {
return Err(Error::MerkleRoot);
@ -186,6 +193,14 @@ impl Verify for ChainVerifier {
return Err(Error::Coinbase)
}
// check that coinbase has a valid 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!(
utils::transaction_sigops(&block.transactions()[0])

View File

@ -50,6 +50,10 @@ 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),
/// Block size is invalid
Size(usize),
}
#[derive(Debug, PartialEq)]