forked from cerc-io/plugeth
core/vm: use golang native big.Int (#26834)
reverts #26021, to use the upstream bigint instead.
This commit is contained in:
parent
e14043db71
commit
b80f05bde2
File diff suppressed because one or more lines are too long
@ -29,7 +29,6 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/crypto/bls12381"
|
"github.com/ethereum/go-ethereum/crypto/bls12381"
|
||||||
"github.com/ethereum/go-ethereum/crypto/bn256"
|
"github.com/ethereum/go-ethereum/crypto/bn256"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
big2 "github.com/holiman/big"
|
|
||||||
"golang.org/x/crypto/ripemd160"
|
"golang.org/x/crypto/ripemd160"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -378,9 +377,9 @@ func (c *bigModExp) Run(input []byte) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
// Retrieve the operands and execute the exponentiation
|
// Retrieve the operands and execute the exponentiation
|
||||||
var (
|
var (
|
||||||
base = new(big2.Int).SetBytes(getData(input, 0, baseLen))
|
base = new(big.Int).SetBytes(getData(input, 0, baseLen))
|
||||||
exp = new(big2.Int).SetBytes(getData(input, baseLen, expLen))
|
exp = new(big.Int).SetBytes(getData(input, baseLen, expLen))
|
||||||
mod = new(big2.Int).SetBytes(getData(input, baseLen+expLen, modLen))
|
mod = new(big.Int).SetBytes(getData(input, baseLen+expLen, modLen))
|
||||||
v []byte
|
v []byte
|
||||||
)
|
)
|
||||||
switch {
|
switch {
|
||||||
|
3
go.mod
3
go.mod
@ -35,7 +35,6 @@ require (
|
|||||||
github.com/gorilla/websocket v1.4.2
|
github.com/gorilla/websocket v1.4.2
|
||||||
github.com/graph-gophers/graphql-go v1.3.0
|
github.com/graph-gophers/graphql-go v1.3.0
|
||||||
github.com/hashicorp/go-bexpr v0.1.10
|
github.com/hashicorp/go-bexpr v0.1.10
|
||||||
github.com/holiman/big v0.0.0-20221017200358-a027dc42d04e
|
|
||||||
github.com/holiman/bloomfilter/v2 v2.0.3
|
github.com/holiman/bloomfilter/v2 v2.0.3
|
||||||
github.com/holiman/uint256 v1.2.0
|
github.com/holiman/uint256 v1.2.0
|
||||||
github.com/huin/goupnp v1.0.3
|
github.com/huin/goupnp v1.0.3
|
||||||
@ -45,6 +44,7 @@ require (
|
|||||||
github.com/jedisct1/go-minisign v0.0.0-20190909160543-45766022959e
|
github.com/jedisct1/go-minisign v0.0.0-20190909160543-45766022959e
|
||||||
github.com/julienschmidt/httprouter v1.3.0
|
github.com/julienschmidt/httprouter v1.3.0
|
||||||
github.com/karalabe/usb v0.0.2
|
github.com/karalabe/usb v0.0.2
|
||||||
|
github.com/kylelemons/godebug v1.1.0
|
||||||
github.com/mattn/go-colorable v0.1.13
|
github.com/mattn/go-colorable v0.1.13
|
||||||
github.com/mattn/go-isatty v0.0.16
|
github.com/mattn/go-isatty v0.0.16
|
||||||
github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416
|
github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416
|
||||||
@ -98,7 +98,6 @@ require (
|
|||||||
github.com/klauspost/compress v1.15.15 // indirect
|
github.com/klauspost/compress v1.15.15 // indirect
|
||||||
github.com/kr/pretty v0.3.1 // indirect
|
github.com/kr/pretty v0.3.1 // indirect
|
||||||
github.com/kr/text v0.2.0 // indirect
|
github.com/kr/text v0.2.0 // indirect
|
||||||
github.com/kylelemons/godebug v1.1.0 // indirect
|
|
||||||
github.com/mattn/go-runewidth v0.0.9 // indirect
|
github.com/mattn/go-runewidth v0.0.9 // indirect
|
||||||
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
|
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
|
||||||
github.com/mitchellh/mapstructure v1.4.1 // indirect
|
github.com/mitchellh/mapstructure v1.4.1 // indirect
|
||||||
|
2
go.sum
2
go.sum
@ -293,8 +293,6 @@ github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09
|
|||||||
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||||
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||||
github.com/holiman/big v0.0.0-20221017200358-a027dc42d04e h1:pIYdhNkDh+YENVNi3gto8n9hAmRxKxoar0iE6BLucjw=
|
|
||||||
github.com/holiman/big v0.0.0-20221017200358-a027dc42d04e/go.mod h1:j9cQbcqHQujT0oKJ38PylVfqohClLr3CvDC+Qcg+lhU=
|
|
||||||
github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao=
|
github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao=
|
||||||
github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA=
|
github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA=
|
||||||
github.com/holiman/uint256 v1.2.0 h1:gpSYcPLWGv4sG43I2mVLiDZCNDh/EpGjSk8tmtxitHM=
|
github.com/holiman/uint256 v1.2.0 h1:gpSYcPLWGv4sG43I2mVLiDZCNDh/EpGjSk8tmtxitHM=
|
||||||
|
@ -125,7 +125,5 @@ compile_fuzzer tests/fuzzers/snap FuzzSRange fuzz_storage_range
|
|||||||
compile_fuzzer tests/fuzzers/snap FuzzByteCodes fuzz_byte_codes
|
compile_fuzzer tests/fuzzers/snap FuzzByteCodes fuzz_byte_codes
|
||||||
compile_fuzzer tests/fuzzers/snap FuzzTrieNodes fuzz_trie_nodes
|
compile_fuzzer tests/fuzzers/snap FuzzTrieNodes fuzz_trie_nodes
|
||||||
|
|
||||||
compile_fuzzer tests/fuzzers/modexp Fuzz fuzzModexp
|
|
||||||
|
|
||||||
#TODO: move this to tests/fuzzers, if possible
|
#TODO: move this to tests/fuzzers, if possible
|
||||||
compile_fuzzer crypto/blake2b Fuzz fuzzBlake2b
|
compile_fuzzer crypto/blake2b Fuzz fuzzBlake2b
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
// Copyright 2020 The go-ethereum Authors
|
|
||||||
// This file is part of the go-ethereum library.
|
|
||||||
//
|
|
||||||
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Lesser General Public License for more details.
|
|
||||||
//
|
|
||||||
// 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/>.
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/tests/fuzzers/modexp"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
if len(os.Args) != 2 {
|
|
||||||
fmt.Fprintf(os.Stderr, "Usage: debug <file>\n")
|
|
||||||
fmt.Fprintf(os.Stderr, "Example\n")
|
|
||||||
fmt.Fprintf(os.Stderr, " $ debug ../crashers/4bbef6857c733a87ecf6fd8b9e7238f65eb9862a\n")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
crasher := os.Args[1]
|
|
||||||
data, err := os.ReadFile(crasher)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "error loading crasher %v: %v", crasher, err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
modexp.Fuzz(data)
|
|
||||||
}
|
|
@ -1,90 +0,0 @@
|
|||||||
// Copyright 2022 The go-ethereum Authors
|
|
||||||
// This file is part of the go-ethereum library.
|
|
||||||
//
|
|
||||||
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Lesser General Public License for more details.
|
|
||||||
//
|
|
||||||
// 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/>.
|
|
||||||
|
|
||||||
package modexp
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"math/big"
|
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
|
||||||
"github.com/ethereum/go-ethereum/core/vm"
|
|
||||||
big2 "github.com/holiman/big"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Fuzz is the fuzzing entry-point.
|
|
||||||
// The function must return
|
|
||||||
//
|
|
||||||
// - 1 if the fuzzer should increase priority of the
|
|
||||||
// given input during subsequent fuzzing (for example, the input is lexically
|
|
||||||
// correct and was parsed successfully);
|
|
||||||
// - -1 if the input must not be added to corpus even if gives new coverage; and
|
|
||||||
// - 0 otherwise
|
|
||||||
//
|
|
||||||
// other values are reserved for future use.
|
|
||||||
func Fuzz(input []byte) int {
|
|
||||||
if len(input) <= 96 {
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
// Abort on too expensive inputs
|
|
||||||
precomp := vm.PrecompiledContractsBerlin[common.BytesToAddress([]byte{5})]
|
|
||||||
if gas := precomp.RequiredGas(input); gas > 40_000_000 {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
var (
|
|
||||||
baseLen = new(big.Int).SetBytes(getData(input, 0, 32)).Uint64()
|
|
||||||
expLen = new(big.Int).SetBytes(getData(input, 32, 32)).Uint64()
|
|
||||||
modLen = new(big.Int).SetBytes(getData(input, 64, 32)).Uint64()
|
|
||||||
)
|
|
||||||
// Handle a special case when both the base and mod length is zero
|
|
||||||
if baseLen == 0 && modLen == 0 {
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
input = input[96:]
|
|
||||||
// Retrieve the operands and execute the exponentiation
|
|
||||||
var (
|
|
||||||
base = new(big.Int).SetBytes(getData(input, 0, baseLen))
|
|
||||||
exp = new(big.Int).SetBytes(getData(input, baseLen, expLen))
|
|
||||||
mod = new(big.Int).SetBytes(getData(input, baseLen+expLen, modLen))
|
|
||||||
base2 = new(big2.Int).SetBytes(getData(input, 0, baseLen))
|
|
||||||
exp2 = new(big2.Int).SetBytes(getData(input, baseLen, expLen))
|
|
||||||
mod2 = new(big2.Int).SetBytes(getData(input, baseLen+expLen, modLen))
|
|
||||||
)
|
|
||||||
if mod.BitLen() == 0 {
|
|
||||||
// Modulo 0 is undefined, return zero
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
var a = new(big2.Int).Exp(base2, exp2, mod2).String()
|
|
||||||
var b = new(big.Int).Exp(base, exp, mod).String()
|
|
||||||
if a != b {
|
|
||||||
panic(fmt.Sprintf("Inequality %#x ^ %#x mod %#x \n have %s\n want %s", base, exp, mod, a, b))
|
|
||||||
}
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
// getData returns a slice from the data based on the start and size and pads
|
|
||||||
// up to size with zero's. This function is overflow safe.
|
|
||||||
func getData(data []byte, start uint64, size uint64) []byte {
|
|
||||||
length := uint64(len(data))
|
|
||||||
if start > length {
|
|
||||||
start = length
|
|
||||||
}
|
|
||||||
end := start + size
|
|
||||||
if end > length {
|
|
||||||
end = length
|
|
||||||
}
|
|
||||||
return common.RightPadBytes(data[start:end], int(size))
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user