From 03af2808f2fd948e994a11e6c2c980646c10b224 Mon Sep 17 00:00:00 2001 From: ledigang Date: Thu, 20 Nov 2025 18:11:55 +0800 Subject: [PATCH 1/4] refactor: replace HasPrefix+TrimPrefix with CutPrefix Signed-off-by: ledigang --- cmd/retest/retest.go | 6 ++---- util/util.go | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/cmd/retest/retest.go b/cmd/retest/retest.go index 348fc42c..85b6d165 100644 --- a/cmd/retest/retest.go +++ b/cmd/retest/retest.go @@ -279,8 +279,7 @@ func processNumericString(s string) *big.Int { if strings.Contains(s, ":") { log.Fatal().Str("string", s).Msg("Unknown number format") } - if strings.HasPrefix(s, "0x") { - s = strings.TrimPrefix(s, "0x") + if s, ok := strings.CutPrefix(s, "0x"); ok { num, fullRead := new(big.Int).SetString(s, 16) if !fullRead { log.Fatal().Str("input", s).Msg("Unable to read the full hex data?!") @@ -585,8 +584,7 @@ func rawArgsToStrings(rawArgs string, params []string) []string { processedArgs := make([]string, count) for k, arg := range argList { if strings.HasPrefix(params[k], "uint") { - if strings.HasPrefix(arg, "0x") { - arg = strings.TrimPrefix(arg, "0x") + if arg, ok := strings.CutPrefix(arg, "0x"); ok { if len(arg) > 64 { // i think this is a bug but there is a test case that's somehow longer than 32 bytes // https://github.com/ethereum/tests/blob/fd26aad70e24f042fcd135b2f0338b1c6bf1a324/src/GeneralStateTestsFiller/Cancun/stEIP1153-transientStorage/transStorageOKFiller.yml#L801 diff --git a/util/util.go b/util/util.go index c8f3ecca..b9582e9c 100644 --- a/util/util.go +++ b/util/util.go @@ -431,8 +431,7 @@ func GetHexString(data any) string { if reflect.TypeOf(data).Kind() == reflect.Float64 { result = fmt.Sprintf("%x", int64(data.(float64))) } else if reflect.TypeOf(data).Kind() == reflect.String { - if strings.HasPrefix(data.(string), "0x") { - result = strings.TrimPrefix(data.(string), "0x") + if result, ok := strings.CutPrefix(data.(string), "0x"); ok { } else { result = data.(string) } From 1b57d3eeacdaf4562b542dc93d51c8293f327a4c Mon Sep 17 00:00:00 2001 From: leovct Date: Thu, 18 Dec 2025 07:57:43 +0000 Subject: [PATCH 2/4] fix: util issue --- util/util.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/util.go b/util/util.go index b9582e9c..29bea912 100644 --- a/util/util.go +++ b/util/util.go @@ -431,8 +431,8 @@ func GetHexString(data any) string { if reflect.TypeOf(data).Kind() == reflect.Float64 { result = fmt.Sprintf("%x", int64(data.(float64))) } else if reflect.TypeOf(data).Kind() == reflect.String { - if result, ok := strings.CutPrefix(data.(string), "0x"); ok { - } else { + result, ok := strings.CutPrefix(data.(string), "0x") + if !ok { result = data.(string) } } else { From 13cf7666afac27d2c0a440fc002dbb16ee5dc383 Mon Sep 17 00:00:00 2001 From: leovct Date: Thu, 18 Dec 2025 08:12:10 +0000 Subject: [PATCH 3/4] fix: var initialization --- util/util.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/util/util.go b/util/util.go index 29bea912..0894d9ca 100644 --- a/util/util.go +++ b/util/util.go @@ -431,7 +431,8 @@ func GetHexString(data any) string { if reflect.TypeOf(data).Kind() == reflect.Float64 { result = fmt.Sprintf("%x", int64(data.(float64))) } else if reflect.TypeOf(data).Kind() == reflect.String { - result, ok := strings.CutPrefix(data.(string), "0x") + var ok bool + result, ok = strings.CutPrefix(data.(string), "0x") if !ok { result = data.(string) } From 596839223eeaacbd36cd2fda99cca756dd4c513c Mon Sep 17 00:00:00 2001 From: leovct Date: Thu, 18 Dec 2025 08:15:49 +0000 Subject: [PATCH 4/4] chore: define new var --- cmd/retest/retest.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cmd/retest/retest.go b/cmd/retest/retest.go index 85b6d165..bcea6e40 100644 --- a/cmd/retest/retest.go +++ b/cmd/retest/retest.go @@ -279,10 +279,10 @@ func processNumericString(s string) *big.Int { if strings.Contains(s, ":") { log.Fatal().Str("string", s).Msg("Unknown number format") } - if s, ok := strings.CutPrefix(s, "0x"); ok { - num, fullRead := new(big.Int).SetString(s, 16) + if result, ok := strings.CutPrefix(s, "0x"); ok { + num, fullRead := new(big.Int).SetString(result, 16) if !fullRead { - log.Fatal().Str("input", s).Msg("Unable to read the full hex data?!") + log.Fatal().Str("input", result).Msg("Unable to read the full hex data?!") } return num } @@ -584,13 +584,13 @@ func rawArgsToStrings(rawArgs string, params []string) []string { processedArgs := make([]string, count) for k, arg := range argList { if strings.HasPrefix(params[k], "uint") { - if arg, ok := strings.CutPrefix(arg, "0x"); ok { - if len(arg) > 64 { + if result, ok := strings.CutPrefix(arg, "0x"); ok { + if len(result) > 64 { // i think this is a bug but there is a test case that's somehow longer than 32 bytes // https://github.com/ethereum/tests/blob/fd26aad70e24f042fcd135b2f0338b1c6bf1a324/src/GeneralStateTestsFiller/Cancun/stEIP1153-transientStorage/transStorageOKFiller.yml#L801 - arg = arg[len(arg)-64:] + result = result[len(result)-64:] } - n, _ := new(big.Int).SetString(arg, 16) + n, _ := new(big.Int).SetString(result, 16) processedArgs[k] = n.String() } else { processedArgs[k] = arg