Skip to content

Commit

Permalink
Validate for duplicated names/addrs in precompile spec (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
ferranbt authored and dmarzzz committed Dec 21, 2023
1 parent e6f1d87 commit ce153ea
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions suave/gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,22 @@ func main() {
return ff.Functions[i].Name < ff.Functions[j].Name
})

funcsByName := make(map[string]struct{})
funcsByAddr := make(map[string]struct{})
for _, f := range ff.Functions {
// validate that there are no two functions with the same name
if _, ok := funcsByName[f.Name]; ok {
panic(fmt.Sprintf("duplicate function name: %s", f.Name))
}
funcsByName[f.Name] = struct{}{}

// validate that there are no two functions with the same address
if _, ok := funcsByAddr[f.Address]; ok {
panic(fmt.Sprintf("duplicate function address: %s", f.Address))
}
funcsByAddr[f.Address] = struct{}{}
}

if err := applyTemplate(structsTemplate, ff, "./core/types/suave_structs.go"); err != nil {
panic(err)
}
Expand Down

0 comments on commit ce153ea

Please sign in to comment.