From 7036ab26d76c1f488817f0400fdd03bdc7b3f3b6 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Fri, 26 Oct 2018 22:44:02 +0800 Subject: [PATCH] Allow zero chain id in EIP155 signing process (#9792) * Allow zero chain id in EIP155 signing process * Rename test * Fix test failure --- ethcore/transaction/src/transaction.rs | 27 +++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/ethcore/transaction/src/transaction.rs b/ethcore/transaction/src/transaction.rs index f5034c4b2..ee37f6852 100644 --- a/ethcore/transaction/src/transaction.rs +++ b/ethcore/transaction/src/transaction.rs @@ -90,8 +90,8 @@ pub mod signature { match v { v if v == 27 => 0, v if v == 28 => 1, - v if v > 36 => ((v - 1) % 2) as u8, - _ => 4 + v if v >= 35 => ((v - 1) % 2) as u8, + _ => 4 } } } @@ -364,7 +364,7 @@ impl UnverifiedTransaction { pub fn chain_id(&self) -> Option { match self.v { v if self.is_unsigned() => Some(v), - v if v > 36 => Some((v - 35) / 2), + v if v >= 35 => Some((v - 35) / 2), _ => None, } } @@ -583,6 +583,27 @@ mod tests { assert_eq!(t.chain_id(), None); } + #[test] + fn signing_eip155_zero_chainid() { + use ethkey::{Random, Generator}; + + let key = Random.generate().unwrap(); + let t = Transaction { + action: Action::Create, + nonce: U256::from(42), + gas_price: U256::from(3000), + gas: U256::from(50_000), + value: U256::from(1), + data: b"Hello!".to_vec() + }; + + let hash = t.hash(Some(0)); + let sig = ::ethkey::sign(&key.secret(), &hash).unwrap(); + let u = t.with_signature(sig, Some(0)); + + assert!(SignedTransaction::new(u).is_ok()); + } + #[test] fn signing() { use ethkey::{Random, Generator};