ensure latest HF is always with p256 verify

This commit is contained in:
Lucca Martins 2025-02-16 19:07:47 -03:00
parent 1de5835163
commit 9b0ca36507
No known key found for this signature in database
GPG key ID: DC3D7F76BDAE23BF
2 changed files with 44 additions and 19 deletions

View file

@ -119,25 +119,26 @@ var PrecompiledContractsCancun = PrecompiledContracts{
// PrecompiledContractsPrague contains the set of pre-compiled Ethereum // PrecompiledContractsPrague contains the set of pre-compiled Ethereum
// contracts used in the Prague release. // contracts used in the Prague release.
var PrecompiledContractsPrague = PrecompiledContracts{ var PrecompiledContractsPrague = PrecompiledContracts{
common.BytesToAddress([]byte{0x01}): &ecrecover{}, common.BytesToAddress([]byte{0x01}): &ecrecover{},
common.BytesToAddress([]byte{0x02}): &sha256hash{}, common.BytesToAddress([]byte{0x02}): &sha256hash{},
common.BytesToAddress([]byte{0x03}): &ripemd160hash{}, common.BytesToAddress([]byte{0x03}): &ripemd160hash{},
common.BytesToAddress([]byte{0x04}): &dataCopy{}, common.BytesToAddress([]byte{0x04}): &dataCopy{},
common.BytesToAddress([]byte{0x05}): &bigModExp{eip2565: true}, common.BytesToAddress([]byte{0x05}): &bigModExp{eip2565: true},
common.BytesToAddress([]byte{0x06}): &bn256AddIstanbul{}, common.BytesToAddress([]byte{0x06}): &bn256AddIstanbul{},
common.BytesToAddress([]byte{0x07}): &bn256ScalarMulIstanbul{}, common.BytesToAddress([]byte{0x07}): &bn256ScalarMulIstanbul{},
common.BytesToAddress([]byte{0x08}): &bn256PairingIstanbul{}, common.BytesToAddress([]byte{0x08}): &bn256PairingIstanbul{},
common.BytesToAddress([]byte{0x09}): &blake2F{}, common.BytesToAddress([]byte{0x09}): &blake2F{},
common.BytesToAddress([]byte{0x0a}): &kzgPointEvaluation{}, common.BytesToAddress([]byte{0x0a}): &kzgPointEvaluation{},
common.BytesToAddress([]byte{0x0b}): &bls12381G1Add{}, common.BytesToAddress([]byte{0x0b}): &bls12381G1Add{},
common.BytesToAddress([]byte{0x0c}): &bls12381G1Mul{}, common.BytesToAddress([]byte{0x0c}): &bls12381G1Mul{},
common.BytesToAddress([]byte{0x0d}): &bls12381G1MultiExp{}, common.BytesToAddress([]byte{0x0d}): &bls12381G1MultiExp{},
common.BytesToAddress([]byte{0x0e}): &bls12381G2Add{}, common.BytesToAddress([]byte{0x0e}): &bls12381G2Add{},
common.BytesToAddress([]byte{0x0f}): &bls12381G2Mul{}, common.BytesToAddress([]byte{0x0f}): &bls12381G2Mul{},
common.BytesToAddress([]byte{0x10}): &bls12381G2MultiExp{}, common.BytesToAddress([]byte{0x10}): &bls12381G2MultiExp{},
common.BytesToAddress([]byte{0x11}): &bls12381Pairing{}, common.BytesToAddress([]byte{0x11}): &bls12381Pairing{},
common.BytesToAddress([]byte{0x12}): &bls12381MapG1{}, common.BytesToAddress([]byte{0x12}): &bls12381MapG1{},
common.BytesToAddress([]byte{0x13}): &bls12381MapG2{}, common.BytesToAddress([]byte{0x13}): &bls12381MapG2{},
common.BytesToAddress([]byte{0x01, 0x00}): &p256Verify{},
} }
var PrecompiledContractsBLS = PrecompiledContractsPrague var PrecompiledContractsBLS = PrecompiledContractsPrague

View file

@ -20,11 +20,15 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"math"
"math/big"
"os" "os"
"testing" "testing"
"time" "time"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params"
"gotest.tools/assert"
) )
// precompiledTest defines the input/output pairs for precompiled contract tests. // precompiledTest defines the input/output pairs for precompiled contract tests.
@ -434,3 +438,23 @@ func TestPrecompiledP256Verify(t *testing.T) {
testJson("p256Verify", "100", t) testJson("p256Verify", "100", t)
} }
// BOR: if this test failed, it means you should include PrecompiledP256Verify in the PrecompiledContracts
// TODO: handle when common.BytesToAddress([]byte{0x01, 0x00}) will colide a new Ethereum's precompile
func TestPrecompiledP256VerifyAlwaysAvailableInHFs(t *testing.T) {
latestHfRules := params.BorMainnetChainConfig.Rules(big.NewInt(math.MaxInt64), true, 0)
precompiledP256VerifyAddress := common.BytesToAddress([]byte{0x01, 0x00})
addresses := ActivePrecompiles(latestHfRules)
addressFound := false
for _, addr := range addresses {
if addr == precompiledP256VerifyAddress {
addressFound = true
break
}
}
assert.Equal(t, true, addressFound)
preCompiledContracts := ActivePrecompiledContracts(latestHfRules)
assert.Equal(t, &p256Verify{}, preCompiledContracts[precompiledP256VerifyAddress])
}