vm: inline minStack/minDupStack/minSwapStack and delete unused functions

This commit is contained in:
Sahil-4555 2025-11-27 10:04:21 +05:30
parent 6452b7ad05
commit 4b3fdbbae7
3 changed files with 172 additions and 181 deletions

View file

@ -85,7 +85,7 @@ func enable1884(jt *JumpTable) {
jt[SELFBALANCE] = &operation{ jt[SELFBALANCE] = &operation{
execute: opSelfBalance, execute: opSelfBalance,
constantGas: GasFastStep, constantGas: GasFastStep,
minStack: minStack(0, 1), minStack: 0,
maxStack: maxStack(0, 1), maxStack: maxStack(0, 1),
} }
} }
@ -103,7 +103,7 @@ func enable1344(jt *JumpTable) {
jt[CHAINID] = &operation{ jt[CHAINID] = &operation{
execute: opChainID, execute: opChainID,
constantGas: GasQuickStep, constantGas: GasQuickStep,
minStack: minStack(0, 1), minStack: 0,
maxStack: maxStack(0, 1), maxStack: maxStack(0, 1),
} }
} }
@ -175,7 +175,7 @@ func enable3198(jt *JumpTable) {
jt[BASEFEE] = &operation{ jt[BASEFEE] = &operation{
execute: opBaseFee, execute: opBaseFee,
constantGas: GasQuickStep, constantGas: GasQuickStep,
minStack: minStack(0, 1), minStack: 0,
maxStack: maxStack(0, 1), maxStack: maxStack(0, 1),
} }
} }
@ -187,14 +187,14 @@ func enable1153(jt *JumpTable) {
jt[TLOAD] = &operation{ jt[TLOAD] = &operation{
execute: opTload, execute: opTload,
constantGas: params.WarmStorageReadCostEIP2929, constantGas: params.WarmStorageReadCostEIP2929,
minStack: minStack(1, 1), minStack: 1,
maxStack: maxStack(1, 1), maxStack: maxStack(1, 1),
} }
jt[TSTORE] = &operation{ jt[TSTORE] = &operation{
execute: opTstore, execute: opTstore,
constantGas: params.WarmStorageReadCostEIP2929, constantGas: params.WarmStorageReadCostEIP2929,
minStack: minStack(2, 0), minStack: 2,
maxStack: maxStack(2, 0), maxStack: maxStack(2, 0),
} }
} }
@ -232,7 +232,7 @@ func enable3855(jt *JumpTable) {
jt[PUSH0] = &operation{ jt[PUSH0] = &operation{
execute: opPush0, execute: opPush0,
constantGas: GasQuickStep, constantGas: GasQuickStep,
minStack: minStack(0, 1), minStack: 0,
maxStack: maxStack(0, 1), maxStack: maxStack(0, 1),
} }
} }
@ -257,7 +257,7 @@ func enable5656(jt *JumpTable) {
execute: opMcopy, execute: opMcopy,
constantGas: GasFastestStep, constantGas: GasFastestStep,
dynamicGas: gasMcopy, dynamicGas: gasMcopy,
minStack: minStack(3, 0), minStack: 3,
maxStack: maxStack(3, 0), maxStack: maxStack(3, 0),
memorySize: memoryMcopy, memorySize: memoryMcopy,
} }
@ -307,7 +307,7 @@ func enable4844(jt *JumpTable) {
jt[BLOBHASH] = &operation{ jt[BLOBHASH] = &operation{
execute: opBlobHash, execute: opBlobHash,
constantGas: GasFastestStep, constantGas: GasFastestStep,
minStack: minStack(1, 1), minStack: 1,
maxStack: maxStack(1, 1), maxStack: maxStack(1, 1),
} }
} }
@ -317,7 +317,7 @@ func enable7939(jt *JumpTable) {
jt[CLZ] = &operation{ jt[CLZ] = &operation{
execute: opCLZ, execute: opCLZ,
constantGas: GasFastStep, constantGas: GasFastStep,
minStack: minStack(1, 1), minStack: 1,
maxStack: maxStack(1, 1), maxStack: maxStack(1, 1),
} }
} }
@ -327,7 +327,7 @@ func enable7516(jt *JumpTable) {
jt[BLOBBASEFEE] = &operation{ jt[BLOBBASEFEE] = &operation{
execute: opBlobBaseFee, execute: opBlobBaseFee,
constantGas: GasQuickStep, constantGas: GasQuickStep,
minStack: minStack(0, 1), minStack: 0,
maxStack: maxStack(0, 1), maxStack: maxStack(0, 1),
} }
} }
@ -338,7 +338,7 @@ func enable6780(jt *JumpTable) {
execute: opSelfdestruct6780, execute: opSelfdestruct6780,
dynamicGas: gasSelfdestructEIP3529, dynamicGas: gasSelfdestructEIP3529,
constantGas: params.SelfdestructGasEIP150, constantGas: params.SelfdestructGasEIP150,
minStack: minStack(1, 0), minStack: 1,
maxStack: maxStack(1, 0), maxStack: maxStack(1, 0),
} }
} }
@ -348,19 +348,19 @@ func enable8024(jt *JumpTable) {
jt[DUPN] = &operation{ jt[DUPN] = &operation{
execute: opDupN, execute: opDupN,
constantGas: GasFastestStep, constantGas: GasFastestStep,
minStack: minStack(1, 0), minStack: 1,
maxStack: maxStack(0, 1), maxStack: maxStack(0, 1),
} }
jt[SWAPN] = &operation{ jt[SWAPN] = &operation{
execute: opSwapN, execute: opSwapN,
constantGas: GasFastestStep, constantGas: GasFastestStep,
minStack: minStack(2, 0), minStack: 2,
maxStack: maxStack(0, 0), maxStack: maxStack(0, 0),
} }
jt[EXCHANGE] = &operation{ jt[EXCHANGE] = &operation{
execute: opExchange, execute: opExchange,
constantGas: GasFastestStep, constantGas: GasFastestStep,
minStack: minStack(2, 0), minStack: 2,
maxStack: maxStack(0, 0), maxStack: maxStack(0, 0),
} }
} }
@ -450,41 +450,41 @@ func enable4762(jt *JumpTable) {
jt[SSTORE] = &operation{ jt[SSTORE] = &operation{
dynamicGas: gasSStore4762, dynamicGas: gasSStore4762,
execute: opSstore, execute: opSstore,
minStack: minStack(2, 0), minStack: 2,
maxStack: maxStack(2, 0), maxStack: maxStack(2, 0),
} }
jt[SLOAD] = &operation{ jt[SLOAD] = &operation{
dynamicGas: gasSLoad4762, dynamicGas: gasSLoad4762,
execute: opSload, execute: opSload,
minStack: minStack(1, 1), minStack: 1,
maxStack: maxStack(1, 1), maxStack: maxStack(1, 1),
} }
jt[BALANCE] = &operation{ jt[BALANCE] = &operation{
execute: opBalance, execute: opBalance,
dynamicGas: gasBalance4762, dynamicGas: gasBalance4762,
minStack: minStack(1, 1), minStack: 1,
maxStack: maxStack(1, 1), maxStack: maxStack(1, 1),
} }
jt[EXTCODESIZE] = &operation{ jt[EXTCODESIZE] = &operation{
execute: opExtCodeSize, execute: opExtCodeSize,
dynamicGas: gasExtCodeSize4762, dynamicGas: gasExtCodeSize4762,
minStack: minStack(1, 1), minStack: 1,
maxStack: maxStack(1, 1), maxStack: maxStack(1, 1),
} }
jt[EXTCODEHASH] = &operation{ jt[EXTCODEHASH] = &operation{
execute: opExtCodeHash, execute: opExtCodeHash,
dynamicGas: gasExtCodeHash4762, dynamicGas: gasExtCodeHash4762,
minStack: minStack(1, 1), minStack: 1,
maxStack: maxStack(1, 1), maxStack: maxStack(1, 1),
} }
jt[EXTCODECOPY] = &operation{ jt[EXTCODECOPY] = &operation{
execute: opExtCodeCopyEIP4762, execute: opExtCodeCopyEIP4762,
dynamicGas: gasExtCodeCopyEIP4762, dynamicGas: gasExtCodeCopyEIP4762,
minStack: minStack(4, 0), minStack: 4,
maxStack: maxStack(4, 0), maxStack: maxStack(4, 0),
memorySize: memoryExtCodeCopy, memorySize: memoryExtCodeCopy,
} }
@ -493,7 +493,7 @@ func enable4762(jt *JumpTable) {
execute: opCodeCopy, execute: opCodeCopy,
constantGas: GasFastestStep, constantGas: GasFastestStep,
dynamicGas: gasCodeCopyEip4762, dynamicGas: gasCodeCopyEip4762,
minStack: minStack(3, 0), minStack: 3,
maxStack: maxStack(3, 0), maxStack: maxStack(3, 0),
memorySize: memoryCodeCopy, memorySize: memoryCodeCopy,
} }
@ -502,7 +502,7 @@ func enable4762(jt *JumpTable) {
execute: opSelfdestruct6780, execute: opSelfdestruct6780,
dynamicGas: gasSelfdestructEIP4762, dynamicGas: gasSelfdestructEIP4762,
constantGas: params.SelfdestructGasEIP150, constantGas: params.SelfdestructGasEIP150,
minStack: minStack(1, 0), minStack: 1,
maxStack: maxStack(1, 0), maxStack: maxStack(1, 0),
} }
@ -510,7 +510,7 @@ func enable4762(jt *JumpTable) {
execute: opCreate, execute: opCreate,
constantGas: params.CreateNGasEip4762, constantGas: params.CreateNGasEip4762,
dynamicGas: gasCreateEip3860, dynamicGas: gasCreateEip3860,
minStack: minStack(3, 1), minStack: 3,
maxStack: maxStack(3, 1), maxStack: maxStack(3, 1),
memorySize: memoryCreate, memorySize: memoryCreate,
} }
@ -519,7 +519,7 @@ func enable4762(jt *JumpTable) {
execute: opCreate2, execute: opCreate2,
constantGas: params.CreateNGasEip4762, constantGas: params.CreateNGasEip4762,
dynamicGas: gasCreate2Eip3860, dynamicGas: gasCreate2Eip3860,
minStack: minStack(4, 1), minStack: 4,
maxStack: maxStack(4, 1), maxStack: maxStack(4, 1),
memorySize: memoryCreate2, memorySize: memoryCreate2,
} }
@ -527,7 +527,7 @@ func enable4762(jt *JumpTable) {
jt[CALL] = &operation{ jt[CALL] = &operation{
execute: opCall, execute: opCall,
dynamicGas: gasCallEIP4762, dynamicGas: gasCallEIP4762,
minStack: minStack(7, 1), minStack: 7,
maxStack: maxStack(7, 1), maxStack: maxStack(7, 1),
memorySize: memoryCall, memorySize: memoryCall,
} }
@ -535,7 +535,7 @@ func enable4762(jt *JumpTable) {
jt[CALLCODE] = &operation{ jt[CALLCODE] = &operation{
execute: opCallCode, execute: opCallCode,
dynamicGas: gasCallCodeEIP4762, dynamicGas: gasCallCodeEIP4762,
minStack: minStack(7, 1), minStack: 7,
maxStack: maxStack(7, 1), maxStack: maxStack(7, 1),
memorySize: memoryCall, memorySize: memoryCall,
} }
@ -543,7 +543,7 @@ func enable4762(jt *JumpTable) {
jt[STATICCALL] = &operation{ jt[STATICCALL] = &operation{
execute: opStaticCall, execute: opStaticCall,
dynamicGas: gasStaticCallEIP4762, dynamicGas: gasStaticCallEIP4762,
minStack: minStack(6, 1), minStack: 6,
maxStack: maxStack(6, 1), maxStack: maxStack(6, 1),
memorySize: memoryStaticCall, memorySize: memoryStaticCall,
} }
@ -551,7 +551,7 @@ func enable4762(jt *JumpTable) {
jt[DELEGATECALL] = &operation{ jt[DELEGATECALL] = &operation{
execute: opDelegateCall, execute: opDelegateCall,
dynamicGas: gasDelegateCallEIP4762, dynamicGas: gasDelegateCallEIP4762,
minStack: minStack(6, 1), minStack: 6,
maxStack: maxStack(6, 1), maxStack: maxStack(6, 1),
memorySize: memoryDelegateCall, memorySize: memoryDelegateCall,
} }
@ -559,14 +559,14 @@ func enable4762(jt *JumpTable) {
jt[PUSH1] = &operation{ jt[PUSH1] = &operation{
execute: opPush1EIP4762, execute: opPush1EIP4762,
constantGas: GasFastestStep, constantGas: GasFastestStep,
minStack: minStack(0, 1), minStack: 0,
maxStack: maxStack(0, 1), maxStack: maxStack(0, 1),
} }
for i := 1; i < 32; i++ { for i := 1; i < 32; i++ {
jt[PUSH1+OpCode(i)] = &operation{ jt[PUSH1+OpCode(i)] = &operation{
execute: makePushEIP4762(uint64(i+1), i+1), execute: makePushEIP4762(uint64(i+1), i+1),
constantGas: GasFastestStep, constantGas: GasFastestStep,
minStack: minStack(0, 1), minStack: 0,
maxStack: maxStack(0, 1), maxStack: maxStack(0, 1),
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -20,16 +20,10 @@ import (
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
) )
func minSwapStack(n int) int {
return minStack(n, n)
}
func maxSwapStack(n int) int { func maxSwapStack(n int) int {
return maxStack(n, n) return maxStack(n, n)
} }
func minDupStack(n int) int {
return minStack(n, n+1)
}
func maxDupStack(n int) int { func maxDupStack(n int) int {
return maxStack(n, n+1) return maxStack(n, n+1)
} }
@ -37,6 +31,3 @@ func maxDupStack(n int) int {
func maxStack(pop, push int) int { func maxStack(pop, push int) int {
return int(params.StackLimit) + pop - push return int(params.StackLimit) + pop - push
} }
func minStack(pops, push int) int {
return pops
}