Skip to content

Commit

Permalink
remove allowlist events (#1107)
Browse files Browse the repository at this point in the history
* remove allowlist events

* add signature to topic count
  • Loading branch information
ceyonur authored Feb 29, 2024
1 parent 5b75de4 commit 21d79e0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
3 changes: 3 additions & 0 deletions accounts/abi/bind/precompilebind/precompile_bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ func createPrecompileHook(abifilename string, template string) bind.BindHook {
for key := range allowlist.AllowListABI.Methods {
delete(funcs, key)
}
for events := range allowlist.AllowListABI.Events {
delete(contract.Events, events)
}
}

precompileContract := &tmplPrecompileContract{
Expand Down
10 changes: 5 additions & 5 deletions accounts/abi/bind/precompilebind/precompile_bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ var bindTests = []struct {
require.NoError(t, err)
require.Equal(t, testBytes, unpacked.BytesTest)
gasCost := GetTestEventGasCost(testEventData)
require.Equal(t, contract.LogGas + 2 * contract.LogTopicGas + contract.LogDataGas, gasCost)
require.Equal(t, contract.LogGas + 3 * contract.LogTopicGas + contract.LogDataGas, gasCost)
topics, data, err = PackEmptyEvent()
require.NoError(t, err)
Expand All @@ -553,7 +553,7 @@ var bindTests = []struct {
require.Equal(t, eventID, topics[0])
require.Equal(t, testAddr.Hash(), topics[1])
require.Equal(t, 0, len(data))
require.Equal(t, contract.LogGas + 2 * contract.LogTopicGas, GetIndexedEventGasCost())
require.Equal(t, contract.LogGas + 3 * contract.LogTopicGas, GetIndexedEventGasCost())
testMixedData := MixedEventData{
Num: testInt,
Expand All @@ -567,7 +567,7 @@ var bindTests = []struct {
unpackedMixedData, err := UnpackMixedEventData(data)
require.NoError(t, err)
require.Equal(t, testMixedData, unpackedMixedData)
require.Equal(t, contract.LogGas + contract.LogTopicGas + contract.LogDataGas, GetMixedEventGasCost(testMixedData))
require.Equal(t, contract.LogGas + 2 * contract.LogTopicGas + contract.LogDataGas, GetMixedEventGasCost(testMixedData))
testDynamicData := DynamicEventData{
Str: "test",
Expand All @@ -581,15 +581,15 @@ var bindTests = []struct {
unpackedDynamicData, err := UnpackDynamicEventData(data)
require.NoError(t, err)
require.Equal(t, testDynamicData, unpackedDynamicData)
require.Equal(t, contract.LogGas + 2 * contract.LogTopicGas + 2 * contract.LogDataGas, GetDynamicEventGasCost(testDynamicData))
require.Equal(t, contract.LogGas + 3 * contract.LogTopicGas + 2 * contract.LogDataGas, GetDynamicEventGasCost(testDynamicData))
topics, data, err = PackUnnamedEvent(testUint, testUint)
require.NoError(t, err)
eventID = IEventerABI.Events["unnamed"].ID
require.Len(t, topics, 3)
require.Equal(t, eventID, topics[0])
require.Equal(t, 0, len(data))
require.Equal(t, contract.LogGas + 2 * contract.LogTopicGas, GetUnnamedEventGasCost())
require.Equal(t, contract.LogGas + 3 * contract.LogTopicGas, GetUnnamedEventGasCost())
`,
"",
false,
Expand Down
5 changes: 3 additions & 2 deletions accounts/abi/bind/precompilebind/precompile_event_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ accessibleState.GetStateDB().AddLog(
{{range .Contract.Events}}
{{$event := .}}
{{$createdDataStruct := false}}
{{$topicCount := 0}}
{{$topicCount := 1}}
{{- range .Normalized.Inputs}}
{{- if .Indexed}}
{{$topicCount = add $topicCount 1}}
Expand All @@ -81,8 +81,9 @@ accessibleState.GetStateDB().AddLog(
// The gas cost of the non-indexed data depends on the data type and the data size.
func Get{{.Normalized.Name}}EventGasCost({{if $createdDataStruct}} data {{.Normalized.Name}}EventData{{end}}) uint64 {
gas := contract.LogGas // base gas cost
{{if $topicCount | lt 0}}
{{if $topicCount | lt 1}}
// Add topics gas cost ({{$topicCount}} topics)
// Topics always include the signature hash of the event. The rest are the indexed event arguments.
gas += contract.LogTopicGas * {{$topicCount}}
{{end}}
Expand Down

0 comments on commit 21d79e0

Please sign in to comment.