-
Notifications
You must be signed in to change notification settings - Fork 772
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement EIP 7623: calldata cost increase (#3813)
* common/evm/vm: implement EIP7623 calldata cost increase * move the floorcost update and add debug log * fix t8ntool empty requests reporting * common: add 7623 * tx: add 7623 validator * t8n: throw on invalid txs * make cspell happy --------- Co-authored-by: harkamal <[email protected]>
- Loading branch information
1 parent
fc3c150
commit fb7e67f
Showing
7 changed files
with
187 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import { createBlock } from '@ethereumjs/block' | ||
import { Common, Hardfork, Mainnet } from '@ethereumjs/common' | ||
import { createLegacyTx } from '@ethereumjs/tx' | ||
import { Account, Address, createZeroAddress, hexToBytes, privateToAddress } from '@ethereumjs/util' | ||
import { assert, describe, it } from 'vitest' | ||
|
||
import { createVM, runTx } from '../../../src/index.js' | ||
|
||
const common = new Common({ chain: Mainnet, hardfork: Hardfork.Prague }) | ||
|
||
const pkey = hexToBytes(`0x${'20'.repeat(32)}`) | ||
const GWEI = BigInt(1000000000) | ||
const sender = new Address(privateToAddress(pkey)) | ||
|
||
const coinbase = new Address(hexToBytes(`0x${'ff'.repeat(20)}`)) | ||
|
||
const block = createBlock( | ||
{ | ||
header: { | ||
baseFeePerGas: 7, | ||
coinbase, | ||
}, | ||
}, | ||
{ common }, | ||
) | ||
|
||
const code = hexToBytes('0x60008080806001415AF100') | ||
const contractAddress = new Address(hexToBytes(`0x${'ee'.repeat(20)}`)) | ||
|
||
async function getVM(common: Common) { | ||
const vm = await createVM({ common }) | ||
await vm.stateManager.putAccount(sender, new Account()) | ||
const account = await vm.stateManager.getAccount(sender) | ||
const balance = GWEI * BigInt(21000) * BigInt(10000000) | ||
account!.balance = balance | ||
await vm.stateManager.putAccount(sender, account!) | ||
|
||
await vm.stateManager.putCode(contractAddress, code) | ||
return vm | ||
} | ||
|
||
describe('EIP 7623 calldata cost increase tests', () => { | ||
it('charges floor gas', async () => { | ||
const vm = await getVM(common) | ||
|
||
const tx = createLegacyTx( | ||
{ | ||
to: createZeroAddress(), | ||
data: new Uint8Array(100).fill(1), | ||
gasLimit: 1000000, | ||
gasPrice: 10, | ||
}, | ||
{ common }, | ||
).sign(pkey) | ||
|
||
const result = await runTx(vm, { | ||
block, | ||
tx, | ||
skipHardForkValidation: true, | ||
}) | ||
|
||
const baseCost = tx.common.param('txGas') | ||
const floorCost = tx.common.param('totalCostFloorPerToken') | ||
|
||
const expected = baseCost + BigInt(tx.data.length) * BigInt(4) * floorCost | ||
|
||
assert.equal(result.totalGasSpent, expected) | ||
}) | ||
it('rejects transactions having a gas limit below the floor gas limit', async () => { | ||
const vm = await getVM(common) | ||
|
||
const tx = createLegacyTx( | ||
{ | ||
to: createZeroAddress(), | ||
data: new Uint8Array(100).fill(1), | ||
gasLimit: 21000 + 100 * 4, | ||
gasPrice: 10, | ||
}, | ||
{ common }, | ||
).sign(pkey) | ||
try { | ||
await runTx(vm, { | ||
block, | ||
tx, | ||
skipHardForkValidation: true, | ||
}) | ||
assert.fail('runTx should throw') | ||
} catch (e) { | ||
assert.ok('Successfully failed') | ||
} | ||
}) | ||
it('correctly charges execution gas instead of floor gas when execution gas exceeds the floor gas', async () => { | ||
const vm = await getVM(common) | ||
const to = createZeroAddress() | ||
|
||
// Store 1 in slot 1 | ||
await vm.stateManager.putCode(to, hexToBytes('0x6001600155')) | ||
|
||
const tx = createLegacyTx( | ||
{ | ||
to: createZeroAddress(), | ||
data: new Uint8Array(100).fill(1), | ||
gasLimit: 1000000, | ||
gasPrice: 10, | ||
}, | ||
{ common }, | ||
).sign(pkey) | ||
|
||
const result = await runTx(vm, { | ||
block, | ||
tx, | ||
skipHardForkValidation: true, | ||
}) | ||
|
||
const baseCost = tx.common.param('txGas') | ||
|
||
const expected = | ||
baseCost + | ||
BigInt(tx.data.length) * tx.common.param('txDataNonZeroGas') + | ||
BigInt(2 * 3) + | ||
BigInt(22_100) | ||
|
||
assert.equal(result.totalGasSpent, expected) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters