Skip to content

Commit 12f5180

Browse files
committed
the current set of hacks
1 parent d4c56ec commit 12f5180

File tree

7 files changed

+198
-2
lines changed

7 files changed

+198
-2
lines changed

packages/common/src/eips.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,4 +470,7 @@ export const eipsDict: EIPsDict = {
470470
minimumHardfork: Hardfork.Chainstart,
471471
requiredEIPs: [2935],
472472
},
473+
9999: {
474+
minimumHardfork: Hardfork.Cancun,
475+
},
473476
}

packages/evm/src/evm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export class EVM implements EVMInterface {
184184
const supportedEIPs = [
185185
663, 1153, 1559, 2537, 2565, 2718, 2929, 2930, 2935, 3198, 3529, 3540, 3541, 3607, 3651, 3670,
186186
3855, 3860, 4200, 4399, 4750, 4788, 4844, 4895, 5133, 5450, 5656, 6110, 6206, 6780, 6800,
187-
7002, 7069, 7251, 7480, 7516, 7620, 7685, 7691, 7692, 7698, 7702, 7709,
187+
7002, 7069, 7251, 7480, 7516, 7620, 7685, 7691, 7692, 7698, 7702, 7709, 9999,
188188
]
189189

190190
for (const eip of this.common.eips()) {

packages/evm/src/params.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,4 +409,11 @@ export const paramsEVM: ParamsDict = {
409409
eofcreateGas: 32000, // Base fee of the EOFCREATE opcode (Same as CREATE/CREATE2)
410410
returncontractGas: 0, // Base fee of the RETURNCONTRACT opcode
411411
},
412+
9999: {
413+
/* Not an actual EIP, but a placeholder for future EXECUTE precompile EIP */
414+
// gasPrices
415+
executeGasCost: 50000,
416+
executeCumulativeGasLimit: 10000000,
417+
executeCumulativeGasTarget: 100000,
418+
},
412419
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { StatelessVerkleStateManager } from '@ethereumjs/statemanager'
2+
3+
import { createEVM } from '../constructors.js'
4+
import { EvmErrorResult, OOGResult } from '../evm.js'
5+
import { ERROR, EvmError } from '../exceptions.js'
6+
7+
import { gasLimitCheck } from './util.js'
8+
9+
import { getPrecompileName } from './index.js'
10+
11+
import type { ExecResult } from '../types.js'
12+
import type { PrecompileInput } from './types.js'
13+
14+
export function precompile12(opts: PrecompileInput): ExecResult {
15+
const pName = getPrecompileName('12')
16+
const data = opts.data
17+
18+
const gasUsed = opts.common.param('executeGasCost')
19+
if (!gasLimitCheck(opts, gasUsed, pName)) {
20+
return OOGResult(opts.gasLimit)
21+
}
22+
23+
if (data.length < 128) {
24+
return EvmErrorResult(new EvmError(ERROR.INVALID_INPUT_LENGTH), opts.gasLimit)
25+
}
26+
27+
const preStateRoot = data.subarray(0, 32) // prestateroot for L2 state
28+
const postStateRoot = data.subarray(32, 64) // post state root for L2 state
29+
const trace = data.subarray(64, 96) // reference to state access and
30+
const executeGasUsed = data.subarray(96)
31+
32+
const executionResult = true
33+
34+
const stateManager = new StatelessVerkleStateManager({ common: opts.common })
35+
const evm = createEVM({ stateManager, common: opts.common })
36+
37+
opts._debug?.(`${pName} trace executed successfully=${executionResult}`)
38+
39+
const returnValue = executionResult ? new Uint8Array(1).fill(1) : new Uint8Array(1).fill(0)
40+
41+
return {
42+
executionGasUsed: gasUsed,
43+
returnValue,
44+
}
45+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { Common, Hardfork, Mainnet } from '@ethereumjs/common'
2+
import { StatelessVerkleStateManager } from '@ethereumjs/statemanager'
3+
import { createTx, createTxFromRLP } from '@ethereumjs/tx'
4+
import { trustedSetup } from '@paulmillr/trusted-setups/fast.js'
5+
import { hexToBytes } from 'ethereum-cryptography/utils'
6+
import { KZG as microEthKZG } from 'micro-eth-signer/kzg'
7+
import * as verkle from 'micro-eth-signer/verkle'
8+
import { assert, describe, it } from 'vitest'
9+
10+
import { createEVM, getActivePrecompiles } from '../../src/index.js'
11+
12+
import witness from './executionWitness.json'
13+
14+
describe('Precompiles: EXECUTE', () => {
15+
it('should execute a trace', async () => {
16+
const kzg = new microEthKZG(trustedSetup)
17+
const common = new Common({
18+
chain: Mainnet,
19+
hardfork: Hardfork.Prague,
20+
eips: [6800, 9999],
21+
customCrypto: {
22+
kzg,
23+
verkle,
24+
},
25+
})
26+
const stateManager = new StatelessVerkleStateManager({ common })
27+
stateManager.initVerkleExecutionWitness(1n, witness.witness)
28+
const evm = await createEVM({ stateManager, common })
29+
const txs = witness.txs.map((tx) => createTxFromRLP(hexToBytes(tx), { common }))
30+
for (const tx of txs) {
31+
const res = await evm.runCall(tx)
32+
console.log(res)
33+
}
34+
const addressStr = '0000000000000000000000000000000000000012'
35+
const EXECUTE = getActivePrecompiles(common).get(addressStr)!
36+
37+
const result = await EXECUTE({})
38+
})
39+
})
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
{
2+
"witness": {
3+
"stateDiff": [
4+
{
5+
"stem": "0x0365b079a274a1808d56484ce5bd97914629907d75767f51439102e22cd50d",
6+
"suffixDiffs": [
7+
{
8+
"suffix": 0,
9+
"currentValue": "0x00000000000000000000000000000000000000000000003635c9adc5dea00000",
10+
"newValue": "0x00000000000000000000000000000001000000000000003635c9adc5de9ccbb0"
11+
},
12+
{
13+
"suffix": 1,
14+
"currentValue": "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470",
15+
"newValue": null
16+
}
17+
]
18+
},
19+
{
20+
"stem": "0x5b5fdfedd6a0e932da408ac7d772a36513d1eee9b9926e52620c43a433aad7",
21+
"suffixDiffs": [
22+
{
23+
"suffix": 64,
24+
"newValue": "0x00b2e892fbf04dcdbb33d71633d7cea0722aed27f8a9d0cf9912f97b34f9dadd",
25+
"currentValue": null
26+
}
27+
]
28+
},
29+
{
30+
"stem": "0x914ec5f0e0c27fe094862fbd89a6abe684939af6940434d8bf218cedb2d624",
31+
"suffixDiffs": [
32+
{
33+
"suffix": 0,
34+
"newValue": "0x000000000000000000000000000000000000000000000000000000000000f618",
35+
"currentValue": null
36+
},
37+
{
38+
"suffix": 1,
39+
"newValue": "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470",
40+
"currentValue": null
41+
}
42+
]
43+
},
44+
{
45+
"stem": "0xecb505156708480caf702cd85124f67f3ed78ae4bc890a6dcb62574ba9a90c",
46+
"suffixDiffs": [
47+
{
48+
"suffix": 0,
49+
"currentValue": null,
50+
"newValue": null
51+
},
52+
{
53+
"suffix": 1,
54+
"currentValue": null,
55+
"newValue": null
56+
}
57+
]
58+
}
59+
],
60+
"verkleProof": {
61+
"otherStems": [],
62+
"depthExtensionPresent": "0x0a0a0808",
63+
"commitmentsByPath": [
64+
"0x360bcc4c15a10f6f058d1d07e13e9a271da3da0cd69026d5a9ab25e1c0a5d697",
65+
"0x324e7b7405bbfae46866bad5c94ac2983093b86f85035fe5984ec40a1b5e5ce3",
66+
"0x61506c1cc4f27c9231a546a4b0d249d5f3ba4ba9e63c5ebb84087665eb396e95",
67+
"0x4909fc1889e10819cda41706a26373145c4e4575d68b96569af12db69040b6e1"
68+
],
69+
"d": "0x530b7b926f178a1ce3fb92922303111735f9e5395f041b8d2b6089dbf9a73c31",
70+
"ipaProof": {
71+
"cl": [
72+
"0x3d87ee7a9da30dba329f168f203cff8690921bf51e03edeb439ccd838abf68af",
73+
"0x5ddc74d79bedcd053f53432f873bebceff9acb5e9eb1c55b7b2228c40fab1e9b",
74+
"0x67eacc9c3d3cf158686d0196256d9b858d00aede48fe7d74345628fa43e2f423",
75+
"0x3a4ee7713b54286822dd4250fe7713ff89bd73f5dd25a8850cb95813df63bdf7",
76+
"0x5341f88ef80898f8550f70466b363626c0e5a4749159e24acb4f7b1fade6e1d6",
77+
"0x18d2a1b99473a3a8f94bb9032e2a30e9f303bc37950fc0f67cb62825f42808ac",
78+
"0x56a7d7f239c132fd999991d2de37bdbc88b0edc780b61e132fd5e57986d20edf",
79+
"0x0bab046e2e62e4c51f807df783f9dc3bef37a943c0dfcf01ec0bc9733f144a38"
80+
],
81+
"cr": [
82+
"0x27e8b165e814dd45d7c628e1f3dcb31b50b0c1818f87cacf2c041b1e42abe5bd",
83+
"0x71dc9a4412d0ae3ce105f16d772c62cefbe7088673b523496b37bf16c303dffd",
84+
"0x0baed508372a64eca49e8e9cc379b848bedd37d040ac683ccde28debac3793ca",
85+
"0x6b96bfb4b9c044137613dc62be2ab377b31fb93a587742bca109525726799b84",
86+
"0x0b26a2aa70fe810cadf1d7cf47b7823ede1a4129fdc714c7b8bee60e01d6d0e9",
87+
"0x4ae3cd3a9e08425363ca98dce1f264e3cd2fd81a92758a372f412547017dd57e",
88+
"0x44ecde38a0a3e046352cac96b63602a73381308fce1c0900197273fe14ab615d",
89+
"0x28bf63a6e0aa789d798fd116fb29e3820aefff43aaa5226c28985871ee519f81"
90+
],
91+
"finalEvaluation": "0x00095c56030aeac61ba23e9468ddf059f5b2dac95af6a13e78720c44ca7c4ed7"
92+
}
93+
},
94+
"parentStateRoot": "0x3901899f4bfd31a5d77611f70c4eb98cffdbbe5280fba656631f04336afe6f5a"
95+
},
96+
"txs": [
97+
"0xf861800a8405f5e100948a0a19589531694250d570040a0c4b74576919b8808025a050ae258f0b1f7c44e5227b43c338aa7f2d9805115b90a6baeaaee2358796e074a00ec910ad0244580c17e1d6a512b3574c62e92840184109e3037760d39b20cb94"
98+
]
99+
}

packages/vm/src/runBlock.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ export async function runBlock(vm: VM, opts: RunBlockOpts): Promise<RunBlockResu
191191
await vm.evm.journal.commit()
192192
}
193193

194+
console.log(block.transactions.map((tx) => bytesToHex(tx.serialize())))
194195
// Checkpoint state
195196
await vm.evm.journal.checkpoint()
196197
if (vm.DEBUG) {
@@ -354,6 +355,8 @@ export async function runBlock(vm: VM, opts: RunBlockOpts): Promise<RunBlockResu
354355
requests,
355356
}
356357

358+
console.log(vm.evm.verkleAccessWitness)
359+
console.log(block.transactions)
357360
const afterBlockEvent: AfterBlockEvent = { ...results, block }
358361

359362
/**
@@ -522,7 +525,7 @@ export async function accumulateParentBlockHash(
522525
if (!vm.common.isActivatedEIP(2935)) {
523526
throw new Error('Cannot call `accumulateParentBlockHash`: EIP 2935 is not active')
524527
}
525-
const historyAddress = new Address(bigIntToAddressBytes(vm.common.param('historyStorageAddress')))
528+
const historyAddress = new Address(bigIntToAddressBytes(vm.common.param('systemAddress')))
526529
const historyServeWindow = vm.common.param('historyServeWindow')
527530

528531
// getAccount with historyAddress will throw error as witnesses are not bundled

0 commit comments

Comments
 (0)