Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: flip if else arms for eip155 check #6134

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions crates/primitives/src/transaction/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,18 @@ impl Signature {
let v = u64::decode(buf)?;
let r = Decodable::decode(buf)?;
let s = Decodable::decode(buf)?;
if v >= 35 {
// EIP-155: v = {0, 1} + CHAIN_ID * 2 + 35
let odd_y_parity = ((v - 35) % 2) != 0;
let chain_id = (v - 35) >> 1;
Ok((Signature { r, s, odd_y_parity }, Some(chain_id)))
} else {
if v < 35 {
// non-EIP-155 legacy scheme, v = 27 for even y-parity, v = 28 for odd y-parity
if v != 27 && v != 28 {
return Err(RlpError::Custom("invalid Ethereum signature (V is not 27 or 28)"))
}
let odd_y_parity = v == 28;
Ok((Signature { r, s, odd_y_parity }, None))
} else {
// EIP-155: v = {0, 1} + CHAIN_ID * 2 + 35
let odd_y_parity = ((v - 35) % 2) != 0;
let chain_id = (v - 35) >> 1;
Ok((Signature { r, s, odd_y_parity }, Some(chain_id)))
}
}

Expand Down
Loading