Skip to content

Commit e8ff671

Browse files
committed
accumulate logs into an ivc contract for advance proofing capabilities
1 parent e9c6f58 commit e8ff671

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

packages/util/src/ssz.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,3 +452,12 @@ export const BlockHeader = new StableContainerType(
452452
MAX_BLOCKHEADER_FIELDS,
453453
{ typeName: 'BlockHeader', jsonCase: 'eth2' },
454454
)
455+
456+
export const IVCEntry = new ContainerType(
457+
{
458+
prevTopicRoot: Bytes32,
459+
number: Uint64,
460+
logRoot: Bytes32,
461+
},
462+
{ typeName: 'IVCEntry', jsonCase: 'eth2' },
463+
)

packages/vm/src/params.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,9 @@ export const paramsVM: ParamsDict = {
8989
systemAddress: '0xfffffffffffffffffffffffffffffffffffffffe', // The system address to perform operations on the consolidation requests predeploy address
9090
consolidationRequestPredeployAddress: '0x00b42dbF2194e931E80326D950320f7d9Dbeac02', // Address of the consolidations contract
9191
},
92+
6493: {
93+
systemAddress: '0xfffffffffffffffffffffffffffffffffffffffe', // The system address to perform operations on the consolidation requests predeploy address
94+
// dummu address right now as actual will be determined with the deployment of ivc contract
95+
ivcPredeployAddress: '0x' + '6493'.repeat(10),
96+
},
9297
}

packages/vm/src/runTx.ts

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
BIGINT_0,
99
BIGINT_1,
1010
KECCAK256_NULL,
11+
bigIntToAddressBytes,
1112
bytesToBigInt,
1213
bytesToHex,
1314
bytesToUnprefixedHex,
@@ -17,10 +18,13 @@ import {
1718
hexToBytes,
1819
publicToAddress,
1920
short,
21+
ssz,
2022
} from '@ethereumjs/util'
2123
import debugDefault from 'debug'
2224
import { keccak256 } from 'ethereum-cryptography/keccak.js'
2325

26+
import { setLengthLeft } from '../../util/src/bytes.js'
27+
2428
import { Bloom } from './bloom/index.js'
2529
import { emitEVMProfile } from './emitEVMProfile.js'
2630

@@ -37,7 +41,7 @@ import type {
3741
import type { VM } from './vm.js'
3842
import type { Block } from '@ethereumjs/block'
3943
import type { Common } from '@ethereumjs/common'
40-
import type { EVM } from '@ethereumjs/evm'
44+
import type { EVM, Log } from '@ethereumjs/evm'
4145
import type {
4246
AccessList,
4347
AccessList2930Transaction,
@@ -741,6 +745,10 @@ async function _runTx(vm: VM, opts: RunTxOpts): Promise<RunTxResult> {
741745
blobGasPrice,
742746
)
743747

748+
if (vm.common.isActivatedEIP(6493)) {
749+
await accumulateIVCLogs(vm, block?.header.number ?? DEFAULT_HEADER.number, results.receipt.logs)
750+
}
751+
744752
if (enableProfiler) {
745753
// eslint-disable-next-line no-console
746754
console.timeEnd(receiptsLabel)
@@ -766,6 +774,43 @@ async function _runTx(vm: VM, opts: RunTxOpts): Promise<RunTxResult> {
766774
return results
767775
}
768776

777+
async function accumulateIVCLogs(vm: VM, number: bigint, logs: Log[]) {
778+
const ivcContractAddress = new Address(
779+
bigIntToAddressBytes(vm.common.param('withdrawalRequestPredeployAddress')),
780+
)
781+
782+
if ((await vm.stateManager.getAccount(ivcContractAddress)) === undefined) {
783+
// store with nonce of 1 to prevent 158 cleanup
784+
const ivcContract = new Account()
785+
ivcContract.nonce = BIGINT_1
786+
await vm.stateManager.putAccount(ivcContractAddress, ivcContract)
787+
}
788+
789+
for (const log of logs) {
790+
const sszLog = {
791+
address: log[0],
792+
topics: log[1],
793+
data: log[2],
794+
}
795+
796+
const logRoot = ssz.Log.hashTreeRoot(sszLog)
797+
for (const topic of sszLog.topics) {
798+
// should be 32 bytes but 0 bytes in case value doesn't exist so just left pad
799+
const prevTopicRoot = setLengthLeft(
800+
await vm.stateManager.getStorage(ivcContractAddress, topic),
801+
32,
802+
)
803+
const newTopicRoot = ssz.IVCEntry.hashTreeRoot({
804+
prevTopicRoot,
805+
number,
806+
logRoot,
807+
})
808+
809+
await vm.stateManager.putStorage(ivcContractAddress, topic, newTopicRoot)
810+
}
811+
}
812+
}
813+
769814
/**
770815
* @method txLogsBloom
771816
* @private

0 commit comments

Comments
 (0)