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:
parent
9b55169251
commit
7036ab26d7
@ -90,8 +90,8 @@ pub mod signature {
|
|||||||
match v {
|
match v {
|
||||||
v if v == 27 => 0,
|
v if v == 27 => 0,
|
||||||
v if v == 28 => 1,
|
v if v == 28 => 1,
|
||||||
v if v > 36 => ((v - 1) % 2) as u8,
|
v if v >= 35 => ((v - 1) % 2) as u8,
|
||||||
_ => 4
|
_ => 4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -364,7 +364,7 @@ impl UnverifiedTransaction {
|
|||||||
pub fn chain_id(&self) -> Option<u64> {
|
pub fn chain_id(&self) -> Option<u64> {
|
||||||
match self.v {
|
match self.v {
|
||||||
v if self.is_unsigned() => Some(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,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -583,6 +583,27 @@ mod tests {
|
|||||||
assert_eq!(t.chain_id(), None);
|
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]
|
#[test]
|
||||||
fn signing() {
|
fn signing() {
|
||||||
use ethkey::{Random, Generator};
|
use ethkey::{Random, Generator};
|
||||||
|
Loading…
Reference in New Issue
Block a user