move origin and gasPrice from Message to vmState
This commit is contained in:
parent
d300bc352d
commit
bab359cabf
|
@ -39,7 +39,7 @@ proc newComputation*(vmState: BaseVMState, message: Message, forkOverride=none(F
|
|||
|
||||
proc isOriginComputation*(c: Computation): bool =
|
||||
# Is this computation the computation initiated by a transaction
|
||||
c.msg.isOrigin
|
||||
c.msg.sender == c.vmState.txOrigin
|
||||
|
||||
template isSuccess*(c: Computation): bool =
|
||||
c.error.isNil
|
||||
|
|
|
@ -240,7 +240,7 @@ op balance, inline = true:
|
|||
|
||||
op origin, inline = true:
|
||||
## 0x32, Get execution origination address.
|
||||
push: c.msg.origin
|
||||
push: c.vmState.txOrigin
|
||||
|
||||
op caller, inline = true:
|
||||
## 0x33, Get caller address.
|
||||
|
@ -301,7 +301,7 @@ op codeCopy, inline = false, memStartPos, copyStartPos, size:
|
|||
|
||||
op gasprice, inline = true:
|
||||
## 0x3A, Get price of gas in current environment.
|
||||
push: c.msg.gasPrice
|
||||
push: c.vmState.txGasPrice
|
||||
|
||||
op extCodeSize, inline = true:
|
||||
## 0x3b, Get size of an account's code
|
||||
|
@ -569,8 +569,6 @@ proc setupCreate(c: Computation, memPos, len: int, value: Uint256, opCode: stati
|
|||
kind: callKind,
|
||||
depth: c.msg.depth + 1,
|
||||
gas: createMsgGas,
|
||||
gasPrice: c.msg.gasPrice,
|
||||
origin: c.msg.origin,
|
||||
sender: c.msg.contractAddress,
|
||||
contractAddress: contractAddress,
|
||||
codeAddress: CREATE_CONTRACT_ADDRESS,
|
||||
|
@ -749,8 +747,6 @@ template genCall(callName: untyped, opCode: Op): untyped =
|
|||
kind: callKind,
|
||||
depth: c.msg.depth + 1,
|
||||
gas: childGasLimit,
|
||||
gasPrice: c.msg.gasPrice,
|
||||
origin: c.msg.origin,
|
||||
sender: sender,
|
||||
contractAddress: contractAddress,
|
||||
codeAddress: codeAddress,
|
||||
|
|
|
@ -9,8 +9,5 @@ import
|
|||
eth/common,
|
||||
../constants, ../validation, ../vm_types, chronicles
|
||||
|
||||
proc isOrigin*(message: Message): bool =
|
||||
message.sender == message.origin
|
||||
|
||||
proc isCreate*(message: Message): bool =
|
||||
message.kind in {evmcCreate, evmcCreate2}
|
||||
|
|
|
@ -35,13 +35,19 @@ proc init*(self: BaseVMState, prevStateRoot: Hash256, header: BlockHeader,
|
|||
self.tracingEnabled = TracerFlags.EnableTracing in tracerFlags
|
||||
self.logEntries = @[]
|
||||
self.accountDb = newAccountStateDB(chainDB.db, prevStateRoot, chainDB.pruneTrie)
|
||||
self.touchedAccounts = initHashSet[EthAddress]()
|
||||
self.touchedAccounts = initHashSet[EthAddress]()
|
||||
|
||||
proc newBaseVMState*(prevStateRoot: Hash256, header: BlockHeader,
|
||||
chainDB: BaseChainDB, tracerFlags: set[TracerFlags] = {}): BaseVMState =
|
||||
new result
|
||||
result.init(prevStateRoot, header, chainDB, tracerFlags)
|
||||
|
||||
proc txContext*(vmState: BaseVMState, origin: EthAddress, gasPrice: GasInt) =
|
||||
## this proc will be called each time a new transaction
|
||||
## is going to be executed
|
||||
vmState.txOrigin = origin
|
||||
vmState.txGasPrice = gasPrice
|
||||
|
||||
method blockhash*(vmState: BaseVMState): Hash256 {.base, gcsafe.} =
|
||||
vmState.blockHeader.hash
|
||||
|
||||
|
|
|
@ -44,12 +44,15 @@ proc setupComputation*(vmState: BaseVMState, tx: Transaction, sender, recipient:
|
|||
debug "not enough gas to perform calculation", gas=gas
|
||||
return
|
||||
|
||||
vmState.txContext(
|
||||
origin = sender,
|
||||
gasPrice = tx.gasPrice
|
||||
)
|
||||
|
||||
let msg = Message(
|
||||
kind: if tx.isContractCreation: evmcCreate else: evmcCall,
|
||||
depth: 0,
|
||||
gas: gas,
|
||||
gasPrice: tx.gasPrice,
|
||||
origin: sender,
|
||||
sender: sender,
|
||||
contractAddress: recipient,
|
||||
codeAddress: tx.to,
|
||||
|
|
|
@ -28,6 +28,8 @@ type
|
|||
touchedAccounts*: HashSet[EthAddress]
|
||||
suicides* : HashSet[EthAddress]
|
||||
status* : bool
|
||||
txOrigin* : EthAddress
|
||||
txGasPrice* : GasInt
|
||||
|
||||
AccessLogs* = ref object
|
||||
reads*: Table[string, string]
|
||||
|
@ -100,8 +102,6 @@ type
|
|||
kind*: CallKind
|
||||
depth*: int
|
||||
gas*: GasInt
|
||||
gasPrice*: GasInt
|
||||
origin*: EthAddress
|
||||
sender*: EthAddress
|
||||
contractAddress*: EthAddress
|
||||
codeAddress*: EthAddress
|
||||
|
|
|
@ -205,13 +205,16 @@ proc initComputation(vmState: BaseVMState, tx: Transaction, sender: EthAddress,
|
|||
|
||||
let gasUsed = 0 #tx.payload.intrinsicGas.GasInt + gasFees[fork][GasTXCreate]
|
||||
|
||||
vmState.txContext(
|
||||
origin = sender,
|
||||
gasPrice = tx.gasPrice
|
||||
)
|
||||
|
||||
let contractAddress = generateAddress(sender, tx.accountNonce)
|
||||
let msg = Message(
|
||||
kind: evmcCall,
|
||||
depth: 0,
|
||||
gas: tx.gasLimit - gasUsed,
|
||||
gasPrice: tx.gasPrice,
|
||||
origin: sender,
|
||||
sender: sender,
|
||||
contractAddress: contractAddress,
|
||||
codeAddress: tx.to,
|
||||
|
|
|
@ -29,11 +29,16 @@ template doTest(fixture: JsonNode, address: byte, action: untyped): untyped =
|
|||
gasPrice = 1.GasInt
|
||||
sender: EthAddress
|
||||
toAddress = initAddress(address)
|
||||
|
||||
vmState.txContext(
|
||||
origin = sender,
|
||||
gasPrice = gasPrice
|
||||
)
|
||||
|
||||
var
|
||||
message = Message(
|
||||
kind: evmcCall,
|
||||
gas: gas,
|
||||
gasPrice: gasPrice,
|
||||
origin: sender,
|
||||
sender: sender,
|
||||
contractAddress: toAddress,
|
||||
codeAddress: toAddress,
|
||||
|
|
|
@ -47,14 +47,17 @@ proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus) =
|
|||
let address = fexec{"address"}.getStr.parseAddress
|
||||
code = db.getCode(address).toSeq
|
||||
|
||||
vmState.txContext(
|
||||
origin = fexec{"origin"}.getStr.parseAddress,
|
||||
gasPrice = fexec{"gasPrice"}.getHexadecimalInt
|
||||
)
|
||||
|
||||
code = fexec{"code"}.getStr.hexToSeqByte
|
||||
let toAddress = fexec{"address"}.getStr.parseAddress
|
||||
let message = Message(
|
||||
kind: if toAddress == ZERO_ADDRESS: evmcCreate else: evmcCall, # assume ZERO_ADDRESS is a contract creation
|
||||
depth: 0,
|
||||
gas: fexec{"gas"}.getHexadecimalInt,
|
||||
gasPrice: fexec{"gasPrice"}.getHexadecimalInt,
|
||||
origin: fexec{"origin"}.getStr.parseAddress,
|
||||
sender: fexec{"caller"}.getStr.parseAddress,
|
||||
contractAddress: toAddress,
|
||||
codeAddress: toAddress,
|
||||
|
|
Loading…
Reference in New Issue