github.com/sberex/go-sberex@v1.8.2-0.20181113200658-ed96ac38f7d7/core/vm/runtime/fuzz.go (about)

     1  // This file is part of the go-sberex library. The go-sberex library is 
     2  // free software: you can redistribute it and/or modify it under the terms 
     3  // of the GNU Lesser General Public License as published by the Free 
     4  // Software Foundation, either version 3 of the License, or (at your option)
     5  // any later version.
     6  //
     7  // The go-sberex library is distributed in the hope that it will be useful, 
     8  // but WITHOUT ANY WARRANTY; without even the implied warranty of
     9  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 
    10  // General Public License <http://www.gnu.org/licenses/> for more details.
    11  
    12  // +build gofuzz
    13  
    14  package runtime
    15  
    16  // Fuzz is the basic entry point for the go-fuzz tool
    17  //
    18  // This returns 1 for valid parsable/runable code, 0
    19  // for invalid opcode.
    20  func Fuzz(input []byte) int {
    21  	_, _, err := Execute(input, input, &Config{
    22  		GasLimit: 3000000,
    23  	})
    24  
    25  	// invalid opcode
    26  	if err != nil && len(err.Error()) > 6 && string(err.Error()[:7]) == "invalid" {
    27  		return 0
    28  	}
    29  
    30  	return 1
    31  }