From 069a21d972286a96800efb80fbcffecfc08b8f02 Mon Sep 17 00:00:00 2001 From: silentcicero Date: Mon, 13 May 2019 17:42:21 +0100 Subject: [PATCH] sloadext --- core/vm/gas_table.go | 4 ++++ core/vm/instructions.go | 9 +++++++++ core/vm/jump_table.go | 7 +++++++ core/vm/opcodes.go | 3 +++ params/protocol_params.go | 1 + 5 files changed, 24 insertions(+) diff --git a/core/vm/gas_table.go b/core/vm/gas_table.go index 8270300ba7..36ac43b380 100644 --- a/core/vm/gas_table.go +++ b/core/vm/gas_table.go @@ -365,6 +365,10 @@ func gasSLoad(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, me return gt.SLoad, nil } +func gasSLoadExt(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { + return gt.SLoad, nil +} + func gasExp(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { expByteLen := uint64((stack.data[stack.len()-2].BitLen() + 7) / 8) diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 2a062d7e77..f9b4c6292a 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -633,6 +633,15 @@ func opSload(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory return nil, nil } +func opSloadExt(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { + addr := common.BigToAddress(stack.pop()) + loc := stack.pop() + + val := interpreter.evm.StateDB.GetState(addr, common.BigToHash(loc)) + loc.SetBytes(val.Bytes()) + return nil, nil +} + func opSstore(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { loc := common.BigToHash(stack.pop()) val := stack.pop() diff --git a/core/vm/jump_table.go b/core/vm/jump_table.go index 425436f9e5..5001ebaf48 100644 --- a/core/vm/jump_table.go +++ b/core/vm/jump_table.go @@ -513,6 +513,13 @@ func newFrontierInstructionSet() [256]operation { maxStack: maxStack(1, 1), valid: true, }, + SLOADEXT: { + execute: opSload, + dynamicGas: gasSLoad, + minStack: minStack(2, 1), + maxStack: maxStack(2, 1), + valid: true, + }, SSTORE: { execute: opSstore, dynamicGas: gasSStore, diff --git a/core/vm/opcodes.go b/core/vm/opcodes.go index 4349ffd295..3f68b7f9a6 100644 --- a/core/vm/opcodes.go +++ b/core/vm/opcodes.go @@ -110,6 +110,7 @@ const ( MSTORE MSTORE8 SLOAD + SLOADEXT SSTORE JUMP JUMPI @@ -286,6 +287,7 @@ var opCodeToString = map[OpCode]string{ MSTORE: "MSTORE", MSTORE8: "MSTORE8", SLOAD: "SLOAD", + SLOADEXT: "SLOADEXT", SSTORE: "SSTORE", JUMP: "JUMP", JUMPI: "JUMPI", @@ -449,6 +451,7 @@ var stringToOp = map[string]OpCode{ "MSTORE": MSTORE, "MSTORE8": MSTORE8, "SLOAD": SLOAD, + "SLOADEXT": SLOADEXT, "SSTORE": SSTORE, "JUMP": JUMP, "JUMPI": JUMPI, diff --git a/params/protocol_params.go b/params/protocol_params.go index 14750f6a1a..a378716d44 100644 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -26,6 +26,7 @@ const ( MaximumExtraDataSize uint64 = 32 // Maximum size extra data may be after Genesis. ExpByteGas uint64 = 10 // Times ceil(log256(exponent)) for the EXP instruction. SloadGas uint64 = 50 // Multiplied by the number of 32-byte words that are copied (round up) for any *COPY operation and added. + SloadExtGas uint64 = 50 // Multiplied by the number of 32-byte words that are copied (round up) for any *COPY operation and added. CallValueTransferGas uint64 = 9000 // Paid for CALL when the value transfer is non-zero. CallNewAccountGas uint64 = 25000 // Paid for CALL when the destination address didn't exist prior. TxGas uint64 = 21000 // Per transaction not creating a contract. NOTE: Not payable on data of calls between transactions.