From ce153ea54b3a9f4f171175e11d58318e06f84f9b Mon Sep 17 00:00:00 2001 From: Ferran Borreguero Date: Tue, 19 Dec 2023 13:23:32 +0000 Subject: [PATCH] Validate for duplicated names/addrs in precompile spec (#132) --- suave/gen/main.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/suave/gen/main.go b/suave/gen/main.go index 3a1d9f3fd..b6276c9bb 100644 --- a/suave/gen/main.go +++ b/suave/gen/main.go @@ -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) }