Skip to content

Commit

Permalink
fix(gnovm): add fuzz cli and delete pkg/mod files
Browse files Browse the repository at this point in the history
  • Loading branch information
rlaau committed Jan 7, 2025
1 parent c6d9618 commit 436478c
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 42 deletions.
4 changes: 0 additions & 4 deletions gnovm/stdlibs/testing/crash_logger.gno
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
Expand Down
8 changes: 0 additions & 8 deletions gnovm/stdlibs/testing/fuzz.gno
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -226,20 +224,17 @@ 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 {
return true
}
} else {
absNumber := absSeedInfo.abstractNumber - 2
// println("hashNumber", hn, ":", absNumber+2)
absEndInfo := f.fsm.CoordinateAbstraction(hn, absNumber)
flag := f.handleEndInfo(absEndInfo, parentSeeds)
if flag {
Expand All @@ -258,7 +253,6 @@ func (f *F) updateMachines(parentSeeds []Seed) bool {
}

}
// println("iters!")
for _, p := range parentSeeds {
f.fsm.CoordinateSeed(p)
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions gnovm/stdlibs/testing/random.gno
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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())
Expand Down
10 changes: 4 additions & 6 deletions gnovm/stdlibs/testing/random_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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))
}
Expand Down
8 changes: 4 additions & 4 deletions gnovm/stdlibs/testing/state_machine.gno
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
1 change: 0 additions & 1 deletion gnovm/stdlibs/testing/testing.gno
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions gnovm/stdlibs/testing/to_string.gno
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 436478c

Please sign in to comment.