Skip to content

Commit

Permalink
logic change to mod exp revert rules
Browse files Browse the repository at this point in the history
  • Loading branch information
hexoscott committed Oct 31, 2024
1 parent e60a53f commit b1bc392
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions core/vm/contracts_zkevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,22 +389,31 @@ func (c *bigModExp_zkevm) Run(input []byte) ([]byte, error) {
} else {
input = input[:0]
}
// Handle a special case when both the base and mod length is zero
if baseLen == 0 && modLen == 0 {

if modLen == 0 {
return []byte{}, nil
}

// 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))
v []byte
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))
v []byte
baseBitLen = base.BitLen()
expBitLen = exp.BitLen()
modBitLen = mod.BitLen()
)

if baseBitLen == 0 {
if modBitLen > 8192 {
return nil, ErrExecutionReverted
} else {
return []byte{}, nil
}
}

// limit to 8192 bits for base, exp, and mod in ZK
baseBitLen := base.BitLen()
expBitLen := exp.BitLen()
modBitLen := mod.BitLen()
if baseBitLen > 8192 || expBitLen > 8192 || modBitLen > 8192 {
return nil, ErrExecutionReverted
}
Expand Down

0 comments on commit b1bc392

Please sign in to comment.