From b02679d0b2772a34b44ccd4c7af5a3de6cfbd625 Mon Sep 17 00:00:00 2001 From: Darioush Jalali Date: Wed, 22 Feb 2023 18:53:40 -0800 Subject: [PATCH 1/4] fix config template for precompilegen --- .../precompile_config_template.go | 23 ------------------- 1 file changed, 23 deletions(-) diff --git a/accounts/abi/bind/precompilebind/precompile_config_template.go b/accounts/abi/bind/precompilebind/precompile_config_template.go index 4d8f9252de..fac3bc60c7 100644 --- a/accounts/abi/bind/precompilebind/precompile_config_template.go +++ b/accounts/abi/bind/precompilebind/precompile_config_template.go @@ -35,30 +35,7 @@ type Config struct { // Add your own custom fields for Config here } -{{$structs := .Structs}} -{{range $structs}} - // {{.Name}} is an auto generated low-level Go binding around an user-defined struct. - type {{.Name}} struct { - {{range $field := .Fields}} - {{$field.Name}} {{$field.Type}}{{end}} - } -{{- end}} - -{{- range .Contract.Funcs}} -{{ if len .Normalized.Inputs | lt 1}} -type {{capitalise .Normalized.Name}}Input struct{ -{{range .Normalized.Inputs}} {{capitalise .Name}} {{bindtype .Type $structs}}; {{end}} -} -{{- end}} -{{ if len .Normalized.Outputs | lt 1}} -type {{capitalise .Normalized.Name}}Output struct{ -{{range .Normalized.Outputs}} {{capitalise .Name}} {{bindtype .Type $structs}}; {{end}} -} -{{- end}} -{{- end}} - // NewConfig returns a config for a network upgrade at [blockTimestamp] that enables -// {{.Contract.Type}} with the given [admins] and [enableds] as members of the allowlist. // {{.Contract.Type}} {{if .Contract.AllowList}} with the given [admins] as members of the allowlist {{end}}. func NewConfig(blockTimestamp *big.Int{{if .Contract.AllowList}}, admins []common.Address, enableds []common.Address,{{end}}) *Config { return &Config{ From 76c57072a9127155159bbeb1274941fead282990 Mon Sep 17 00:00:00 2001 From: Darioush Jalali Date: Wed, 22 Feb 2023 18:59:39 -0800 Subject: [PATCH 2/4] nits --- .../precompilebind/precompile_config_template.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/accounts/abi/bind/precompilebind/precompile_config_template.go b/accounts/abi/bind/precompilebind/precompile_config_template.go index fac3bc60c7..0d4c7b03c5 100644 --- a/accounts/abi/bind/precompilebind/precompile_config_template.go +++ b/accounts/abi/bind/precompilebind/precompile_config_template.go @@ -24,8 +24,8 @@ import ( var _ precompileconfig.Config = &Config{} -// Config implements the StatefulPrecompileConfig -// interface while adding in the {{.Contract.Type}} specific precompile address. +// Config implements the precompileconfig.Config interface and +// adds specific configuration for {{.Contract.Type}}. type Config struct { {{- if .Contract.AllowList}} allowlist.AllowListConfig @@ -36,14 +36,14 @@ type Config struct { } // NewConfig returns a config for a network upgrade at [blockTimestamp] that enables -// {{.Contract.Type}} {{if .Contract.AllowList}} with the given [admins] as members of the allowlist {{end}}. +// {{.Contract.Type}} {{- if .Contract.AllowList}} with the given [admins] as members of the allowlist {{end}}. func NewConfig(blockTimestamp *big.Int{{if .Contract.AllowList}}, admins []common.Address, enableds []common.Address,{{end}}) *Config { return &Config{ {{- if .Contract.AllowList}} AllowListConfig: allowlist.AllowListConfig{ AdminAddresses: admins, EnabledAddresses: enableds, - }, + }, {{- end}} Upgrade: precompileconfig.Upgrade{BlockTimestamp: blockTimestamp}, } @@ -66,12 +66,12 @@ func (*Config) Key() string { return ConfigKey } // Verify tries to verify Config and returns an error accordingly. func (c *Config) Verify() error { - {{if .Contract.AllowList}} + {{- if .Contract.AllowList}} // Verify AllowList first if err := c.AllowListConfig.Verify(); err != nil { return err } - {{end}} + {{- end}} // CUSTOM CODE STARTS HERE // Add your own custom verify code for Config here // and return an error accordingly @@ -88,7 +88,7 @@ func (c *Config) Equal(s precompileconfig.Config) bool { // CUSTOM CODE STARTS HERE // modify this boolean accordingly with your custom Config, to check if [other] and the current [c] are equal // if Config contains only Upgrade {{if .Contract.AllowList}} and AllowListConfig {{end}} you can skip modifying it. - equals := c.Upgrade.Equal(&other.Upgrade) {{if .Contract.AllowList}} && c.AllowListConfig.Equal(&other.AllowListConfig) {{end}} + equals := c.Upgrade.Equal(&other.Upgrade) {{- if .Contract.AllowList}} && c.AllowListConfig.Equal(&other.AllowListConfig) {{end}} return equals } ` From cca59b15280671291f958350800446c1d881c199 Mon Sep 17 00:00:00 2001 From: Darioush Jalali Date: Wed, 22 Feb 2023 19:01:14 -0800 Subject: [PATCH 3/4] nit --- accounts/abi/bind/precompilebind/precompile_config_template.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/accounts/abi/bind/precompilebind/precompile_config_template.go b/accounts/abi/bind/precompilebind/precompile_config_template.go index 0d4c7b03c5..9b42725302 100644 --- a/accounts/abi/bind/precompilebind/precompile_config_template.go +++ b/accounts/abi/bind/precompilebind/precompile_config_template.go @@ -87,7 +87,7 @@ func (c *Config) Equal(s precompileconfig.Config) bool { } // CUSTOM CODE STARTS HERE // modify this boolean accordingly with your custom Config, to check if [other] and the current [c] are equal - // if Config contains only Upgrade {{if .Contract.AllowList}} and AllowListConfig {{end}} you can skip modifying it. + // if Config contains only Upgrade {{- if .Contract.AllowList}} and AllowListConfig {{end}} you can skip modifying it. equals := c.Upgrade.Equal(&other.Upgrade) {{- if .Contract.AllowList}} && c.AllowListConfig.Equal(&other.AllowListConfig) {{end}} return equals } From 84d1370f9fe45b320574170fc29a1510aace93a1 Mon Sep 17 00:00:00 2001 From: Darioush Jalali Date: Wed, 22 Feb 2023 19:09:40 -0800 Subject: [PATCH 4/4] nits --- .../abi/bind/precompilebind/precompile_contract_template.go | 6 +++--- .../abi/bind/precompilebind/precompile_module_template.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/accounts/abi/bind/precompilebind/precompile_contract_template.go b/accounts/abi/bind/precompilebind/precompile_contract_template.go index 1c302d4b49..21476406bb 100644 --- a/accounts/abi/bind/precompilebind/precompile_contract_template.go +++ b/accounts/abi/bind/precompilebind/precompile_contract_template.go @@ -52,7 +52,7 @@ const ( {{- if .Contract.AllowList}} // This contract also uses AllowList precompile. // You should also increase gas costs of functions that read from AllowList storage. - {{- end}}} + {{- end}} {{- range .Contract.Funcs}} {{.Normalized.Name}}GasCost uint64 = 0 {{if not .Original.IsConstant | and $contract.AllowList}} + allowlist.ReadAllowListGasCost {{end}} // SET A GAS COST HERE {{- end}} @@ -136,7 +136,7 @@ func Set{{.Contract.Type}}AllowListStatus(stateDB contract.StateDB, address comm {{range .Contract.Funcs}} {{if len .Normalized.Inputs | lt 1}} -// Unpack{{capitalise .Normalized.Name}}Input attempts to unpack [input] into the arguments for the {{capitalise .Normalized.Name}}Input{} +// Unpack{{capitalise .Normalized.Name}}Input attempts to unpack [input] as {{capitalise .Normalized.Name}}Input // assumes that [input] does not include selector (omits first 4 func signature bytes) func Unpack{{capitalise .Normalized.Name}}Input(input []byte) ({{capitalise .Normalized.Name}}Input, error) { inputStruct := {{capitalise .Normalized.Name}}Input{} @@ -298,7 +298,7 @@ func {{decapitalise $contract.Type}}Fallback (accessibleState contract.Accessibl {{- end}} // create{{.Contract.Type}}Precompile returns a StatefulPrecompiledContract with getters and setters for the precompile. -{{if .Contract.AllowList}} // Access to the getters/setters is controlled by an allow list for ContractAddress.{{end}} +{{- if .Contract.AllowList}} // Access to the getters/setters is controlled by an allow list for ContractAddress.{{end}} func create{{.Contract.Type}}Precompile() contract.StatefulPrecompiledContract { var functions []*contract.StatefulPrecompileFunction {{- if .Contract.AllowList}} diff --git a/accounts/abi/bind/precompilebind/precompile_module_template.go b/accounts/abi/bind/precompilebind/precompile_module_template.go index db3950e3f5..6a7b27dc92 100644 --- a/accounts/abi/bind/precompilebind/precompile_module_template.go +++ b/accounts/abi/bind/precompilebind/precompile_module_template.go @@ -65,11 +65,11 @@ func (*configurator) Configure(chainConfig contract.ChainConfig, cfg precompilec return fmt.Errorf("incorrect config %T: %v", config, config) } // CUSTOM CODE STARTS HERE - {{if .Contract.AllowList}} + {{- if .Contract.AllowList}} // AllowList is activated for this precompile. Configuring allowlist addresses here. return config.AllowListConfig.Configure(state, ContractAddress) - {{else}} + {{- else}} return nil - {{end}} + {{- end}} } `