From 436478c8e97d9cd90351975f8789aa2ef9064f16 Mon Sep 17 00:00:00 2001 From: rlaau Date: Tue, 7 Jan 2025 16:00:50 +0900 Subject: [PATCH] fix(gnovm): add fuzz cli and delete pkg/mod files --- gnovm/stdlibs/testing/crash_logger.gno | 4 ---- gnovm/stdlibs/testing/fuzz.gno | 8 ------- ...om_algorythm.gno => genetic_algorythm.gno} | 24 ++++++------------- gnovm/stdlibs/testing/random.gno | 3 +-- gnovm/stdlibs/testing/random_test.gno | 10 ++++---- gnovm/stdlibs/testing/state_machine.gno | 8 +++---- gnovm/stdlibs/testing/testing.gno | 1 - gnovm/stdlibs/testing/to_string.gno | 1 + 8 files changed, 17 insertions(+), 42 deletions(-) rename gnovm/stdlibs/testing/{genom_algorythm.gno => genetic_algorythm.gno} (97%) diff --git a/gnovm/stdlibs/testing/crash_logger.gno b/gnovm/stdlibs/testing/crash_logger.gno index 10e201bd11f..4c4a76c87bf 100644 --- a/gnovm/stdlibs/testing/crash_logger.gno +++ b/gnovm/stdlibs/testing/crash_logger.gno @@ -103,9 +103,7 @@ func (log *Crash_Logger) Kind() []KindInfo { for _, c := range log.data { ki, exists := lookup[c.HashNumber] if !exists { - repMsg := "" - if c.IsPanic { repMsg = c.PanicMessage } else { @@ -194,14 +192,12 @@ func PrintKinds(kinds []KindInfo) { println("No crash kinds found.") return } - println("----- Crash Kinds -----") for _, k := range kinds { println("HashNumber:", k.HashNumber, ", IsPanic:", k.IsPanic, ", Count:", k.Count, ", RepresentativeError:", k.RepresentativeError) - inputStr := k.RepresentativeInput println(" Printed Input:", inputStr) println(" In machine(Escaped edge bytes) Input:", TransForHuman(inputStr)) diff --git a/gnovm/stdlibs/testing/fuzz.gno b/gnovm/stdlibs/testing/fuzz.gno index e426631b8a9..822b76c9c86 100644 --- a/gnovm/stdlibs/testing/fuzz.gno +++ b/gnovm/stdlibs/testing/fuzz.gno @@ -203,8 +203,6 @@ func (f *F) handleEndInfo(endInfo EndInfo, parentSeeds []Seed) bool { func (f *F) updateMachines(parentSeeds []Seed) bool { abstractSeedMap := make(map[HashNumber]abstractSeedInfo) childSeeds := Evolve(parentSeeds, &f.seedCount, f.fsm.string_byte_candidates) - // println("childlen", len(childSeeds)) - for _, child := range childSeeds { child = f.simulateFF(child) if f.failed { @@ -226,12 +224,10 @@ func (f *F) updateMachines(parentSeeds []Seed) bool { } abstractSeedMap[hn] = absSeedInfo } - // println("len!", len(abstractSeedMap)) for hn, absSeedInfo := range abstractSeedMap { seeds := absSeedInfo.seeds if len(seeds) == 1 { - // println("hashNumber", hn, ": 1") concreteEndInfo := f.fsm.CoordinateSeed(seeds[0]) flag := f.handleEndInfo(concreteEndInfo, parentSeeds) if flag { @@ -239,7 +235,6 @@ func (f *F) updateMachines(parentSeeds []Seed) bool { } } else { absNumber := absSeedInfo.abstractNumber - 2 - // println("hashNumber", hn, ":", absNumber+2) absEndInfo := f.fsm.CoordinateAbstraction(hn, absNumber) flag := f.handleEndInfo(absEndInfo, parentSeeds) if flag { @@ -258,7 +253,6 @@ func (f *F) updateMachines(parentSeeds []Seed) bool { } } - // println("iters!") for _, p := range parentSeeds { f.fsm.CoordinateSeed(p) } @@ -522,7 +516,6 @@ func monitor(run Runner, content []interface{}) (coverage Coverage, err error, i } }() t := NewT("fuzzing") - // Ensuring the immutability of content copied := make([]interface{}, len(content)) for i, v := range content { @@ -537,7 +530,6 @@ func monitor(run Runner, content []interface{}) (coverage Coverage, err error, i // TODO: It's just pshedo-covrage of some function coverage = Get_Coverage_of_runner(t, content) - // println(string(t.output)) return coverage, err, isPanic, panicMsg } diff --git a/gnovm/stdlibs/testing/genom_algorythm.gno b/gnovm/stdlibs/testing/genetic_algorythm.gno similarity index 97% rename from gnovm/stdlibs/testing/genom_algorythm.gno rename to gnovm/stdlibs/testing/genetic_algorythm.gno index 2f9a53b942f..25715ebdb3b 100644 --- a/gnovm/stdlibs/testing/genom_algorythm.gno +++ b/gnovm/stdlibs/testing/genetic_algorythm.gno @@ -35,6 +35,8 @@ func Mutate(seed Seed, mut_range int) Seed { case bool: seed.Content[index] = randomBool() // Cancellation due to value set issue + // As in the comment code below, the spread in implementation does not cover all string values. + // This is the description of the logic that deals with strings as bytes. // case string: // runes := []rune(v) // if len(runes) > 0 { @@ -161,17 +163,16 @@ func InsertDelete(seed Seed, p float64, mut_range int, string_byte_candidates [] // I deleted the existing fit, fitness. // As I tried to increase the speed by integrating into AFL, I decided that it was faster to manage it with just queue, stack, and unique linked list. -// (Something gets uncomfortable if you follow the afl logic I've seen and maintain that fitness management.) +// (Something gets uncomfortable if follow the afl logic I've seen and maintain that fitness management.) // Fitness and selection logic are replaced. -// Modified existing mating logic. -// I adjusted the number according to gen to solve the sticking problem. +// Modified existing crossover logic. +// I adjusted the number according to gen to solve the sticking problem.(a phenomenon in which they become similar as inputs increase) // Changed to multi-intersection logic. func TwoPointCrossover(parent1, parent2 Seed, seedCount *uint) (Seed, Seed) { - // 깊은 복사를 위해 새로운 슬라이스 생성 content1 := make([]interface{}, len(parent1.Content)) for i, v := range parent1.Content { - content1[i] = v // 안전하게 string으로 캐스팅 + content1[i] = v } content2 := make([]interface{}, len(parent2.Content)) for i, v := range parent2.Content { @@ -243,17 +244,6 @@ func TwoPointCrossover(parent1, parent2 Seed, seedCount *uint) (Seed, Seed) { content1[i] = result_byt1 content2[i] = result_byt2 case string: - // t1 := tokenizeString(v1) - // v2, ok := parent2.Content[i].(string) - // if !ok { - // panic("type not equal") - // } - // t2 := tokenizeString(v2) - - // c1, c2 := twoPointCrossoverTokens(t1, t2) - // result_str1 := rebuildString(c1) - // result_str2 := rebuildString(c2) - byt1 := v1 byt2, ok := parent2.Content[i].(string) if !ok { @@ -406,7 +396,7 @@ func Evolve(seeds []Seed, seedCount *uint, string_byte_candidates []int) []Seed // 40% range if randSeed <= 3 { - new_generation[i] = Mutate(new_generation[i], mutation_range) // 원본 데이터 수정 + new_generation[i] = Mutate(new_generation[i], mutation_range) } // 30%range and 10% intersection if randSeed >= 3 && randSeed <= 5 { diff --git a/gnovm/stdlibs/testing/random.gno b/gnovm/stdlibs/testing/random.gno index 54da4f156a4..5a4869ce079 100644 --- a/gnovm/stdlibs/testing/random.gno +++ b/gnovm/stdlibs/testing/random.gno @@ -39,7 +39,7 @@ func NewCustomSource(seed int64) *CustomSource { func GetSingleRand() *rand.Rand { if !isCalled { isCalled = true - seed := unixNano() // 동적 시드 설정 + seed := unixNano() source := NewCustomSource(seed) singleRand = rand.New(source) @@ -63,7 +63,6 @@ func UniformRand() uint64 { // _srand function sets the seed for the random number generator. // This function provides an initial starting point for the sequence of random numbers. -// 고쳤습니다. func _srand() { r := GetSingleRand() x = uint64(r.Uint64()) diff --git a/gnovm/stdlibs/testing/random_test.gno b/gnovm/stdlibs/testing/random_test.gno index 9363d67df86..bdea3a663ae 100644 --- a/gnovm/stdlibs/testing/random_test.gno +++ b/gnovm/stdlibs/testing/random_test.gno @@ -66,7 +66,10 @@ func Test_GenerateRandomBool(t *T) { falseCount++ } } - //? This is also a question. Why do you write a test case like this? + //? question. Why do you write a test case like this? + // If the bias is 0,1, most of them will fail the test. + // However, this is still a phenomenon that happens even if it is implemented correctly. + //I would like to know why you wrote the test case like this. if trueCount == 0 || falseCount == 0 { t.Errorf("Bias = %v, trueCount = %v, falseCount = %v, want both > 0", bias, trueCount, falseCount) } @@ -93,11 +96,6 @@ func TestRandRange(t *T) { } } - // if len(nums) != 11 { - //? I modified it because the teke was weird. I think it should be 10. - // for num, count := range nums { - // t.Errorf("Number %d: %d times\n", num, count) - // } if len(nums) != 10 { t.Errorf("len(nums) = %v, want in range [0, 10]", len(nums)) } diff --git a/gnovm/stdlibs/testing/state_machine.gno b/gnovm/stdlibs/testing/state_machine.gno index 2374052ef10..634c3858aad 100644 --- a/gnovm/stdlibs/testing/state_machine.gno +++ b/gnovm/stdlibs/testing/state_machine.gno @@ -101,9 +101,9 @@ type EndInfo struct { func (sm *StateMachine) CoordinateAbstraction(hn HashNumber, abstract_number uint) EndInfo { sm.Input_count = sm.Input_count + abstract_number - // 현재의 priort를 알아올 수 있음 - // 1. prior는 불연속 증가함 - // 2. hn는 반드시 연속 증가함 + // Get current priorty + // 1. Prior increases discontinuously + // 2. Hn must increase continuously sm.HashNumber2Priority[hn] = sm.HashNumber2Priority[hn] + abstract_number next_priority := sm.HashNumber2Priority[hn] next_hn := hn @@ -262,7 +262,7 @@ func (sm *StateMachine) Summarize() []Seed { Priority: e, HashNumber: i, }) - // 슬라이스 길이가 Partial_Capacity를를 초과하면 종료 + // Exit when slice length exceeds Partial_Capacity if len(collected_P_HN_Pair) >= int(Partial_Capacity) { break } diff --git a/gnovm/stdlibs/testing/testing.gno b/gnovm/stdlibs/testing/testing.gno index 32c2a0cbded..da6a4623bdc 100644 --- a/gnovm/stdlibs/testing/testing.gno +++ b/gnovm/stdlibs/testing/testing.gno @@ -307,7 +307,6 @@ func (t *T) shouldRun(name string) bool { } func RunTest(runFlag string, verbose bool, test InternalTest) (ret string) { - // func RunTest(runFlag string, verbose bool, test InternalTest) (ret string) { t := &T{ name: test.Name, verbose: verbose, diff --git a/gnovm/stdlibs/testing/to_string.gno b/gnovm/stdlibs/testing/to_string.gno index 43283ecb960..bc1855c8791 100644 --- a/gnovm/stdlibs/testing/to_string.gno +++ b/gnovm/stdlibs/testing/to_string.gno @@ -70,6 +70,7 @@ func byteToHex(b byte) []byte { return []byte{hi, lo} } +// Recover what the escape characters break when they are printed. (e.g."�" -> "\xeb") func TransForHuman(s string) string { toks := TokenizeString(s) escaped := RebuildEscaped(toks)