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

GH-3406 test different conditional value #3422

Merged
merged 1 commit into from
Jun 3, 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
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,13 @@ extension SECP256K1.UnmarshaledSignature {
let vBytes: Bytes

// if v was overflown (e.g. chain_id > 109 according to EIP-155)
let chainIdTerm = UInt64((Sol.UInt128(chainIdInt) * 2 + 35) % 256)
let chainIdTerm: UInt8 = UInt8((Sol.UInt128(chainIdInt) * 2 + 35) % 256)
if data.count > 65 {
// max 8 bytes to fit into UInt64
let vBytes = [UInt8](data.suffix(from: 64).prefix(8))
let vInt = UInt64(vBytes)
// recover V by deducting (chainId * 2 + 35) according to EIP-155
let vRecovered = vInt % 256 - chainIdTerm
v = try! UInt8(vRecovered)
v = try! UInt8(vInt % 256) - chainIdTerm
} else {
vBytes = [UInt8]([data[64]])
let vInt = UInt8(vBytes)
Expand All @@ -126,11 +125,10 @@ extension SECP256K1.UnmarshaledSignature {
} else {
// v still can be `{0, 1} + chainId * 2 + 35` for non-legacy transactions (chainId >=0)
if vInt >= 35 {
if chainIdTerm > UInt64(vBytes) {
v = 0
if vInt > chainIdTerm {
v = vInt - chainIdTerm
} else {
let vRecovered = UInt64(vBytes) - chainIdTerm
v = try! UInt8(vRecovered)
v = 0
}
} else {
v = vInt
Expand Down
Loading