fix(modexp): disallow len of 0x8000000000000000000000000000000000000000000… (#496)

* modexp: disallow len of 0x8000000000000000000000000000000000000000000000000000000000000000

* minor

---------

Co-authored-by: HAOYUatHZ <haoyu@protonmail.com>
This commit is contained in:
Zhang Zhuo 2023-08-31 10:33:31 +08:00 committed by GitHub
parent 63cbb77cdc
commit ef328dbb6e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

View file

@ -407,12 +407,18 @@ func (c *bigModExp) RequiredGas(input []byte) uint64 {
func (c *bigModExp) Run(input []byte) ([]byte, error) {
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()
baseLenBigInt = new(big.Int).SetBytes(getData(input, 0, 32))
expLenBigInt = new(big.Int).SetBytes(getData(input, 32, 32))
modLenBigInt = new(big.Int).SetBytes(getData(input, 64, 32))
)
var (
baseLen = baseLenBigInt.Uint64()
expLen = expLenBigInt.Uint64()
modLen = modLenBigInt.Uint64()
)
// Check that all inputs are `u256` (32 - bytes) or less, revert otherwise
if baseLen > 32 || expLen > 32 || modLen > 32 {
var lenLimit = new(big.Int).SetInt64(32)
if baseLenBigInt.Cmp(lenLimit) > 0 || expLenBigInt.Cmp(lenLimit) > 0 || modLenBigInt.Cmp(lenLimit) > 0 {
return nil, errModexpUnsupportedInput
}
if len(input) > 96 {

View file

@ -24,7 +24,7 @@ import (
const (
VersionMajor = 4 // Major version component of the current release
VersionMinor = 3 // Minor version component of the current release
VersionPatch = 57 // Patch version component of the current release
VersionPatch = 58 // Patch version component of the current release
VersionMeta = "sepolia" // Version metadata to append to the version string
)