Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
eb9ef75
common,util,tx: implement aip 6493 stable container txs
g11tech Jun 13, 2024
73d9dca
update and proagate ssz signature scheme as well as authroization list
g11tech Oct 4, 2024
8fc90ca
check and remove an invalid failing spec test
g11tech Oct 4, 2024
a624dae
impl ssz receipts and dev modify the receipts rooting work
g11tech Oct 5, 2024
e9c6f58
debug and fix the client 6493 end to end spec test
g11tech Oct 5, 2024
e8ff671
accumulate logs into an ivc contract for advance proofing capabilities
g11tech Oct 5, 2024
6e53fce
add ivc spec test in end to end client spec and debug and fix it
g11tech Oct 5, 2024
1292329
modify the ivc accumulator code for smartcontract comaptible compute …
g11tech Oct 9, 2024
a2d598f
move the log accumulation to post executions
g11tech Oct 9, 2024
0238872
move the ivc log processing to pre 7685 to allow adding transfer logs…
g11tech Oct 9, 2024
a45d884
add and process systemslogs root to header for allowing system logs v…
g11tech Oct 14, 2024
223ce1a
debug and fix issues introduced by systemlogs field and fix the 6493 …
g11tech Oct 14, 2024
b410d3d
add log for the combined miner/priority reward and debug/fix/validate…
g11tech Oct 15, 2024
f6f5ad8
simplify log based on discussion with etan and make changes
g11tech Oct 15, 2024
f60853e
remove console trace
g11tech Oct 17, 2024
61935e7
update ssz to stablecontainer released version
g11tech Oct 17, 2024
8821e70
fix missing sz update
g11tech Oct 17, 2024
e2bf0bc
propagate, serve and save system logs and modify, debug and fix clien…
g11tech Oct 21, 2024
f4b31d6
add systemlogs root
g11tech Nov 3, 2024
cd9b75c
add transfer logs
g11tech Nov 6, 2024
1383b1e
generate and add receipt proof to jsonrpc api
g11tech Nov 7, 2024
2617e81
added and verified receipt proof check in the test
g11tech Nov 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/block/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"tsc": "../../config/cli/ts-compile.sh"
},
"dependencies": {
"@chainsafe/ssz": "^0.18.0",
"@ethereumjs/common": "^4.4.0",
"@ethereumjs/rlp": "^5.0.2",
"@ethereumjs/mpt": "^6.2.2",
Expand Down
44 changes: 20 additions & 24 deletions packages/block/src/block/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { keccak256 } from 'ethereum-cryptography/keccak.js'
// TODO: See if there is an easier way to achieve the same result.
// See: https://github.com/microsoft/TypeScript/issues/47558
// (situation will eventually improve on Typescript and/or Eslint update)
import { genTransactionsSszRoot, genWithdrawalsSszRoot } from '../helpers.js'
import {
genRequestsTrieRoot,
genTransactionsTrieRoot,
Expand Down Expand Up @@ -226,10 +227,9 @@ export class Block {
* Generates transaction trie for validation.
*/
async genTxTrie(): Promise<Uint8Array> {
return genTransactionsTrieRoot(
this.transactions,
new MerklePatriciaTrie({ common: this.common }),
)
return this.common.isActivatedEIP(6493)
? genTransactionsSszRoot(this.transactions)
: genTransactionsTrieRoot(this.transactions, new MerklePatriciaTrie({ common: this.common }))
}

/**
Expand All @@ -238,16 +238,10 @@ export class Block {
* @returns True if the transaction trie is valid, false otherwise
*/
async transactionsTrieIsValid(): Promise<boolean> {
let result
if (this.transactions.length === 0) {
result = equalsBytes(this.header.transactionsTrie, KECCAK256_RLP)
return result
}

if (this.cache.txTrieRoot === undefined) {
this.cache.txTrieRoot = await this.genTxTrie()
}
result = equalsBytes(this.cache.txTrieRoot, this.header.transactionsTrie)
const result = equalsBytes(this.cache.txTrieRoot, this.header.transactionsTrie)
return result
}

Expand Down Expand Up @@ -367,7 +361,9 @@ export class Block {
}

if (!(await this.transactionsTrieIsValid())) {
const msg = this._errorMsg('invalid transaction trie')
const msg = this._errorMsg(
`invalid transaction trie expected=${bytesToHex(this.cache.txTrieRoot!)}`,
)
throw new Error(msg)
}

Expand Down Expand Up @@ -456,6 +452,12 @@ export class Block {
return equalsBytes(this.keccakFunction(raw), this.header.uncleHash)
}

async genWithdrawalsTrie(): Promise<Uint8Array> {
return this.common.isActivatedEIP(6493)
? genWithdrawalsSszRoot(this.withdrawals!)
: genWithdrawalsTrieRoot(this.withdrawals!, new MerklePatriciaTrie({ common: this.common }))
}

/**
* Validates the withdrawal root
* @returns true if the withdrawals trie root is valid, false otherwise
Expand All @@ -465,19 +467,10 @@ export class Block {
throw new Error('EIP 4895 is not activated')
}

let result
if (this.withdrawals!.length === 0) {
result = equalsBytes(this.header.withdrawalsRoot!, KECCAK256_RLP)
return result
}

if (this.cache.withdrawalsTrieRoot === undefined) {
this.cache.withdrawalsTrieRoot = await genWithdrawalsTrieRoot(
this.withdrawals!,
new MerklePatriciaTrie({ common: this.common }),
)
this.cache.withdrawalsTrieRoot = await this.genWithdrawalsTrie()
}
result = equalsBytes(this.cache.withdrawalsTrieRoot, this.header.withdrawalsRoot!)
const result = equalsBytes(this.cache.withdrawalsTrieRoot, this.header.withdrawalsRoot!)
return result
}

Expand Down Expand Up @@ -546,7 +539,9 @@ export class Block {
toExecutionPayload(): ExecutionPayload {
const blockJSON = this.toJSON()
const header = blockJSON.header!
const transactions = this.transactions.map((tx) => bytesToHex(tx.serialize())) ?? []
const transactions = this.common.isActivatedEIP(6493)
? this.transactions.map((tx) => tx.toExecutionPayloadTx())
: this.transactions.map((tx) => bytesToHex(tx.serialize()))
const withdrawalsArr = blockJSON.withdrawals ? { withdrawals: blockJSON.withdrawals } : {}

const executionPayload: ExecutionPayload = {
Expand Down Expand Up @@ -574,6 +569,7 @@ export class Block {
depositRequests: this.common.isActivatedEIP(6110) ? [] : undefined,
withdrawalRequests: this.common.isActivatedEIP(7002) ? [] : undefined,
consolidationRequests: this.common.isActivatedEIP(7251) ? [] : undefined,
systemLogsRoot: this.common.isActivatedEIP(6493) ? header.systemLogsRoot : undefined,
}

if (this.requests !== undefined) {
Expand Down
46 changes: 34 additions & 12 deletions packages/block/src/block/constructors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
type TxOptions,
createTx,
createTxFromBlockBodyData,
createTxFromExecutionPayloadTx,
createTxFromRLP,
normalizeTxParams,
} from '@ethereumjs/tx'
Expand All @@ -25,7 +26,13 @@ import {
} from '@ethereumjs/util'

import { generateCliqueBlockExtraData } from '../consensus/clique.js'
import { genRequestsTrieRoot, genTransactionsTrieRoot, genWithdrawalsTrieRoot } from '../helpers.js'
import {
genRequestsTrieRoot,
genTransactionsSszRoot,
genTransactionsTrieRoot,
genWithdrawalsSszRoot,
genWithdrawalsTrieRoot,
} from '../helpers.js'
import {
Block,
createBlockHeader,
Expand All @@ -46,6 +53,7 @@ import type {
RequestsBytes,
WithdrawalsBytes,
} from '../types.js'
import type { Common } from '@ethereumjs/common'
import type { TypedTransaction } from '@ethereumjs/tx'
import type {
CLRequest,
Expand Down Expand Up @@ -373,7 +381,7 @@ export const createBlockFromJSONRPCProvider = async (
*/
export async function createBlockFromExecutionPayload(
payload: ExecutionPayload,
opts?: BlockOptions,
opts: BlockOptions & { common: Common },
): Promise<Block> {
const {
blockNumber: number,
Expand All @@ -389,25 +397,39 @@ export async function createBlockFromExecutionPayload(
} = payload

const txs = []
for (const [index, serializedTx] of transactions.entries()) {
for (const [index, serializedTxOrPayload] of transactions.entries()) {
try {
const tx = createTxFromRLP(hexToBytes(serializedTx as PrefixedHexString), {
common: opts?.common,
})
let tx
if (opts.common.isActivatedEIP(6493)) {
if (typeof serializedTxOrPayload === 'string') {
throw Error('EIP 6493 activated for transaction bytes')
}
tx = createTxFromExecutionPayloadTx(serializedTxOrPayload, {
common: opts?.common,
})
} else {
if (typeof serializedTxOrPayload !== 'string') {
throw Error('EIP 6493 not activated for transaction payload')
}
tx = createTxFromRLP(hexToBytes(serializedTxOrPayload as PrefixedHexString), {
common: opts?.common,
})
}
txs.push(tx)
} catch (error) {
const validationError = `Invalid tx at index ${index}: ${error}`
throw validationError
}
}

const transactionsTrie = await genTransactionsTrieRoot(
txs,
new MerklePatriciaTrie({ common: opts?.common }),
)
const transactionsTrie = opts.common.isActivatedEIP(6493)
? await genTransactionsSszRoot(txs)
: await genTransactionsTrieRoot(txs, new MerklePatriciaTrie({ common: opts?.common }))
const withdrawals = withdrawalsData?.map((wData) => createWithdrawal(wData))
const withdrawalsRoot = withdrawals
? await genWithdrawalsTrieRoot(withdrawals, new MerklePatriciaTrie({ common: opts?.common }))
? opts.common.isActivatedEIP(6493)
? genWithdrawalsSszRoot(withdrawals)
: await genWithdrawalsTrieRoot(withdrawals, new MerklePatriciaTrie({ common: opts?.common }))
: undefined

const hasDepositRequests = depositRequests !== undefined && depositRequests !== null
Expand Down Expand Up @@ -481,7 +503,7 @@ export async function createBlockFromExecutionPayload(
*/
export async function createBlockFromBeaconPayloadJSON(
payload: BeaconPayloadJSON,
opts?: BlockOptions,
opts: BlockOptions & { common: Common },
): Promise<Block> {
const executionPayload = executionPayloadFromBeaconPayload(payload)
return createBlockFromExecutionPayload(executionPayload, opts)
Expand Down
Loading