Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions core/vm/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ var PrecompiledContractsPrague = map[common.Address]PrecompiledContract{
common.BytesToAddress([]byte{0x07}): &bn254ScalarMulIstanbul{},
common.BytesToAddress([]byte{0x08}): &bn254PairingIstanbul{},
common.BytesToAddress([]byte{0x09}): &blake2F{},
common.BytesToAddress([]byte{0x0a}): &pointEvaluation{},
common.BytesToAddress([]byte{0x0b}): &bls12381G1Add{},
common.BytesToAddress([]byte{0x0c}): &bls12381G1MultiExp{},
common.BytesToAddress([]byte{0x0d}): &bls12381G2Add{},
Expand Down Expand Up @@ -235,6 +236,7 @@ var PrecompiledContractsMadhugiri = map[common.Address]PrecompiledContract{
common.BytesToAddress([]byte{0x07}): &bn254ScalarMulIstanbul{},
common.BytesToAddress([]byte{0x08}): &bn254PairingIstanbul{},
common.BytesToAddress([]byte{0x09}): &blake2F{},
common.BytesToAddress([]byte{0x0a}): &pointEvaluation{},
common.BytesToAddress([]byte{0x0b}): &bls12381G1Add{},
common.BytesToAddress([]byte{0x0c}): &bls12381G1MultiExp{},
common.BytesToAddress([]byte{0x0d}): &bls12381G2Add{},
Expand All @@ -254,6 +256,7 @@ var PrecompiledContractsMadhugiriPro = map[common.Address]PrecompiledContract{
common.BytesToAddress([]byte{0x07}): &bn254ScalarMulIstanbul{},
common.BytesToAddress([]byte{0x08}): &bn254PairingIstanbul{},
common.BytesToAddress([]byte{0x09}): &blake2F{},
common.BytesToAddress([]byte{0x0a}): &pointEvaluation{},
common.BytesToAddress([]byte{0x0b}): &bls12381G1Add{},
common.BytesToAddress([]byte{0x0c}): &bls12381G1MultiExp{},
common.BytesToAddress([]byte{0x0d}): &bls12381G2Add{},
Expand Down
86 changes: 62 additions & 24 deletions core/vm/contracts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,35 +527,73 @@ func TestLisovoCLZOpcode(t *testing.T) {
}
}

// TestPointEvaluationPrecompileRemoval verifies that the pointEvaluation (KZG) precompile
// is present before LisovoPro and removed starting with LisovoPro.
func TestPointEvaluationPrecompileRemoval(t *testing.T) {
// TestPointEvaluationPrecompileAvailability verifies that the pointEvaluation (KZG)
// precompile remains available through Lisovo and is only removed starting with LisovoPro.
func TestPointEvaluationPrecompileAvailability(t *testing.T) {
t.Parallel()

pointEvaluationAddr := common.BytesToAddress([]byte{0x0a})

// Test Lisovo: should have pointEvaluation
lisovoRules := &chain.Rules{
IsLisovo: true,
IsMadhugiriPro: true,
IsMadhugiri: true,
IsBhilai: true,
}
lisovoPrecompiles := Precompiles(lisovoRules)
if _, exists := lisovoPrecompiles[pointEvaluationAddr]; !exists {
t.Error("pointEvaluation (0x0a) should exist in Lisovo precompiles")
testCases := []struct {
name string
rules *chain.Rules
wantExist bool
}{
{
name: "Prague",
rules: &chain.Rules{
IsPrague: true,
},
wantExist: true,
},
{
name: "Madhugiri",
rules: &chain.Rules{
IsMadhugiri: true,
IsBhilai: true,
},
wantExist: true,
},
{
name: "MadhugiriPro",
rules: &chain.Rules{
IsMadhugiriPro: true,
IsMadhugiri: true,
IsBhilai: true,
},
wantExist: true,
},
{
name: "Lisovo",
rules: &chain.Rules{
IsLisovo: true,
IsMadhugiriPro: true,
IsMadhugiri: true,
IsBhilai: true,
},
wantExist: true,
},
{
name: "LisovoPro",
rules: &chain.Rules{
IsLisovoPro: true,
IsLisovo: true,
IsMadhugiriPro: true,
IsMadhugiri: true,
IsBhilai: true,
},
wantExist: false,
},
}

// Test LisovoPro: should not have pointEvaluation
lisovoProRules := &chain.Rules{
IsLisovoPro: true,
IsLisovo: true,
IsMadhugiriPro: true,
IsMadhugiri: true,
IsBhilai: true,
}
lisovoProPrecompiles := Precompiles(lisovoProRules)
if _, exists := lisovoProPrecompiles[pointEvaluationAddr]; exists {
t.Error("pointEvaluation (0x0a) should not exist in LisovoPro precompiles")
for _, testCase := range testCases {
testCase := testCase
t.Run(testCase.name, func(t *testing.T) {
precompiles := Precompiles(testCase.rules)
_, exists := precompiles[pointEvaluationAddr]
if exists != testCase.wantExist {
t.Fatalf("pointEvaluation (0x0a) existence = %t, want %t", exists, testCase.wantExist)
}
})
}
}