From 63a8bcfa973f95ac506b9634d60a9fa742d40f07 Mon Sep 17 00:00:00 2001 From: cuiweixie Date: Sun, 19 Oct 2025 09:27:36 +0800 Subject: [PATCH] core/vm: optimize bigModExp using uint256.Int.SetBytes32 --- core/vm/contracts.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/vm/contracts.go b/core/vm/contracts.go index cae0be9f2d..37f7e23529 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -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))