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

Replace old packers #857

Merged
merged 26 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f19a275
add equality tests
ceyonur Sep 6, 2023
143aeb7
regenerate abis
ceyonur Sep 6, 2023
f51a4d0
Merge branch 'master' into abi-standardize
ceyonur Sep 6, 2023
a6a90a0
add extra padding tests
ceyonur Sep 11, 2023
a1774c3
Merge branch 'abi-standardize' of github.com:ava-labs/subnet-evm into…
ceyonur Sep 11, 2023
c964e42
Merge branch 'master' into abi-standardize
ceyonur Sep 14, 2023
1166ad3
override network upgrades (#839)
ceyonur Sep 12, 2023
c31b56b
update native minter
ceyonur Sep 13, 2023
80e6d6e
nativeminter nit test changes
ceyonur Sep 14, 2023
116b981
replace fee manager packers
ceyonur Sep 14, 2023
0585f89
remove generated abis
ceyonur Sep 14, 2023
97357bf
Update precompile/contracts/feemanager/contract.go
ceyonur Sep 14, 2023
f0c504c
fix comments
ceyonur Sep 14, 2023
eb2c13b
Merge branch 'replace-old-packers' of github.com:ava-labs/subnet-evm …
ceyonur Sep 14, 2023
d953bf1
readd pack/unpack tests
ceyonur Nov 2, 2023
61d4513
Merge branch 'master' into replace-old-packers
ceyonur Nov 13, 2023
f8301dd
Merge branch 'master' into replace-old-packers
ceyonur Nov 28, 2023
467eac4
add signature tests
ceyonur Nov 28, 2023
f804066
remove skip len check vars
ceyonur Dec 6, 2023
8f69a18
add native minter equality tests
ceyonur Dec 6, 2023
2422e07
add get fee config output fuzz tests
ceyonur Dec 7, 2023
74da64c
add fee manager fuzz tests
ceyonur Dec 7, 2023
6ef61a6
move tests to another test file
ceyonur Dec 7, 2023
7049cf5
move signatures to unpack test
ceyonur Dec 7, 2023
5ba8195
nits
ceyonur Dec 14, 2023
408bb95
Merge branch 'master' into replace-old-packers
ceyonur Dec 15, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

var _ contract.Configurator = &configurator{}

// ConfigKey is the key used in json config files to specify this precompile precompileconfig.
// ConfigKey is the key used in json config files to specify this precompile config.
// must be unique across all precompiles.
const ConfigKey = "{{decapitalise .Contract.Type}}Config"

Expand Down
6 changes: 1 addition & 5 deletions precompile/allowlist/allowlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,10 @@ func CreateAllowListPrecompile(precompileAddr common.Address) contract.StatefulP

func CreateAllowListFunctions(precompileAddr common.Address) []*contract.StatefulPrecompileFunction {
setAdmin := contract.NewStatefulPrecompileFunction(setAdminSignature, createAllowListRoleSetter(precompileAddr, AdminRole))
setManager := contract.NewStatefulPrecompileFunctionWithActivator(setManagerSignature, createAllowListRoleSetter(precompileAddr, ManagerRole), isManagerRoleActivated)
setManager := contract.NewStatefulPrecompileFunctionWithActivator(setManagerSignature, createAllowListRoleSetter(precompileAddr, ManagerRole), contract.IsDUpgradeActivated)
setEnabled := contract.NewStatefulPrecompileFunction(setEnabledSignature, createAllowListRoleSetter(precompileAddr, EnabledRole))
setNone := contract.NewStatefulPrecompileFunction(setNoneSignature, createAllowListRoleSetter(precompileAddr, NoRole))
read := contract.NewStatefulPrecompileFunction(readAllowListSignature, createReadAllowList(precompileAddr))

return []*contract.StatefulPrecompileFunction{setAdmin, setManager, setEnabled, setNone, read}
}

func isManagerRoleActivated(evm contract.AccessibleState) bool {
return evm.GetChainConfig().IsDUpgrade(evm.GetBlockContext().Timestamp())
}
1 change: 0 additions & 1 deletion precompile/contract/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ type ActivationFunc func(AccessibleState) bool
// StatefulPrecompileFunction defines a function implemented by a stateful precompile
type StatefulPrecompileFunction struct {
// selector is the 4 byte function selector for this function
// This should be calculated from the function signature using CalculateFunctionSelector
selector []byte
// execute is performed when this function is selected
execute RunStatefulPrecompileFunc
Expand Down
49 changes: 49 additions & 0 deletions precompile/contract/test_utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package contract

import (
"fmt"

"github.com/ethereum/go-ethereum/common"
)

// PackOrderedHashesWithSelector packs the function selector and ordered list of hashes into [dst]
// byte slice.
// assumes that [dst] has sufficient room for [functionSelector] and [hashes].
// Kept for testing backwards compatibility.
func PackOrderedHashesWithSelector(dst []byte, functionSelector []byte, hashes []common.Hash) error {
copy(dst[:len(functionSelector)], functionSelector)
return PackOrderedHashes(dst[len(functionSelector):], hashes)
}

// PackOrderedHashes packs the ordered list of [hashes] into the [dst] byte buffer.
// assumes that [dst] has sufficient space to pack [hashes] or else this function will panic.
// Kept for testing backwards compatibility.
func PackOrderedHashes(dst []byte, hashes []common.Hash) error {
if len(dst) != len(hashes)*common.HashLength {
return fmt.Errorf("destination byte buffer has insufficient length (%d) for %d hashes", len(dst), len(hashes))
}

var (
start = 0
end = common.HashLength
)
for _, hash := range hashes {
copy(dst[start:end], hash.Bytes())
start += common.HashLength
end += common.HashLength
}
return nil
}

// PackedHash returns packed the byte slice with common.HashLength from [packed]
// at the given [index].
// Assumes that [packed] is composed entirely of packed 32 byte segments.
// Kept for testing backwards compatibility.
func PackedHash(packed []byte, index int) []byte {
start := common.HashLength * index
end := start + common.HashLength
return packed[start:end]
}
41 changes: 4 additions & 37 deletions precompile/contract/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/ava-labs/subnet-evm/accounts/abi"
"github.com/ava-labs/subnet-evm/vmerrs"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
)

Expand Down Expand Up @@ -42,42 +41,6 @@ func DeductGas(suppliedGas uint64, requiredGas uint64) (uint64, error) {
return suppliedGas - requiredGas, nil
}

// PackOrderedHashesWithSelector packs the function selector and ordered list of hashes into [dst]
// byte slice.
// assumes that [dst] has sufficient room for [functionSelector] and [hashes].
func PackOrderedHashesWithSelector(dst []byte, functionSelector []byte, hashes []common.Hash) error {
copy(dst[:len(functionSelector)], functionSelector)
return PackOrderedHashes(dst[len(functionSelector):], hashes)
}

// PackOrderedHashes packs the ordered list of [hashes] into the [dst] byte buffer.
// assumes that [dst] has sufficient space to pack [hashes] or else this function will panic.
func PackOrderedHashes(dst []byte, hashes []common.Hash) error {
if len(dst) != len(hashes)*common.HashLength {
return fmt.Errorf("destination byte buffer has insufficient length (%d) for %d hashes", len(dst), len(hashes))
}

var (
start = 0
end = common.HashLength
)
for _, hash := range hashes {
copy(dst[start:end], hash.Bytes())
start += common.HashLength
end += common.HashLength
}
return nil
}

// PackedHash returns packed the byte slice with common.HashLength from [packed]
// at the given [index].
// Assumes that [packed] is composed entirely of packed 32 byte segments.
func PackedHash(packed []byte, index int) []byte {
start := common.HashLength * index
end := start + common.HashLength
return packed[start:end]
}

// ParseABI parses the given ABI string and returns the parsed ABI.
// If the ABI is invalid, it panics.
func ParseABI(rawABI string) abi.ABI {
Expand All @@ -88,3 +51,7 @@ func ParseABI(rawABI string) abi.ABI {

return parsed
}

func IsDUpgradeActivated(evm AccessibleState) bool {
return evm.GetChainConfig().IsDUpgrade(evm.GetBlockContext().Timestamp())
}
5 changes: 4 additions & 1 deletion precompile/contracts/deployerallowlist/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@ func init() {
}
}

// MakeConfig returns a new precompile config instance.
// This is required for Marshal/Unmarshal the precompile config.
marun marked this conversation as resolved.
Show resolved Hide resolved
func (*configurator) MakeConfig() precompileconfig.Config {
return new(Config)
}

// Configure configures [state] with the given [cfg] config.
// Configure configures [state] with the given [cfg] precompileconfig.
// This function is called by the EVM once per precompile contract activation.
func (c *configurator) Configure(chainConfig precompileconfig.ChainConfig, cfg precompileconfig.Config, state contract.StateDB, blockContext contract.ConfigurationBlockContext) error {
config, ok := cfg.(*Config)
if !ok {
Expand Down
3 changes: 3 additions & 0 deletions precompile/contracts/feemanager/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ func NewDisableConfig(blockTimestamp *uint64) *Config {
}
}

// Key returns the key for the FeeManager precompileconfig.
// This should be the same key as used in the precompile module.
darioush marked this conversation as resolved.
Show resolved Hide resolved
func (*Config) Key() string { return ConfigKey }

// Equal returns true if [cfg] is a [*FeeManagerConfig] and it has been configured identical to [c].
Expand All @@ -67,6 +69,7 @@ func (c *Config) Equal(cfg precompileconfig.Config) bool {
return c.InitialFeeConfig.Equal(other.InitialFeeConfig)
}

// Verify tries to verify Config and returns an error accordingly.
func (c *Config) Verify(chainConfig precompileconfig.ChainConfig) error {
if err := c.AllowListConfig.Verify(chainConfig, c.Upgrade); err != nil {
return err
Expand Down
169 changes: 169 additions & 0 deletions precompile/contracts/feemanager/contract.abi
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
[
{
"inputs": [],
"name": "getFeeConfig",
"outputs": [
{
"internalType": "uint256",
"name": "gasLimit",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "targetBlockRate",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "minBaseFee",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "targetGas",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "baseFeeChangeDenominator",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "minBlockGasCost",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "maxBlockGasCost",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "blockGasCostStep",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getFeeConfigLastChangedAt",
"outputs": [
{
"internalType": "uint256",
"name": "blockNumber",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "addr",
"type": "address"
}
],
"name": "readAllowList",
"outputs": [
{
"internalType": "uint256",
"name": "role",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "addr",
"type": "address"
}
],
"name": "setAdmin",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "addr",
"type": "address"
}
],
"name": "setEnabled",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "gasLimit",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "targetBlockRate",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "minBaseFee",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "targetGas",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "baseFeeChangeDenominator",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "minBlockGasCost",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "maxBlockGasCost",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "blockGasCostStep",
"type": "uint256"
}
],
"name": "setFeeConfig",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "addr",
"type": "address"
}
],
"name": "setNone",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
]
Loading
Loading