feat(core/vm): modexp precompiled support also less than 32-bytes inputs (#393)

* modexp support 32-bytes or less inputs

* change revert string

* bump version

---------

Co-authored-by: Péter Garamvölgyi <peter@scroll.io>
This commit is contained in:
Nazarii Denha 2023-07-10 16:04:14 +02:00 committed by GitHub
parent 2dcc60a082
commit 5eac3a73bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 38 additions and 20 deletions

View file

@ -36,7 +36,7 @@ import (
var (
errPrecompileDisabled = errors.New("sha256, ripemd160, blake2f precompiles temporarily disabled")
errModexpUnsupportedInput = errors.New("modexp temporarily accepts only 32-byte (256-bit) inputs")
errModexpUnsupportedInput = errors.New("modexp temporarily only accepts inputs of 32 bytes (256 bits) or less")
)
// PrecompiledContract is the basic interface for native Go contracts. The implementation
@ -411,8 +411,8 @@ func (c *bigModExp) Run(input []byte) ([]byte, error) {
expLen = new(big.Int).SetBytes(getData(input, 32, 32)).Uint64()
modLen = new(big.Int).SetBytes(getData(input, 64, 32)).Uint64()
)
// Check that all inputs are `u256` (32 - bytes), revert otherwise
if baseLen != 32 || expLen != 32 || modLen != 32 {
// Check that all inputs are `u256` (32 - bytes) or less, revert otherwise
if baseLen > 32 || expLen > 32 || modLen > 32 {
return nil, errModexpUnsupportedInput
}
if len(input) > 96 {

View file

@ -1,12 +1,7 @@
[
{
"Input": "000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020",
"ExpectedError": "modexp temporarily accepts only 32-byte (256-bit) inputs",
"Name": "too small input"
},
{
"Input": "000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000020",
"ExpectedError": "modexp temporarily accepts only 32-byte (256-bit) inputs",
"ExpectedError": "modexp temporarily only accepts inputs of 32 bytes (256 bits) or less",
"Name": "too big input"
}
]

View file

@ -1,12 +1,7 @@
[
{
"Input": "000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020",
"ExpectedError": "modexp temporarily accepts only 32-byte (256-bit) inputs",
"Name": "too small input"
},
{
"Input": "000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000020",
"ExpectedError": "modexp temporarily accepts only 32-byte (256-bit) inputs",
"ExpectedError": "modexp temporarily only accepts inputs of 32 bytes (256 bits) or less",
"Name": "too big input"
}
]

View file

@ -1,16 +1,30 @@
[
{
"Input": "0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2efffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f",
"Input": "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002003fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2efffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f",
"Expected": "0000000000000000000000000000000000000000000000000000000000000001",
"Name": "eip_example1",
"Gas": 13056,
"NoBenchmark": false
},
{
"Input": "0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2efffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f",
"Input": "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2efffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f",
"Expected": "0000000000000000000000000000000000000000000000000000000000000000",
"Name": "eip_example2",
"Gas": 13056,
"NoBenchmark": false
},
{
"Input": "0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2efffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f",
"Expected": "0000000000000000000000000000000000000000000000000000000000000001",
"Name": "eip_example3",
"Gas": 13056,
"NoBenchmark": false
},
{
"Input": "0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2efffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f",
"Expected": "0000000000000000000000000000000000000000000000000000000000000000",
"Name": "eip_example4",
"Gas": 13056,
"NoBenchmark": false
}
]

View file

@ -1,16 +1,30 @@
[
{
"Input": "0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2efffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f",
"Input": "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002003fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2efffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f",
"Expected": "0000000000000000000000000000000000000000000000000000000000000001",
"Name": "eip_example1",
"Gas": 1360,
"NoBenchmark": false
},
{
"Input": "0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2efffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f",
"Input": "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2efffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f",
"Expected": "0000000000000000000000000000000000000000000000000000000000000000",
"Name": "eip_example2",
"Gas": 1360,
"NoBenchmark": false
},
{
"Input": "0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2efffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f",
"Expected": "0000000000000000000000000000000000000000000000000000000000000001",
"Name": "eip_example3",
"Gas": 1360,
"NoBenchmark": false
},
{
"Input": "0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2efffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f",
"Expected": "0000000000000000000000000000000000000000000000000000000000000000",
"Name": "eip_example4",
"Gas": 1360,
"NoBenchmark": false
}
]

View file

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