Skip to content

Commit

Permalink
Remove requirement for chainid to be encoded in transaction v
Browse files Browse the repository at this point in the history
  • Loading branch information
jdowning100 committed Jun 14, 2023
1 parent 79a8d0e commit 82cd1e9
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 22 deletions.
10 changes: 1 addition & 9 deletions core/types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,9 @@ func (tx *Transaction) setDecoded(inner TxData, size int) {
}

func sanityCheckSignature(v *big.Int, r *big.Int, s *big.Int) error {
var plainV byte
if isProtectedV(v) {
chainID := deriveChainId(v).Uint64()
plainV = byte(v.Uint64() - 35 - 2*chainID)
} else {
return ErrExpectedProtection // Unprotected transactions are not supported
}
if !crypto.ValidateSignatureValues(plainV, r, s) {
if !crypto.ValidateSignatureValues(byte(v.Uint64()), r, s) {
return ErrInvalidSig
}

return nil
}

Expand Down
13 changes: 0 additions & 13 deletions core/types/transaction_signing.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,16 +280,3 @@ func recoverPlain(sighash common.Hash, R, S, Vb *big.Int) (common.Address, error
addr := common.BytesToAddress(crypto.Keccak256(pub[1:])[12:])
return addr, nil
}

// deriveChainId derives the chain id from the given v parameter
func deriveChainId(v *big.Int) *big.Int {
if v.BitLen() <= 64 {
v := v.Uint64()
if v == 27 || v == 28 {
return new(big.Int)
}
return new(big.Int).SetUint64((v - 35) / 2)
}
v = new(big.Int).Sub(v, big.NewInt(35))
return v.Div(v, big.NewInt(2))
}

0 comments on commit 82cd1e9

Please sign in to comment.