From 18834721043b48d888e33af3a9bf80d06ed2cf00 Mon Sep 17 00:00:00 2001 From: andri lim Date: Thu, 18 Apr 2019 12:42:37 +0700 Subject: [PATCH] fix evm msg contract creation, GST +3 --- GeneralStateTests.md | 14 +++++++------- nimbus/constants.nim | 3 +++ nimbus/vm/computation.nim | 2 ++ nimbus/vm/interpreter/opcodes_impl.nim | 2 ++ nimbus/vm/message.nim | 7 +++++-- nimbus/vm_state_transactions.nim | 1 + nimbus/vm_types.nim | 17 ++--------------- tests/test_generalstate_failing.nim | 7 +++---- 8 files changed, 25 insertions(+), 28 deletions(-) diff --git a/GeneralStateTests.md b/GeneralStateTests.md index 99b3c4208..d4f8eade3 100644 --- a/GeneralStateTests.md +++ b/GeneralStateTests.md @@ -515,7 +515,7 @@ OK: 5/5 Fail: 0/5 Skip: 0/5 ```diff + CallContractToCreateContractAndCallItOOG.json OK + CallContractToCreateContractNoCash.json OK - CallContractToCreateContractOOG.json Skip ++ CallContractToCreateContractOOG.json OK + CallContractToCreateContractOOGBonusGas.json OK + CallContractToCreateContractWhichWouldCreateContractIfCalled.jsonOK + CallContractToCreateContractWhichWouldCreateContractInInitCode.jsonOK @@ -532,7 +532,7 @@ OK: 5/5 Fail: 0/5 Skip: 0/5 + TransactionCreateStopInInitcode.json OK + TransactionCreateSuicideInInitcode.json OK ``` -OK: 17/18 Fail: 0/18 Skip: 1/18 +OK: 18/18 Fail: 0/18 Skip: 0/18 ## stLogTests ```diff + log0_emptyMem.json OK @@ -1706,14 +1706,14 @@ OK: 16/16 Fail: 0/16 Skip: 0/16 + StackDepthLimitSEC.json OK block504980.json Skip + deploymentError.json OK - failed_tx_xcf416c53.json Skip ++ failed_tx_xcf416c53.json OK gasPrice0.json Skip + makeMoney.json OK sha3_deja.json Skip txCost-sec73.json Skip + tx_e1c174e2.json OK ``` -OK: 7/13 Fail: 0/13 Skip: 6/13 +OK: 8/13 Fail: 0/13 Skip: 5/13 ## stStackTests ```diff shallowStack.json Skip @@ -2123,7 +2123,7 @@ OK: 63/67 Fail: 0/67 Skip: 4/67 + TransactionNonceCheck.json OK + TransactionNonceCheck2.json OK + TransactionSendingToEmpty.json OK - TransactionSendingToZero.json Skip ++ TransactionSendingToZero.json OK + TransactionToAddressh160minusOne.json OK + TransactionToItself.json OK + TransactionToItselfNotEnoughFounds.json OK @@ -2131,7 +2131,7 @@ OK: 63/67 Fail: 0/67 Skip: 4/67 + UserTransactionZeroCost.json OK + UserTransactionZeroCostWithData.json OK ``` -OK: 43/44 Fail: 0/44 Skip: 1/44 +OK: 44/44 Fail: 0/44 Skip: 0/44 ## stTransitionTest ```diff + createNameRegistratorPerTxsAfter.json OK @@ -2520,4 +2520,4 @@ OK: 5/133 Fail: 0/133 Skip: 128/133 OK: 0/130 Fail: 0/130 Skip: 130/130 ---TOTAL--- -OK: 1507/2334 Fail: 0/2334 Skip: 827/2334 +OK: 1510/2334 Fail: 0/2334 Skip: 824/2334 diff --git a/nimbus/constants.nim b/nimbus/constants.nim index 048e10320..6e0cd8991 100644 --- a/nimbus/constants.nim +++ b/nimbus/constants.nim @@ -9,6 +9,9 @@ const INT_256_MAX_AS_UINT256* = high(Uint256) shr 1 UINT160CEILING*: UInt256 = 2.u256.pow(160) ZERO_ADDRESS* = default(EthAddress) + # TODO: use Option[EthAddress]? + # create contract address cannot be ZERO_ADDRESS + # because actual zero address exists CREATE_CONTRACT_ADDRESS* = ZERO_ADDRESS ZERO_HASH32* = Hash256() diff --git a/nimbus/vm/computation.nim b/nimbus/vm/computation.nim index 86a3bccac..6be387098 100644 --- a/nimbus/vm/computation.nim +++ b/nimbus/vm/computation.nim @@ -82,6 +82,7 @@ proc prepareChildMessage*( value: UInt256, data: seq[byte], code: seq[byte], + contractCreation: bool, options: MessageOptions = newMessageOptions()): Message = var childOptions = options @@ -94,6 +95,7 @@ proc prepareChildMessage*( value, data, code, + contractCreation, childOptions) proc snapshot*(comp: BaseComputation) = diff --git a/nimbus/vm/interpreter/opcodes_impl.nim b/nimbus/vm/interpreter/opcodes_impl.nim index 1e1c6d663..3ba85ca70 100644 --- a/nimbus/vm/interpreter/opcodes_impl.nim +++ b/nimbus/vm/interpreter/opcodes_impl.nim @@ -576,6 +576,7 @@ proc setupCreate(computation: BaseComputation, memPos, len: int, value: Uint256) value = value, data = @[], code = callData, + contractCreation = true, options = MessageOptions(createAddress: contractAddress) ) @@ -741,6 +742,7 @@ template genCall(callName: untyped, opCode: Op): untyped = value, callData, code.toSeq, + false, MessageOptions(flags: flags) ) diff --git a/nimbus/vm/message.nim b/nimbus/vm/message.nim index 295e65c80..54ab47b11 100644 --- a/nimbus/vm/message.nim +++ b/nimbus/vm/message.nim @@ -43,6 +43,7 @@ proc newMessage*( value: UInt256, data: seq[byte], code: seq[byte], + contractCreation: bool, options: MessageOptions = newMessageOptions()): Message = validateGte(options.depth, minimum=0, title="Message.depth") @@ -55,7 +56,8 @@ proc newMessage*( value = value, depth = options.depth, storageAddress = options.createAddress, - codeAddress = options.codeAddress + codeAddress = options.codeAddress, + contractCreation = contractCreation new(result) result.gas = gas @@ -69,6 +71,7 @@ proc newMessage*( result.codeAddress = options.codeAddress result.flags = options.flags result.code = code + result.contractCreation = contractCreation if options.origin != ZERO_ADDRESS: result.internalOrigin = options.origin @@ -97,4 +100,4 @@ proc `storageAddress`*(message: Message): EthAddress = message.destination proc isCreate*(message: Message): bool = - message.destination == CREATE_CONTRACT_ADDRESS + message.contractCreation diff --git a/nimbus/vm_state_transactions.nim b/nimbus/vm_state_transactions.nim index 9dc1dc675..ca88455b9 100644 --- a/nimbus/vm_state_transactions.nim +++ b/nimbus/vm_state_transactions.nim @@ -62,6 +62,7 @@ proc setupComputation*(vmState: BaseVMState, tx: Transaction, sender, recipient: value = tx.value, data = data, code = code, + tx.isContractCreation, options = newMessageOptions(origin = sender, createAddress = recipient)) diff --git a/nimbus/vm_types.nim b/nimbus/vm_types.nim index 14362018a..354925e4c 100644 --- a/nimbus/vm_types.nim +++ b/nimbus/vm_types.nim @@ -99,37 +99,24 @@ type Message* = ref object # A message for VM computation # https://github.com/ethereum/evmc/blob/master/include/evmc/evmc.h - - # depth = None - - # code = None - # codeAddress = None - - # createAddress = None - - # logger = logging.getLogger("evm.vm.message.Message") - destination*: EthAddress sender*: EthAddress value*: UInt256 data*: seq[byte] - # size_t input_size; - codeHash*: UInt256 - create2Salt*: Uint256 gas*: GasInt gasPrice*: GasInt depth*: int - kind*: CallKind + #kind*: CallKind flags*: MsgFlags # Not in EVMC API - # TODO: Done via callback function (v)table in EVMC code*: seq[byte] internalOrigin*: EthAddress internalCodeAddress*: EthAddress internalStorageAddress*: EthAddress + contractCreation*: bool MessageOptions* = ref object origin*: EthAddress diff --git a/tests/test_generalstate_failing.nim b/tests/test_generalstate_failing.nim index 121c13ade..6cbf9568f 100644 --- a/tests/test_generalstate_failing.nim +++ b/tests/test_generalstate_failing.nim @@ -21,10 +21,9 @@ func allowedFailingGeneralStateTest*(folder, name: string): bool = "doubleSelfdestructTest2.json", # Spurious Dragon failed GST - "CallContractToCreateContractOOG.json", - "failed_tx_xcf416c53.json", - "TransactionSendingToZero.json" - + #"CallContractToCreateContractOOG.json", + #"failed_tx_xcf416c53.json", + #"TransactionSendingToZero.json" #"OutOfGasContractCreation.json", #"OutOfGasPrefundedContractCreation.json", #"RevertOpcodeInInit.json",