diff --git a/TransactionTests.md b/TransactionTests.md index 5c32de278..466039e69 100644 --- a/TransactionTests.md +++ b/TransactionTests.md @@ -24,15 +24,15 @@ OK: 8/8 Fail: 0/8 Skip: 0/8 ```diff + NotEnoughGasLimit.json OK + TransactionWithGasLimitOverflow.json OK -+ TransactionWithGasLimitOverflow2.json OK -+ TransactionWithGasLimitOverflow63.json OK -+ TransactionWithGasLimitOverflow63_1.json OK +- TransactionWithGasLimitOverflow2.json Fail +- TransactionWithGasLimitOverflow63.json Fail +- TransactionWithGasLimitOverflow63_1.json Fail + TransactionWithGasLimitxPriceOverflow.json OK + TransactionWithGasLimitxPriceOverflow2.json OK + TransactionWithHighGas.json OK + TransactionWithHihghGasLimit63m1.json OK ``` -OK: 9/9 Fail: 0/9 Skip: 0/9 +OK: 6/9 Fail: 3/9 Skip: 0/9 ## ttGasPrice ```diff + TransactionWithGasPriceOverflow.json OK @@ -221,4 +221,4 @@ OK: 2/2 Fail: 0/2 Skip: 0/2 OK: 70/70 Fail: 0/70 Skip: 0/70 ---TOTAL--- -OK: 179/179 Fail: 0/179 Skip: 0/179 +OK: 176/179 Fail: 3/179 Skip: 0/179 diff --git a/nimbus/transaction.nim b/nimbus/transaction.nim index 64da542e4..f72eb62b6 100644 --- a/nimbus/transaction.nim +++ b/nimbus/transaction.nim @@ -29,13 +29,6 @@ proc intrinsicGas*(tx: Transaction, fork: Fork): GasInt = if tx.isContractCreation: result = result + gasFees[fork][GasTXCreate] -proc validate*(t: Transaction, fork: Fork) = - # Hook called during instantiation to ensure that all transaction - # parameters pass validation rules - if t.intrinsicGas(fork) > t.gasLimit: - raise newException(ValidationError, "Insufficient gas") - # self.check_signature_validity() - proc getSignature*(transaction: Transaction, output: var Signature): bool = var bytes: array[65, byte] bytes[0..31] = transaction.R.toByteArrayBE() @@ -55,7 +48,7 @@ proc getSignature*(transaction: Transaction, output: var Signature): bool = proc toSignature*(transaction: Transaction): Signature = if not getSignature(transaction, result): - raise newException(Exception, "Invalid signaure") + raise newException(Exception, "Invalid signature") proc getSender*(transaction: Transaction, output: var EthAddress): bool = ## Find the address the transaction was sent from. @@ -78,3 +71,15 @@ proc getRecipient*(tx: Transaction): EthAddress = result = generateAddress(sender, tx.accountNonce) else: result = tx.to + +proc validate*(tx: Transaction, fork: Fork) = + # Hook called during instantiation to ensure that all transaction + # parameters pass validation rules + if tx.intrinsicGas(fork) > tx.gasLimit: + raise newException(ValidationError, "Insufficient gas") + + # check signature validity + var sender: EthAddress + if not tx.getSender(sender): + raise newException(ValidationError, "Invalid signature or failed message verification") + diff --git a/tests/all_tests.nim b/tests/all_tests.nim index dbe1821a7..7ad99f87c 100644 --- a/tests/all_tests.nim +++ b/tests/all_tests.nim @@ -23,5 +23,6 @@ import ./test_code_stream, ./test_op_misc, ./test_op_custom, ./test_state_db, - ./test_difficulty + ./test_difficulty, + ./test_transaction_json