-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stricter validation of EIP-7702 transactions (#11885)
Check (in the txpool and in the main code) that an EIP-7702 transaction is [valid](https://eips.ethereum.org/EIPS/eip-7702#set-code-transaction), namely that: - `to != nil` - `len(authorization_list) != 0` - `authorization.chain_id` is `uint256` - `authorization.nonce` is `uint64` - `authorization.address` is `bytes20` - `authorization.y_parity == 0 || authorization.y_parity == 1` - `authorization.r` is `uint256` - `authorization.s` is `uint256` and `authorization.s <= secp256k1n/2` This PR doesn't implement ethereum/EIPs#8865 or ethereum/EIPs#8845
- Loading branch information
Showing
14 changed files
with
260 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright 2014 The go-ethereum Authors | ||
// (original work) | ||
// Copyright 2024 The Erigon Authors | ||
// (modifications) | ||
// This file is part of Erigon. | ||
// | ||
// Erigon is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Erigon is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with Erigon. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package crypto | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/holiman/uint256" | ||
|
||
"github.com/erigontech/erigon-lib/common/u256" | ||
) | ||
|
||
func TestTransactionSignatureIsValid(t *testing.T) { | ||
check := func(expected bool, v byte, r, s *uint256.Int) { | ||
if TransactionSignatureIsValid(v, r, s, true) != expected { | ||
t.Errorf("mismatch for v: %d r: %d s: %d want: %v", v, r, s, expected) | ||
} | ||
} | ||
minusOne := uint256.NewInt(0).SetAllOne() | ||
one := u256.N1 | ||
zero := u256.N0 | ||
secp256k1nMinus1 := new(uint256.Int).Sub(secp256k1N, u256.N1) | ||
|
||
// correct v,r,s | ||
check(true, 0, one, one) | ||
check(true, 1, one, one) | ||
// incorrect v, correct r,s, | ||
check(false, 2, one, one) | ||
check(false, 3, one, one) | ||
|
||
// incorrect v, combinations of incorrect/correct r,s at lower limit | ||
check(false, 2, zero, zero) | ||
check(false, 2, zero, one) | ||
check(false, 2, one, zero) | ||
check(false, 2, one, one) | ||
|
||
// correct v for any combination of incorrect r,s | ||
check(false, 0, zero, zero) | ||
check(false, 0, zero, one) | ||
check(false, 0, one, zero) | ||
|
||
check(false, 1, zero, zero) | ||
check(false, 1, zero, one) | ||
check(false, 1, one, zero) | ||
|
||
// correct sig with max r,s | ||
check(true, 0, secp256k1nMinus1, secp256k1nMinus1) | ||
// correct v, combinations of incorrect r,s at upper limit | ||
check(false, 0, secp256k1N, secp256k1nMinus1) | ||
check(false, 0, secp256k1nMinus1, secp256k1N) | ||
check(false, 0, secp256k1N, secp256k1N) | ||
|
||
// current callers ensures r,s cannot be negative, but let's test for that too | ||
// as crypto package could be used stand-alone | ||
check(false, 0, minusOne, one) | ||
check(false, 0, one, minusOne) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.