Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Allow zero chain id in EIP155 signing process (#9792)
Browse files Browse the repository at this point in the history
* Allow zero chain id in EIP155 signing process

* Rename test

* Fix test failure
  • Loading branch information
sorpaas authored and ordian committed Oct 26, 2018
1 parent 5113335 commit 1349350
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions ethcore/transaction/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down Expand Up @@ -358,7 +358,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,
}
}
Expand Down Expand Up @@ -577,6 +577,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};
Expand Down

0 comments on commit 1349350

Please sign in to comment.