Allow zero chain id in EIP155 signing process (#9792)

* Allow zero chain id in EIP155 signing process

* Rename test

* Fix test failure
This commit is contained in:
Wei Tang 2018-10-26 22:44:02 +08:00 committed by GitHub
parent 9b55169251
commit 7036ab26d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 3 deletions

View File

@ -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<u64> {
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};