finishing touches

This commit is contained in:
Jared Wasinger 2024-11-30 00:05:58 +07:00
parent 08bd16adff
commit e4aa362e75
4 changed files with 17 additions and 11 deletions

View file

@ -54,7 +54,6 @@ func evmmaxMemoryGasCost(pc uint64, scope *ScopeContext, newMemSize uint64, newE
curEVMMAXMemSizePadded := toWordSize(curEVMMAXMemSize) * 32
newEVMMAXMemSizePadded := toWordSize(newEVMMAXMemSize) * 32
// if newEVMMAXMemSize + newEVMMemSize > curEVMMAXMemSize + curEVMMemSize
if newMemSizePadded > uint64(scope.Memory.Len()) || newEVMMAXMemSizePadded > curEVMMAXMemSizePadded {
// if this is called by the invocation of SETUPX, the new evm memory is
// 0, but we still need it to compute the fee
@ -548,7 +547,7 @@ func isPowerOfTwo(val *big.Int) bool {
return false
}
func gasSetupx(pc uint64, evm *EVM, scope *ScopeContext, memorySize uint64) (uint64, error) {
func gasSetmodx(pc uint64, evm *EVM, scope *ScopeContext, memorySize uint64) (uint64, error) {
if !scope.Stack.Back(0).IsUint64() || !scope.Stack.Back(2).IsUint64() || !scope.Stack.Back(3).IsUint64() {
return 0, errors.New("one or more parameters overflows 64 bits")
}
@ -619,9 +618,11 @@ func gasStorex(pc uint64, evm *EVM, scope *ScopeContext, memorySize uint64) (uin
}
if scope.modExtState.active.IsModulusBinary() {
// TODO: seems pretty impossible that this can overflow, just adding a note
// here to remind myself to double-check this once again.
return toWordSize(storeSize) * params.CopyGas, nil
} else {
return count.Uint64() * uint64(params.MulmodxCost[int(scope.modExtState.active.ElemSize()/8)-1]), nil
return count.Uint64() * params.MulmodxCost[int(scope.modExtState.active.ElemSize()/8)-1], nil
}
}
@ -646,16 +647,21 @@ func gasLoadx(pc uint64, evm *EVM, scope *ScopeContext, memorySize uint64) (uint
return 0, errors.New("out of bounds destination")
}
loadSize := count.Uint64() * uint64(scope.modExtState.active.ElemSize())
loadSize, overflow := math.SafeMul(count.Uint64(), uint64(scope.modExtState.active.ElemSize()))
if overflow {
return 0, fmt.Errorf("overflow")
}
last, overflow := math.SafeAdd(dst.Uint64(), loadSize)
if overflow || last > uint64(scope.Memory.Len()) {
return 0, errors.New("out of bounds destination")
}
if scope.modExtState.active.IsModulusBinary() {
// TODO: seems pretty impossible that this can overflow, just adding a note
// here to remind myself to double-check this once again.
return toWordSize(loadSize) * params.CopyGas, nil
} else {
return count.Uint64() * uint64(params.MulmodxCost[int(scope.modExtState.active.ElemSize()/8)-1]), nil
return count.Uint64() * params.MulmodxCost[int(scope.modExtState.active.ElemSize()/8)-1], nil
}
}

View file

@ -954,7 +954,7 @@ func makeLog(size int) executionFunc {
}
}
func opSetupx(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
func opSetmodx(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
id, modOffset, modSize, allocSize := scope.Stack.pop(), scope.Stack.pop(), scope.Stack.pop(), scope.Stack.pop()
modulus := scope.Memory.GetCopy(modOffset.Uint64(), modSize.Uint64())

View file

@ -104,9 +104,9 @@ func newPragueEOFInstructionSet() JumpTable {
func newEVMMAXInstructionSet() JumpTable {
instructionSet := newCancunInstructionSet()
instructionSet[SETUPX] = &operation{
execute: opSetupx,
dynamicGas: gasSetupx,
instructionSet[SETMODX] = &operation{
execute: opSetmodx,
dynamicGas: gasSetmodx,
minStack: minStack(4, 0),
maxStack: maxStack(4, 0),
}

View file

@ -204,7 +204,7 @@ const (
// 0xc0 range - extended-width modular arithmetic ops.
const (
SETUPX OpCode = 0xc0 + iota
SETMODX OpCode = 0xc0 + iota
LOADX
STOREX
ADDMODX
@ -418,7 +418,7 @@ var opCodeToString = [256]string{
SWAP16: "SWAP16",
// 0xc0 range - extended-range modular arithmetic ops
SETUPX: "SETUPX",
SETMODX: "SETMODX",
LOADX: "LOADX",
STOREX: "STOREX",
ADDMODX: "ADDMODX",