From ef328dbb6ef3c44bba43189e7d53b8df1394ffd2 Mon Sep 17 00:00:00 2001 From: Zhang Zhuo Date: Thu, 31 Aug 2023 10:33:31 +0800 Subject: [PATCH] =?UTF-8?q?fix(modexp):=20disallow=20len=20of=200x80000000?= =?UTF-8?q?00000000000000000000000000000000000=E2=80=A6=20(#496)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * modexp: disallow len of 0x8000000000000000000000000000000000000000000000000000000000000000 * minor --------- Co-authored-by: HAOYUatHZ --- core/vm/contracts.go | 14 ++++++++++---- params/version.go | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/core/vm/contracts.go b/core/vm/contracts.go index 539d34388a..278746e02c 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -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 { diff --git a/params/version.go b/params/version.go index 0802f41b38..f525aa1228 100644 --- a/params/version.go +++ b/params/version.go @@ -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 )