2023-12-04 02:55:31 +00:00
|
|
|
# Nimbus
|
2024-05-20 10:17:51 +00:00
|
|
|
# Copyright (c) 2023-2024 Status Research & Development GmbH
|
2023-12-04 02:55:31 +00:00
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
|
|
|
|
# http://opensource.org/licenses/MIT)
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except
|
|
|
|
# according to those terms.
|
|
|
|
|
2024-05-28 12:49:35 +00:00
|
|
|
import eth/[keys, trie]
|
2023-12-04 02:55:31 +00:00
|
|
|
import stew/byteutils
|
|
|
|
import unittest2
|
|
|
|
import ../nimbus/common
|
2024-06-17 07:56:39 +00:00
|
|
|
import ../nimbus/evm/state
|
|
|
|
import ../nimbus/evm/types
|
2023-12-04 02:55:31 +00:00
|
|
|
import ../nimbus/transaction
|
|
|
|
import ../nimbus/transaction/call_evm
|
|
|
|
import ../nimbus/db/core_db
|
2023-12-12 19:12:56 +00:00
|
|
|
import ../nimbus/db/ledger
|
2023-12-04 02:55:31 +00:00
|
|
|
|
|
|
|
const
|
|
|
|
data = [0x5b.uint8, 0x5a, 0x5a, 0x30, 0x30, 0x30, 0x30, 0x72, 0x00, 0x00, 0x00, 0x58,
|
|
|
|
0x58, 0x24, 0x58, 0x58, 0x3a, 0x19, 0x75, 0x75, 0x2e, 0x2e, 0x2e, 0x2e,
|
|
|
|
0xec, 0x9f, 0x69, 0x67, 0x7f, 0xff, 0xff, 0xff, 0xff, 0x6c, 0x5a, 0x32,
|
|
|
|
0x07, 0xf4, 0x75, 0x75, 0xf5, 0x75, 0x75, 0x75, 0x7f, 0x5b, 0xd9, 0x32,
|
|
|
|
0x5a, 0x07, 0x19, 0x34, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e,
|
|
|
|
0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e,
|
|
|
|
0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0x2e, 0xec,
|
|
|
|
0x9f, 0x69, 0x67, 0x7f, 0xff, 0xff, 0xff, 0xff, 0x6c, 0xfc, 0xf7, 0xfc,
|
|
|
|
0xfc, 0xfc, 0xfc, 0xf4, 0x03, 0x03, 0x81, 0x81, 0x81, 0xfb, 0x7a, 0x30,
|
|
|
|
0x80, 0x3d, 0x59, 0x59, 0x59, 0x59, 0x81, 0x00, 0x59, 0x2f, 0x45, 0x30,
|
|
|
|
0x32, 0xf4, 0x5d, 0x5b, 0x37, 0x19]
|
|
|
|
|
|
|
|
codeAddress = hexToByteArray[20]("000000000000000000000000636f6e7472616374")
|
|
|
|
coinbase = hexToByteArray[20]("4444588443C3a91288c5002483449Aba1054192b")
|
|
|
|
|
|
|
|
proc overflowMain*() =
|
|
|
|
test "GasCall unhandled overflow":
|
|
|
|
let header = BlockHeader(
|
2024-05-28 12:49:35 +00:00
|
|
|
stateRoot: emptyRlpHash,
|
2024-06-14 07:31:08 +00:00
|
|
|
number: 1150000'u64,
|
2023-12-04 02:55:31 +00:00
|
|
|
coinBase: coinbase,
|
|
|
|
gasLimit: 30000000,
|
|
|
|
timeStamp: EthTime(123456),
|
|
|
|
)
|
|
|
|
|
2024-05-20 10:17:51 +00:00
|
|
|
let com = CommonRef.new(newCoreDbRef(DefaultDbMemory), config = chainConfigForNetwork(MainNet))
|
2023-12-04 02:55:31 +00:00
|
|
|
let s = BaseVMState.new(
|
|
|
|
header,
|
|
|
|
header,
|
|
|
|
com,
|
|
|
|
)
|
|
|
|
|
|
|
|
s.stateDB.setCode(codeAddress, @data)
|
|
|
|
let unsignedTx = Transaction(
|
|
|
|
txType: TxLegacy,
|
|
|
|
nonce: 0,
|
|
|
|
chainId: MainNet.ChainId,
|
|
|
|
gasPrice: 0.GasInt,
|
|
|
|
gasLimit: 30000000,
|
2024-06-14 07:31:08 +00:00
|
|
|
to: Opt.some codeAddress,
|
2023-12-04 02:55:31 +00:00
|
|
|
value: 0.u256,
|
|
|
|
payload: @data
|
|
|
|
)
|
|
|
|
|
|
|
|
let privateKey = PrivateKey.fromHex("0000000000000000000000000000000000000000000000000000001000000000")[]
|
|
|
|
let tx = signTransaction(unsignedTx, privateKey, ChainId(1), false)
|
|
|
|
let res = testCallEvm(tx, tx.getSender, s, FkHomestead)
|
2024-06-07 08:24:32 +00:00
|
|
|
|
2023-12-04 02:55:31 +00:00
|
|
|
when defined(evmc_enabled):
|
|
|
|
check res.error == "EVMC_FAILURE"
|
|
|
|
else:
|
2024-06-07 08:24:32 +00:00
|
|
|
check res.error == "Opcode Dispatch Error: GasIntOverflow, depth=1"
|
2023-12-04 02:55:31 +00:00
|
|
|
|
|
|
|
when isMainModule:
|
|
|
|
overflowMain()
|