core/vm: optimize bigModExp using uint256.Int.SetBytes32

This commit is contained in:
cuiweixie 2025-10-19 09:27:36 +08:00
parent 0ec63272bf
commit 63a8bcfa97
No known key found for this signature in database
GPG key ID: 16DF64EE15E495A3

View file

@ -560,9 +560,9 @@ func osakaModexpGas(baseLen, expLen, modLen uint64, expHead uint256.Int) uint64
// RequiredGas returns the gas required to execute the pre-compiled contract.
func (c *bigModExp) RequiredGas(input []byte) uint64 {
// Parse input lengths
baseLenBig := new(uint256.Int).SetBytes(getData(input, 0, 32))
expLenBig := new(uint256.Int).SetBytes(getData(input, 32, 32))
modLenBig := new(uint256.Int).SetBytes(getData(input, 64, 32))
baseLenBig := new(uint256.Int).SetBytes32(getData(input, 0, 32))
expLenBig := new(uint256.Int).SetBytes32(getData(input, 32, 32))
modLenBig := new(uint256.Int).SetBytes32(getData(input, 64, 32))
// Convert to uint64, capping at max value
baseLen := baseLenBig.Uint64()
@ -589,7 +589,7 @@ func (c *bigModExp) RequiredGas(input []byte) uint64 {
var expHead uint256.Int
if uint64(len(input)) > baseLen {
if expLen > 32 {
expHead.SetBytes(getData(input, baseLen, 32))
expHead.SetBytes32(getData(input, baseLen, 32))
} else {
// TODO: Check that if expLen < baseLen, then getData will return an empty slice
expHead.SetBytes(getData(input, baseLen, expLen))