fix create contract address collision, GST +1

This commit is contained in:
andri lim 2019-03-18 12:48:32 +07:00
parent 4383831772
commit cd765bf452
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
5 changed files with 17 additions and 13 deletions

View File

@ -186,14 +186,14 @@ OK: 50/79 Fail: 0/79 Skip: 29/79
createInitFailUndefinedInstruction.json Skip
+ createInitFail_OOGduringInit.json OK
+ createInitOOGforCREATE.json OK
createJS_ExampleContract.json Skip
+ createJS_ExampleContract.json OK
+ createJS_NoCollision.json OK
+ createNameRegistratorPerTxs.json OK
+ createNameRegistratorPerTxsNotEnoughGas.json OK
+ createNameRegistratorPreStore1NotEnoughGas.json OK
+ createNameRegistratorendowmentTooHigh.json OK
```
OK: 18/39 Fail: 0/39 Skip: 21/39
OK: 19/39 Fail: 0/39 Skip: 20/39
## stCallDelegateCodesCallCodeHomestead
```diff
callcallcallcode_001.json Skip
@ -2520,4 +2520,4 @@ OK: 0/133 Fail: 0/133 Skip: 133/133
OK: 0/130 Fail: 0/130 Skip: 130/130
---TOTAL---
OK: 1309/2334 Fail: 0/2334 Skip: 1025/2334
OK: 1310/2334 Fail: 0/2334 Skip: 1024/2334

View File

@ -29,17 +29,23 @@ proc processTransaction*(tx: Transaction, sender: EthAddress, vmState: BaseVMSta
if balance < upfrontGasCost:
return tx.gasLimit
var computation = setupComputation(vmState, tx, sender, forkOverride)
let recipient = tx.getRecipient()
let isCollision = vmState.readOnlyStateDb().hasCodeOrNonce(recipient)
var computation = setupComputation(vmState, tx, sender, recipient, forkOverride)
if computation.isNil:
return 0
vmState.mutateStateDB:
db.incNonce(sender)
db.subBalance(sender, upfrontGasCost)
if tx.isContractCreation and isCollision:
return tx.gasLimit
var snapshot = vmState.snapshot()
defer: snapshot.dispose()
var contractOK = true
result = tx.gasLimit

View File

@ -35,11 +35,13 @@ template balance(addressDb: ReadOnlyStateDb, address: EthAddress): GasInt =
proc binarySearchGas(vmState: var BaseVMState, transaction: Transaction, sender: EthAddress, gasPrice: GasInt, tolerance = 1): GasInt =
proc dummyComputation(vmState: var BaseVMState, transaction: Transaction, sender: EthAddress): BaseComputation =
let recipient = transaction.getRecipient()
# Note that vmState may be altered
setupComputation(
vmState,
transaction,
sender)
sender,
recipient)
proc dummyTransaction(gasLimit, gasPrice: GasInt, destination: EthAddress, value: UInt256): Transaction =
Transaction(

View File

@ -24,14 +24,13 @@ proc validateTransaction*(vmState: BaseVMState, transaction: Transaction, sender
transaction.accountNonce == readOnlyDB.getNonce(sender) and
readOnlyDB.getBalance(sender) >= gasCost
proc setupComputation*(vmState: BaseVMState, tx: Transaction, sender: EthAddress, forkOverride=none(Fork)) : BaseComputation =
proc setupComputation*(vmState: BaseVMState, tx: Transaction, sender, recipient: EthAddress, forkOverride=none(Fork)) : BaseComputation =
let fork =
if forkOverride.isSome:
forkOverride.get
else:
vmState.blockNumber.toFork
var recipient: EthAddress
var gas = tx.gasLimit - tx.intrinsicGas
# TODO: refactor message to use byterange
@ -39,12 +38,10 @@ proc setupComputation*(vmState: BaseVMState, tx: Transaction, sender: EthAddress
var data, code: seq[byte]
if tx.isContractCreation:
recipient = generateAddress(sender, tx.accountNonce)
gas = gas - gasFees[fork][GasTXCreate]
data = @[]
code = tx.payload
else:
recipient = tx.to
data = tx.payload
code = vmState.readOnlyStateDB.getCode(tx.to).toSeq

View File

@ -78,8 +78,7 @@ func allowedFailingGeneralStateTest*(folder, name: string): bool =
"callcodecallcallcode_ABCB_RECURSIVE.json",
"callcodecallcodecall_ABCB_RECURSIVE.json",
"callcodecallcodecallcode_ABCB_RECURSIVE.json",
# Frontier failed test cases
"createJS_ExampleContract.json",
# Frontier failed test cases
"callcallcallcode_001_OOGMAfter_1.json",
"callcallcallcode_001_OOGMAfter_2.json",
"createInitFailUndefinedInstruction.json",