Skip to content

Commit

Permalink
Remove precompiles (Gingerbread P2) (#2168)
Browse files Browse the repository at this point in the history
* Remove bls12377 precompiles

* Remove bls12381 precompiles

* Remove CIP20 precompile

---------

Co-authored-by: Paul Lange <paul.lange@clabs.co>
  • Loading branch information
gastonponti and palango authored Aug 15, 2023
1 parent b77d52a commit 1c5df77
Show file tree
Hide file tree
Showing 32 changed files with 72 additions and 11,189 deletions.
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

0 comments on commit 1c5df77

Please sign in to comment.