Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upstream merge fixes #1273

Merged
merged 1 commit into from
Nov 2, 2021
Merged
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
2 changes: 1 addition & 1 deletion core/vm/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func init() {
PrecompiledAddressesHomestead = append(PrecompiledAddressesHomestead, k)
}
for k := range PrecompiledContractsByzantium {
PrecompiledAddressesHomestead = append(PrecompiledAddressesByzantium, k)
PrecompiledAddressesByzantium = append(PrecompiledAddressesByzantium, k)
}
for k := range PrecompiledContractsIstanbul {
PrecompiledAddressesIstanbul = append(PrecompiledAddressesIstanbul, k)
Expand Down
15 changes: 15 additions & 0 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ type (
// ActivePrecompiles returns the addresses of the precompiles enabled with the current
// configuration
func (evm *EVM) ActivePrecompiles() []common.Address {
return append(evm.activePrecompiles(), evm.activeQuorumPrecompiles()...)
}

// (Quorum) moved upstream ActivePrecompiles() logic to new method activePrecompiles()
// This functionality is part of an experimental feature so may be subject to future changes. Keeping the original code
// untouched in a new method should flag any changes from future merges.
func (evm *EVM) activePrecompiles() []common.Address {
switch {
case evm.chainRules.IsYoloV2:
return PrecompiledAddressesYoloV2
Expand All @@ -72,6 +79,14 @@ func (evm *EVM) ActivePrecompiles() []common.Address {
}
}

func (evm *EVM) activeQuorumPrecompiles() []common.Address {
var p []common.Address
if evm.chainRules.IsPrivacyPrecompile {
p = append(p, common.QuorumPrivacyPrecompileContractAddress())
}
return p
}

func (evm *EVM) precompile(addr common.Address) (PrecompiledContract, bool) {
var precompiles map[common.Address]PrecompiledContract
switch {
Expand Down
97 changes: 97 additions & 0 deletions core/vm/evm_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package vm

import (
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params"
"github.com/stretchr/testify/require"
)

func TestActivePrecompiles(t *testing.T) {
tests := []struct {
name string
evm *EVM
want []common.Address
}{
{
name: "istanbul-plus-quorum-privacy",
evm: &EVM{
chainRules: params.Rules{
IsIstanbul: true,
IsPrivacyPrecompile: true,
},
},
want: []common.Address{
common.BytesToAddress([]byte{1}),
common.BytesToAddress([]byte{2}),
common.BytesToAddress([]byte{3}),
common.BytesToAddress([]byte{4}),
common.BytesToAddress([]byte{5}),
common.BytesToAddress([]byte{6}),
common.BytesToAddress([]byte{7}),
common.BytesToAddress([]byte{8}),
common.BytesToAddress([]byte{9}),
common.QuorumPrivacyPrecompileContractAddress(),
},
},
{
name: "homestead-plus-quorum-privacy",
evm: &EVM{
chainRules: params.Rules{
IsHomestead: true,
IsPrivacyPrecompile: true,
},
},
want: []common.Address{
common.BytesToAddress([]byte{1}),
common.BytesToAddress([]byte{2}),
common.BytesToAddress([]byte{3}),
common.BytesToAddress([]byte{4}),
common.QuorumPrivacyPrecompileContractAddress(),
},
},
{
name: "istanbul",
evm: &EVM{
chainRules: params.Rules{
IsIstanbul: true,
IsPrivacyPrecompile: false,
},
},
want: []common.Address{
common.BytesToAddress([]byte{1}),
common.BytesToAddress([]byte{2}),
common.BytesToAddress([]byte{3}),
common.BytesToAddress([]byte{4}),
common.BytesToAddress([]byte{5}),
common.BytesToAddress([]byte{6}),
common.BytesToAddress([]byte{7}),
common.BytesToAddress([]byte{8}),
common.BytesToAddress([]byte{9}),
},
},
{
name: "homestead",
evm: &EVM{
chainRules: params.Rules{
IsHomestead: true,
IsPrivacyPrecompile: false,
},
},
want: []common.Address{
common.BytesToAddress([]byte{1}),
common.BytesToAddress([]byte{2}),
common.BytesToAddress([]byte{3}),
common.BytesToAddress([]byte{4}),
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := tt.evm.ActivePrecompiles()
require.ElementsMatchf(t, tt.want, got, "want: %v, got: %v", tt.want, got)
})
}
}