Skip to content

Commit

Permalink
wip: synthesizer handler
Browse files Browse the repository at this point in the history
  • Loading branch information
SonYoungsung committed Jan 8, 2025
1 parent e6a23aa commit d7db793
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
5 changes: 5 additions & 0 deletions packages/frontend/synthesizer/src/opcodes/codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import type { CustomOpcode } from '../types.js'
import type { OpHandler } from './functions.js'
import type { AsyncDynamicGasHandler, SyncDynamicGasHandler } from './gas.js'
import type { Common } from '@ethereumjs/common'
import { SynthesizerHandler } from './synthesizer/types.js'
import { synthesizerHandlers } from './synthesizer/handlers.js'
export class Opcode {
readonly code: number
readonly name: string
Expand Down Expand Up @@ -411,6 +413,7 @@ export type OpcodeMapEntry = {
opcodeInfo: Opcode
opHandler: OpHandler
gasHandler: AsyncDynamicGasHandler | SyncDynamicGasHandler
synthesizerHandler: SynthesizerHandler
subcircuit: SubcircuitCode | undefined
}
export type OpcodeMap = OpcodeMapEntry[]
Expand Down Expand Up @@ -504,11 +507,13 @@ export function getOpcodesForHF(common: Common, customOpcodes?: CustomOpcode[]):
for (const [opNumber, op] of ops) {
const dynamicGas = dynamicGasHandlersCopy.get(opNumber)!
const handler = handlersCopy.get(opNumber)!
const synthesizerHandler = synthesizerHandlers.get(opNumber)!
const subcircuitCode = subcircuits.find((entry) => parseInt(entry.opcode, 16) === opNumber)
opcodeMap[opNumber] = {
opcodeInfo: op,
opHandler: handler,
gasHandler: dynamicGas,
synthesizerHandler,
subcircuit: subcircuitCode
? {
subcircuitId: subcircuitCode.id,
Expand Down
11 changes: 1 addition & 10 deletions packages/frontend/synthesizer/src/opcodes/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,8 @@ import { keccak256 } from 'ethereum-cryptography/keccak.js'

import { EOFContainer, EOFContainerMode } from '../eof/container.js'
import { EOFError } from '../eof/errors.js'
import { EOFBYTES, EOFHASH, isEOF } from '../eof/util.js'
import { isEOF } from '../eof/util.js'
import { ERROR } from '../exceptions.js'
import {
prepareEXTCodePt,
synthesizerArith,
synthesizerBlkInf,
synthesizerEnvInf,
} from '../tokamak/core/synthesizer.js'
import { copyMemoryRegion, simulateMemoryPt } from '../tokamak/pointers/index.js'
import { DELEGATION_7702_FLAG } from '../types.js'

import {
Expand All @@ -48,15 +41,13 @@ import {
exponentiation,
fromTwos,
getDataSlice,
jumpIsValid,
mod,
toTwos,
trap,
writeCallOutput,
} from './util.js'

import type { RunState } from '../interpreter.js'
import type { MemoryPtEntry, MemoryPts } from '../tokamak/pointers/index.js'
import type { Common } from '@ethereumjs/common'

export interface SyncOpHandler {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import { mod, fromTwos, toTwos } from "../util.js"
import {
synthesizerArith,
synthesizerEnvInf,
synthesizerBlkInf
synthesizerBlkInf,
prepareEXTCodePt
} from "../../tokamak/core/synthesizer.js"
import { copyMemoryRegion, simulateMemoryPt } from "../../tokamak/pointers/index.js"
import { BIGINT_0, BIGINT_1 } from "@ethereumjs/util"



export const synthesizerHandlers = new Map([
// 0x01: ADD
[0x01, async function (runState: RunState) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { RunState } from "../../interpreter.js";

export type SynthesizerHandler = (runState: RunState) => Promise<void>
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export async function synthesizerEnvInf(
target?: bigint,
offset?: bigint,
): Promise<void> {
// Environment information을 Stack에 load하는 경우만 다룹니다. 그 외의 경우 (~COPY)는 functionst.ts에서 직접 처리 합니다.
// Environment information을 Stack에 load하는 경우만 다룹니다. 그 외의 경우 (~COPY)는 functions.ts에서 직접 처리 합니다.
let dataPt: DataPt
switch (op) {
case 'CALLDATALOAD': {
Expand Down

0 comments on commit d7db793

Please sign in to comment.