mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-21 22:24:32 +00:00
common, crypto: move fuzzers out of core (#22029)
This commit is contained in:
parent
96f5876896
commit
4f9501f12c
3 changed files with 17 additions and 17 deletions
|
|
@ -14,11 +14,13 @@
|
|||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
// +build gofuzz
|
||||
|
||||
package bitutil
|
||||
|
||||
import "bytes"
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/XinFinOrg/XDPoSChain/common/bitutil"
|
||||
)
|
||||
|
||||
// Fuzz implements a go-fuzz fuzzer method to test various encoding method
|
||||
// invocations.
|
||||
|
|
@ -35,7 +37,7 @@ func Fuzz(data []byte) int {
|
|||
// fuzzEncode implements a go-fuzz fuzzer method to test the bitset encoding and
|
||||
// decoding algorithm.
|
||||
func fuzzEncode(data []byte) int {
|
||||
proc, _ := bitsetDecodeBytes(bitsetEncodeBytes(data), len(data))
|
||||
proc, _ := bitutil.DecompressBytes(bitutil.CompressBytes(data), len(data))
|
||||
if !bytes.Equal(data, proc) {
|
||||
panic("content mismatch")
|
||||
}
|
||||
|
|
@ -45,11 +47,11 @@ func fuzzEncode(data []byte) int {
|
|||
// fuzzDecode implements a go-fuzz fuzzer method to test the bit decoding and
|
||||
// reencoding algorithm.
|
||||
func fuzzDecode(data []byte) int {
|
||||
blob, err := bitsetDecodeBytes(data, 1024)
|
||||
blob, err := bitutil.DecompressBytes(data, 1024)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
if comp := bitsetEncodeBytes(blob); !bytes.Equal(comp, data) {
|
||||
if comp := bitutil.CompressBytes(blob); !bytes.Equal(comp, data) {
|
||||
panic("content mismatch")
|
||||
}
|
||||
return 1
|
||||
|
|
@ -14,8 +14,6 @@
|
|||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
// +build gofuzz
|
||||
|
||||
package bn256
|
||||
|
||||
import (
|
||||
|
|
@ -36,7 +34,7 @@ func getG1Points(input io.Reader) (*cloudflare.G1, *google.G1) {
|
|||
}
|
||||
xg := new(google.G1)
|
||||
if _, err := xg.Unmarshal(xc.Marshal()); err != nil {
|
||||
panic(fmt.Sprintf("Could not marshal cloudflare -> google:", err))
|
||||
panic(fmt.Sprintf("Could not marshal cloudflare -> google: %v", err))
|
||||
}
|
||||
return xc, xg
|
||||
}
|
||||
|
|
@ -49,7 +47,7 @@ func getG2Points(input io.Reader) (*cloudflare.G2, *google.G2) {
|
|||
}
|
||||
xg := new(google.G2)
|
||||
if _, err := xg.Unmarshal(xc.Marshal()); err != nil {
|
||||
panic(fmt.Sprintf("Could not marshal cloudflare -> google:", err))
|
||||
panic(fmt.Sprintf("Could not marshal cloudflare -> google: %v", err))
|
||||
}
|
||||
return xc, xg
|
||||
}
|
||||
|
|
@ -14,23 +14,23 @@
|
|||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
// +build gofuzz
|
||||
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"github.com/XinFinOrg/XDPoSChain/core/vm/runtime"
|
||||
)
|
||||
|
||||
// Fuzz is the basic entry point for the go-fuzz tool
|
||||
//
|
||||
// This returns 1 for valid parsable/runable code, 0
|
||||
// for invalid opcode.
|
||||
func Fuzz(input []byte) int {
|
||||
_, _, err := Execute(input, input, &Config{
|
||||
GasLimit: 3000000,
|
||||
_, _, err := runtime.Execute(input, input, &runtime.Config{
|
||||
GasLimit: 12000000,
|
||||
})
|
||||
|
||||
// invalid opcode
|
||||
if err != nil && len(err.Error()) > 6 && string(err.Error()[:7]) == "invalid" {
|
||||
if err != nil && len(err.Error()) > 6 && err.Error()[:7] == "invalid" {
|
||||
return 0
|
||||
}
|
||||
|
||||
return 1
|
||||
}
|
||||
Loading…
Reference in a new issue