Skip to content

Commit 9b0ca36

Browse files
committed
ensure latest HF is always with p256 verify
1 parent 1de5835 commit 9b0ca36

File tree

2 files changed

+44
-19
lines changed

2 files changed

+44
-19
lines changed

core/vm/contracts.go

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -119,25 +119,26 @@ var PrecompiledContractsCancun = PrecompiledContracts{
119119
// PrecompiledContractsPrague contains the set of pre-compiled Ethereum
120120
// contracts used in the Prague release.
121121
var PrecompiledContractsPrague = PrecompiledContracts{
122-
common.BytesToAddress([]byte{0x01}): &ecrecover{},
123-
common.BytesToAddress([]byte{0x02}): &sha256hash{},
124-
common.BytesToAddress([]byte{0x03}): &ripemd160hash{},
125-
common.BytesToAddress([]byte{0x04}): &dataCopy{},
126-
common.BytesToAddress([]byte{0x05}): &bigModExp{eip2565: true},
127-
common.BytesToAddress([]byte{0x06}): &bn256AddIstanbul{},
128-
common.BytesToAddress([]byte{0x07}): &bn256ScalarMulIstanbul{},
129-
common.BytesToAddress([]byte{0x08}): &bn256PairingIstanbul{},
130-
common.BytesToAddress([]byte{0x09}): &blake2F{},
131-
common.BytesToAddress([]byte{0x0a}): &kzgPointEvaluation{},
132-
common.BytesToAddress([]byte{0x0b}): &bls12381G1Add{},
133-
common.BytesToAddress([]byte{0x0c}): &bls12381G1Mul{},
134-
common.BytesToAddress([]byte{0x0d}): &bls12381G1MultiExp{},
135-
common.BytesToAddress([]byte{0x0e}): &bls12381G2Add{},
136-
common.BytesToAddress([]byte{0x0f}): &bls12381G2Mul{},
137-
common.BytesToAddress([]byte{0x10}): &bls12381G2MultiExp{},
138-
common.BytesToAddress([]byte{0x11}): &bls12381Pairing{},
139-
common.BytesToAddress([]byte{0x12}): &bls12381MapG1{},
140-
common.BytesToAddress([]byte{0x13}): &bls12381MapG2{},
122+
common.BytesToAddress([]byte{0x01}): &ecrecover{},
123+
common.BytesToAddress([]byte{0x02}): &sha256hash{},
124+
common.BytesToAddress([]byte{0x03}): &ripemd160hash{},
125+
common.BytesToAddress([]byte{0x04}): &dataCopy{},
126+
common.BytesToAddress([]byte{0x05}): &bigModExp{eip2565: true},
127+
common.BytesToAddress([]byte{0x06}): &bn256AddIstanbul{},
128+
common.BytesToAddress([]byte{0x07}): &bn256ScalarMulIstanbul{},
129+
common.BytesToAddress([]byte{0x08}): &bn256PairingIstanbul{},
130+
common.BytesToAddress([]byte{0x09}): &blake2F{},
131+
common.BytesToAddress([]byte{0x0a}): &kzgPointEvaluation{},
132+
common.BytesToAddress([]byte{0x0b}): &bls12381G1Add{},
133+
common.BytesToAddress([]byte{0x0c}): &bls12381G1Mul{},
134+
common.BytesToAddress([]byte{0x0d}): &bls12381G1MultiExp{},
135+
common.BytesToAddress([]byte{0x0e}): &bls12381G2Add{},
136+
common.BytesToAddress([]byte{0x0f}): &bls12381G2Mul{},
137+
common.BytesToAddress([]byte{0x10}): &bls12381G2MultiExp{},
138+
common.BytesToAddress([]byte{0x11}): &bls12381Pairing{},
139+
common.BytesToAddress([]byte{0x12}): &bls12381MapG1{},
140+
common.BytesToAddress([]byte{0x13}): &bls12381MapG2{},
141+
common.BytesToAddress([]byte{0x01, 0x00}): &p256Verify{},
141142
}
142143

143144
var PrecompiledContractsBLS = PrecompiledContractsPrague

core/vm/contracts_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,15 @@ import (
2020
"bytes"
2121
"encoding/json"
2222
"fmt"
23+
"math"
24+
"math/big"
2325
"os"
2426
"testing"
2527
"time"
2628

2729
"github.com/ethereum/go-ethereum/common"
30+
"github.com/ethereum/go-ethereum/params"
31+
"gotest.tools/assert"
2832
)
2933

3034
// precompiledTest defines the input/output pairs for precompiled contract tests.
@@ -434,3 +438,23 @@ func TestPrecompiledP256Verify(t *testing.T) {
434438

435439
testJson("p256Verify", "100", t)
436440
}
441+
442+
// BOR: if this test failed, it means you should include PrecompiledP256Verify in the PrecompiledContracts
443+
// TODO: handle when common.BytesToAddress([]byte{0x01, 0x00}) will colide a new Ethereum's precompile
444+
func TestPrecompiledP256VerifyAlwaysAvailableInHFs(t *testing.T) {
445+
latestHfRules := params.BorMainnetChainConfig.Rules(big.NewInt(math.MaxInt64), true, 0)
446+
precompiledP256VerifyAddress := common.BytesToAddress([]byte{0x01, 0x00})
447+
448+
addresses := ActivePrecompiles(latestHfRules)
449+
addressFound := false
450+
for _, addr := range addresses {
451+
if addr == precompiledP256VerifyAddress {
452+
addressFound = true
453+
break
454+
}
455+
}
456+
assert.Equal(t, true, addressFound)
457+
458+
preCompiledContracts := ActivePrecompiledContracts(latestHfRules)
459+
assert.Equal(t, &p256Verify{}, preCompiledContracts[precompiledP256VerifyAddress])
460+
}

0 commit comments

Comments
 (0)