move input size cap enforcement before input loading

This commit is contained in:
Jared Wasinger 2025-05-29 21:21:27 +08:00
parent abe1b884b6
commit e7d7126433

View file

@ -481,6 +481,10 @@ func (c *bigModExp) Run(input []byte) ([]byte, error) {
if baseLen == 0 && modLen == 0 {
return []byte{}, nil
}
// enforce size cap for inputs
if c.eip7823 && max(max(baseLen, expLen), max(baseLen, modLen)) > 1024 {
return nil, fmt.Errorf("one or more of base/exponent/modulus length exceeded 1024 bytes")
}
// Retrieve the operands and execute the exponentiation
var (
base = new(big.Int).SetBytes(getData(input, 0, baseLen))
@ -488,9 +492,6 @@ func (c *bigModExp) Run(input []byte) ([]byte, error) {
mod = new(big.Int).SetBytes(getData(input, baseLen+expLen, modLen))
v []byte
)
if c.eip7823 && max(max(baseLen, expLen), modLen) > 1024 {
return nil, fmt.Errorf("one or more of base/exponent/modulus length exceeded 1024 bytes")
}
switch {
case mod.BitLen() == 0:
// Modulo 0 is undefined, return zero