Skip to content

Commit 7a804e8

Browse files
authored
Merge branch 'master' into tx-fix-isSigned
2 parents afbd077 + 5953e09 commit 7a804e8

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

packages/vm/lib/runTx.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ export interface RunTxOpts {
2727
* If true, skips the balance check
2828
*/
2929
skipBalance?: boolean
30+
31+
/**
32+
* If true, skips the validation of the tx's gas limit
33+
* agains the block's gas limit.
34+
*/
35+
skipBlockGasLimitValidation?: boolean
3036
}
3137

3238
/**
@@ -66,7 +72,10 @@ export default async function runTx(this: VM, opts: RunTxOpts): Promise<RunTxRes
6672
// create a reasonable default if no block is given
6773
opts.block = opts.block ?? Block.fromBlockData({}, { common: opts.tx.common })
6874

69-
if (opts.block.header.gasLimit.lt(opts.tx.gasLimit)) {
75+
if (
76+
opts.skipBlockGasLimitValidation !== true &&
77+
opts.block.header.gasLimit.lt(opts.tx.gasLimit)
78+
) {
7079
throw new Error('tx has a higher gas limit than the block')
7180
}
7281

packages/vm/tests/api/runTx.spec.ts

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import tape from 'tape'
2-
import { Address, BN, MAX_INTEGER } from 'ethereumjs-util'
2+
import { Account, Address, BN, MAX_INTEGER } from 'ethereumjs-util'
3+
import { Block } from '@ethereumjs/block'
34
import Common from '@ethereumjs/common'
45
import { Transaction } from '@ethereumjs/tx'
56
import VM from '../../lib'
@@ -144,6 +145,48 @@ tape('should clear storage cache after every transaction', async (t) => {
144145
t.end()
145146
})
146147

148+
tape('should be possible to disable the block gas limit validation', async (t) => {
149+
const vm = new VM()
150+
151+
const privateKey = Buffer.from(
152+
'e331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109',
153+
'hex'
154+
)
155+
const address = Address.fromPrivateKey(privateKey)
156+
const initialBalance = new BN(10).pow(new BN(18))
157+
158+
const account = await vm.stateManager.getAccount(address)
159+
await vm.stateManager.putAccount(
160+
address,
161+
Account.fromAccountData({ ...account, balance: initialBalance })
162+
)
163+
164+
const transferCost = 21000
165+
166+
const unsignedTx = Transaction.fromTxData({
167+
to: address,
168+
gasLimit: transferCost,
169+
gasPrice: 1,
170+
nonce: 0,
171+
})
172+
173+
const tx = unsignedTx.sign(privateKey)
174+
175+
const block = Block.fromBlockData({
176+
header: { gasLimit: transferCost - 1 },
177+
})
178+
179+
const result = await vm.runTx({
180+
tx,
181+
block,
182+
skipBlockGasLimitValidation: true,
183+
})
184+
185+
t.equals(result.execResult.exceptionError, undefined)
186+
187+
t.end()
188+
})
189+
147190
// The following test tries to verify that running a tx
148191
// would work, even when stateManager is not using a cache.
149192
// It fails at the moment, and has been therefore commented.

0 commit comments

Comments
 (0)