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

Remove precompiles (Gingerbread P2) #2168

Merged
merged 5 commits into from
Aug 15, 2023
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
79 changes: 67 additions & 12 deletions core/vm/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ var PrecompiledContractsIstanbul = map[common.Address]CeloPrecompiledContract{
}

// PrecompiledContractsDonut contains the default set of pre-compiled Ethereum
// contracts used in the Donit release.
// contracts used in the Donut release.
var PrecompiledContractsDonut = map[common.Address]CeloPrecompiledContract{
common.BytesToAddress([]byte{1}): &wrap{&ecrecover{}},
common.BytesToAddress([]byte{2}): &wrap{&sha256hash{}},
Expand Down Expand Up @@ -148,9 +148,9 @@ var PrecompiledContractsDonut = map[common.Address]CeloPrecompiledContract{
celoPrecompileAddress(30): &getValidatorBLS{},
}

// PrecompiledContractsBerlin contains the default set of pre-compiled Ethereum
// contracts used in the Berlin release.
var PrecompiledContractsE = map[common.Address]CeloPrecompiledContract{
// PrecompiledContractsEspresso contains the default set of pre-compiled Ethereum
// contracts used in the Espresso release.
var PrecompiledContractsEspresso = map[common.Address]CeloPrecompiledContract{
common.BytesToAddress([]byte{1}): &wrap{&ecrecover{}},
common.BytesToAddress([]byte{2}): &wrap{&sha256hash{}},
common.BytesToAddress([]byte{3}): &wrap{&ripemd160hash{}},
Expand Down Expand Up @@ -195,12 +195,62 @@ var PrecompiledContractsE = map[common.Address]CeloPrecompiledContract{
celoPrecompileAddress(30): &getValidatorBLS{},
}

// PrecompiledContractsGingerbread contains the default set of pre-compiled Ethereum
// contracts used in the Gingerbread release.
var PrecompiledContractsGingerbreadP2 = map[common.Address]CeloPrecompiledContract{
common.BytesToAddress([]byte{1}): &wrap{&ecrecover{}},
common.BytesToAddress([]byte{2}): &wrap{&sha256hash{}},
common.BytesToAddress([]byte{3}): &wrap{&ripemd160hash{}},
common.BytesToAddress([]byte{4}): &wrap{&dataCopy{}},
common.BytesToAddress([]byte{5}): &wrap{&bigModExp{eip2565: true}},
common.BytesToAddress([]byte{6}): &wrap{&bn256AddIstanbul{}},
common.BytesToAddress([]byte{7}): &wrap{&bn256ScalarMulIstanbul{}},
common.BytesToAddress([]byte{8}): &wrap{&bn256PairingIstanbul{}},
common.BytesToAddress([]byte{9}): &wrap{&blake2F{}},

// Celo Precompiled Contracts
celoPrecompileAddress(2): &transfer{},
celoPrecompileAddress(3): &fractionMulExp{},
celoPrecompileAddress(4): &wrap{&proofOfPossession{}},
celoPrecompileAddress(5): &getValidator{},
celoPrecompileAddress(6): &numberValidators{},
celoPrecompileAddress(7): &epochSize{},
celoPrecompileAddress(8): &wrap{&blockNumberFromHeader{}},
celoPrecompileAddress(9): &wrap{&hashHeader{}},
celoPrecompileAddress(10): &getParentSealBitmap{},
celoPrecompileAddress(11): &getVerifiedSealBitmap{},

// New in Donut hard fork
celoPrecompileAddress(12): &ed25519Verify{},
celoPrecompileAddress(30): &getValidatorBLS{},

// Precompiles removed in Gingerbread P2 hard fork
// * bls12381G1Add
// * bls12381G1Mul
// * bls12381G1MultiExp
// * bls12381G2Add
// * bls12381G2Mul
// * bls12381G2MultiExp
// * bls12381Pairing
// * bls12381MapG1
// * bls12381MapG2
// * bls12377G1Add
// * bls12377G1Mul
// * bls12377G1MultiExp
// * bls12377G2Add
// * bls12377G2Mul
// * bls12377G2MultiExp
// * bls12377Pairing
// * cip20HashFunctions
}

var (
PrecompiledAddressesE []common.Address
PrecompiledAddressesDonut []common.Address
PrecompiledAddressesIstanbul []common.Address
PrecompiledAddressesByzantium []common.Address
PrecompiledAddressesHomestead []common.Address
PrecompiledAddressesGingerbreadP2 []common.Address
PrecompiledAddressesEspresso []common.Address
PrecompiledAddressesDonut []common.Address
PrecompiledAddressesIstanbul []common.Address
PrecompiledAddressesByzantium []common.Address
PrecompiledAddressesHomestead []common.Address
)

func init() {
Expand All @@ -216,16 +266,21 @@ func init() {
for k := range PrecompiledContractsDonut {
PrecompiledAddressesDonut = append(PrecompiledAddressesDonut, k)
}
for k := range PrecompiledContractsE {
PrecompiledAddressesE = append(PrecompiledAddressesE, k)
for k := range PrecompiledContractsEspresso {
PrecompiledAddressesEspresso = append(PrecompiledAddressesEspresso, k)
}
for k := range PrecompiledContractsGingerbreadP2 {
PrecompiledAddressesGingerbreadP2 = append(PrecompiledAddressesGingerbreadP2, k)
}
}

// ActivePrecompiles returns the precompiles enabled with the current configuration.
func ActivePrecompiles(rules params.Rules) []common.Address {
switch {
case rules.IsGingerbreadP2:
return PrecompiledAddressesGingerbreadP2
case rules.IsEspresso:
return PrecompiledAddressesE
return PrecompiledAddressesEspresso
case rules.IsDonut:
return PrecompiledAddressesDonut
case rules.IsIstanbul:
Expand Down
4 changes: 3 additions & 1 deletion core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ type (
func (evm *EVM) precompile(addr common.Address) (CeloPrecompiledContract, bool) {
var precompiles map[common.Address]CeloPrecompiledContract
switch {
case evm.chainRules.IsGingerbreadP2:
precompiles = PrecompiledContractsGingerbreadP2
case evm.chainRules.IsEspresso:
precompiles = PrecompiledContractsE
precompiles = PrecompiledContractsEspresso
case evm.chainRules.IsDonut:
precompiles = PrecompiledContractsDonut
case evm.chainRules.IsIstanbul:
Expand Down
9 changes: 0 additions & 9 deletions e2e_test/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,15 +685,6 @@ func runMochaTest(t *testing.T, add_args func(*env.AccountsConfig, *genesis.Conf
require.NoError(t, err)
}

func TestPrecompileWrappers(t *testing.T) {
add_args := func(ac *env.AccountsConfig, gc *genesis.Config, network test.Network) []string {
accounts := test.Accounts(ac.DeveloperAccounts(), gc.ChainConfig())
privateKeyHex := fmt.Sprintf("0x%064x", accounts[0].Key.D)
return []string{"test-precompile-wrappers", "--signerkey=" + privateKeyHex}
}
runMochaTest(t, add_args)
}

func TestEthersJSCompatibility(t *testing.T) {
add_args := func(ac *env.AccountsConfig, gc *genesis.Config, network test.Network) []string {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*20)
Expand Down
3 changes: 1 addition & 2 deletions e2e_test/ethersjs-api-check/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"description": "runs ethers.js against an api to check compatibility",
"main": "index.js",
"scripts": {
"test": "mocha -r ts-node/register test/*.ts",
"test-precompile-wrappers": "mocha -r ts-node/register test-precompile-wrappers/*.ts"
"test": "mocha -r ts-node/register test/*.ts"
},
"author": "",
"license": "ISC",
Expand Down
Loading