-
Notifications
You must be signed in to change notification settings - Fork 759
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into add-kurtosis-to-ci-…
…workflows
- Loading branch information
Showing
17 changed files
with
290 additions
and
72 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,121 @@ | ||
import { Hardfork } from '@ethereumjs/common' | ||
import { TransactionFactory } from '@ethereumjs/tx' | ||
import { | ||
Address, | ||
BIGINT_0, | ||
BIGINT_256, | ||
blobsToCommitments, | ||
commitmentsToVersionedHashes, | ||
getBlobs, | ||
hexToBytes, | ||
} from '@ethereumjs/util' | ||
import { loadKZG } from 'kzg-wasm' | ||
import { assert, describe, it } from 'vitest' | ||
|
||
import genesisJSON from '../../testdata/geth-genesis/eip4844.json' | ||
import { getRpcClient, setupChain } from '../helpers.js' | ||
|
||
import type { Chain } from '../../../src/blockchain/chain.js' | ||
import type { VMExecution } from '../../../src/execution/vmexecution.js' | ||
const method = 'eth_blobBaseFee' | ||
|
||
const privateKey = hexToBytes('0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8') | ||
const accountAddress = Address.fromPrivateKey(privateKey) | ||
const produceBlockWith4844Tx = async ( | ||
execution: VMExecution, | ||
chain: Chain, | ||
blobsCount: number[] | ||
) => { | ||
const kzg = await loadKZG() | ||
// 4844 sample blob | ||
const sampleBlob = getBlobs('hello world') | ||
const commitment = blobsToCommitments(kzg, sampleBlob) | ||
const blobVersionedHash = commitmentsToVersionedHashes(commitment) | ||
|
||
const { vm } = execution | ||
const account = await vm.stateManager.getAccount(accountAddress) | ||
let nonce = account?.nonce ?? BIGINT_0 | ||
const parentBlock = await chain.getCanonicalHeadBlock() | ||
const vmCopy = await vm.shallowCopy() | ||
// Set block's gas used to max | ||
const blockBuilder = await vmCopy.buildBlock({ | ||
parentBlock, | ||
headerData: { | ||
timestamp: parentBlock.header.timestamp + BigInt(1), | ||
}, | ||
blockOpts: { | ||
calcDifficultyFromHeader: parentBlock.header, | ||
putBlockIntoBlockchain: false, | ||
}, | ||
}) | ||
for (let i = 0; i < blobsCount.length; i++) { | ||
const blobVersionedHashes = [] | ||
const blobs = [] | ||
const kzgCommitments = [] | ||
const to = Address.zero() | ||
if (blobsCount[i] > 0) { | ||
for (let blob = 0; blob < blobsCount[i]; blob++) { | ||
blobVersionedHashes.push(...blobVersionedHash) | ||
blobs.push(...sampleBlob) | ||
kzgCommitments.push(...commitment) | ||
} | ||
} | ||
await blockBuilder.addTransaction( | ||
TransactionFactory.fromTxData( | ||
{ | ||
type: 3, | ||
gasLimit: 21000, | ||
maxFeePerGas: 0xffffffff, | ||
maxPriorityFeePerGas: BIGINT_256, | ||
nonce, | ||
to, | ||
blobVersionedHashes, | ||
blobs, | ||
kzgCommitments, | ||
maxFeePerBlobGas: BigInt(1000), | ||
}, | ||
{ common: vmCopy.common } | ||
).sign(privateKey) | ||
) | ||
nonce++ | ||
} | ||
|
||
const block = await blockBuilder.build() | ||
await chain.putBlocks([block], true) | ||
await execution.run() | ||
} | ||
|
||
describe(method, () => { | ||
it('call', async () => { | ||
const kzg = await loadKZG() | ||
const { server } = await setupChain(genesisJSON, 'post-merge', { | ||
engine: true, | ||
hardfork: Hardfork.Cancun, | ||
customCrypto: { | ||
kzg, | ||
}, | ||
}) | ||
|
||
const rpc = getRpcClient(server) | ||
const res = await rpc.request(method, []) | ||
assert.equal(res.result, '0x1') | ||
}) | ||
|
||
it('call with more realistic blockchain', async () => { | ||
const kzg = await loadKZG() | ||
const { server, execution, chain } = await setupChain(genesisJSON, 'post-merge', { | ||
engine: true, | ||
hardfork: Hardfork.Cancun, | ||
customCrypto: { | ||
kzg, | ||
}, | ||
}) | ||
|
||
for (let i = 0; i < 10; i++) { | ||
await produceBlockWith4844Tx(execution, chain, [6]) | ||
} | ||
const rpc = getRpcClient(server) | ||
const res = await rpc.request(method, []) | ||
assert.equal(res.result, '0x3') | ||
}) | ||
}) |
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
Oops, something went wrong.