Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: kaustinen7 verkle testnet preparation #3433

Merged
merged 18 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions packages/block/src/block/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ export class Block {
// undefined indicates that the executionWitness should be initialized with the default state
if (this.common.isActivatedEIP(6800) && this.executionWitness === undefined) {
this.executionWitness = {
// TODO: Evaluate how default parentStateRoot should be handled?
parentStateRoot: '0x',
stateDiff: [],
verkleProof: {
commitmentsByPath: [],
Expand Down
3 changes: 3 additions & 0 deletions packages/block/src/from-beacon-payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,18 @@ type VerkleStateDiffSnakeJson = {
}

type VerkleExecutionWitnessSnakeJson = {
parent_state_root: PrefixedHexString
state_diff: VerkleStateDiffSnakeJson[]
verkle_proof: VerkleProofSnakeJson
}

function parseExecutionWitnessFromSnakeJson({
parent_state_root,
state_diff,
verkle_proof,
}: VerkleExecutionWitnessSnakeJson): VerkleExecutionWitness {
return {
parentStateRoot: parent_state_root,
stateDiff: state_diff.map(({ stem, suffix_diffs }) => ({
stem,
suffixDiffs: suffix_diffs.map(({ current_value, new_value, suffix }) => ({
Expand Down
6 changes: 0 additions & 6 deletions packages/client/bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,12 +474,6 @@ const args: ClientOpts = yargs
boolean: true,
hidden: true,
})
.option('initialVerkleStateRoot', {
describe:
'Provides an initial stateRoot to start the StatelessVerkleStateManager. This is required to bootstrap verkle witness proof verification, since they depend on the stateRoot of the parent block',
string: true,
coerce: (initialVerkleStateRoot: PrefixedHexString) => hexToBytes(initialVerkleStateRoot),
})
.option('useJsCrypto', {
describe: 'Use pure Javascript cryptography functions',
boolean: true,
Expand Down
3 changes: 0 additions & 3 deletions packages/client/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,6 @@ export interface ConfigOptions {
statelessVerkle?: boolean
startExecution?: boolean
ignoreStatelessInvalidExecs?: boolean
initialVerkleStateRoot?: Uint8Array

/**
* Enables Prometheus Metrics that can be collected for monitoring client health
Expand Down Expand Up @@ -451,7 +450,6 @@ export class Config {
public readonly statelessVerkle: boolean
public readonly startExecution: boolean
public readonly ignoreStatelessInvalidExecs: boolean
public readonly initialVerkleStateRoot: Uint8Array

public synchronized: boolean
public lastSynchronized?: boolean
Expand Down Expand Up @@ -545,7 +543,6 @@ export class Config {
this.ignoreStatelessInvalidExecs = options.ignoreStatelessInvalidExecs ?? false

this.metrics = options.prometheusMetrics
this.initialVerkleStateRoot = options.initialVerkleStateRoot ?? new Uint8Array()

// Start it off as synchronized if this is configured to mine or as single node
this.synchronized = this.isSingleNode ?? this.mine
Expand Down
1 change: 0 additions & 1 deletion packages/client/src/execution/vmexecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ export class VMExecution extends Execution {
this.config.logger.info(`Setting up verkleVM`)
const verkleCrypto = await loadVerkleCrypto()
const stateManager = new StatelessVerkleStateManager({
initialStateRoot: this.config.initialVerkleStateRoot,
verkleCrypto,
})
await mcl.init(mcl.BLS12_381)
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export interface StateManagerInterface {
executionWitness?: VerkleExecutionWitness | null,
accessWitness?: AccessWitnessInterface,
): void
verifyVerkleProof?(stateRoot: Uint8Array): boolean
verifyVerkleProof?(): boolean
verifyPostState?(): boolean
checkChunkWitnessPresent?(contract: Address, programCounter: number): Promise<boolean>
getAppliedKey?(address: Uint8Array): Uint8Array // only for preimages
Expand Down
4 changes: 2 additions & 2 deletions packages/evm/scripts/stackDeltaGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class OpcodeInfo {
opcode: number,
inputs: number,
outputs: number,
opSize: number
opSize: number,
) {
return this.parse(instr, opcode, inputs, outputs, opSize)
}
Expand All @@ -16,7 +16,7 @@ class OpcodeInfo {
opcode: number,
inputs: number,
outputs: number,
opSize: number
opSize: number,
) {
return this.parse(instr, opcode, inputs, outputs, opSize)
}
Expand Down
42 changes: 8 additions & 34 deletions packages/evm/src/opcodes/gas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import {
BIGINT_31,
BIGINT_32,
BIGINT_64,
VERKLE_BALANCE_LEAF_KEY,
VERKLE_BASIC_DATA_LEAF_KEY,
VERKLE_CODE_HASH_LEAF_KEY,
VERKLE_CODE_SIZE_LEAF_KEY,
VERKLE_VERSION_LEAF_KEY,
bigIntToBytes,
getVerkleTreeIndexesForStorageSlot,
setLengthLeft,
Expand Down Expand Up @@ -95,7 +93,7 @@ export const dynamicGasHandlers: Map<number, AsyncDynamicGasHandler | SyncDynami
const coldAccessGas = runState.env.accessWitness!.touchAddressOnReadAndComputeGas(
address,
0,
VERKLE_BALANCE_LEAF_KEY,
VERKLE_BASIC_DATA_LEAF_KEY,
)

gas += coldAccessGas
Expand Down Expand Up @@ -165,12 +163,7 @@ export const dynamicGasHandlers: Map<number, AsyncDynamicGasHandler | SyncDynami
coldAccessGas += runState.env.accessWitness!.touchAddressOnReadAndComputeGas(
address,
0,
VERKLE_VERSION_LEAF_KEY,
)
coldAccessGas += runState.env.accessWitness!.touchAddressOnReadAndComputeGas(
address,
0,
VERKLE_CODE_SIZE_LEAF_KEY,
VERKLE_BASIC_DATA_LEAF_KEY,
)

gas += coldAccessGas
Expand Down Expand Up @@ -203,12 +196,7 @@ export const dynamicGasHandlers: Map<number, AsyncDynamicGasHandler | SyncDynami
coldAccessGas += runState.env.accessWitness!.touchAddressOnReadAndComputeGas(
address,
0,
VERKLE_VERSION_LEAF_KEY,
)
coldAccessGas += runState.env.accessWitness!.touchAddressOnReadAndComputeGas(
address,
0,
VERKLE_CODE_SIZE_LEAF_KEY,
VERKLE_BASIC_DATA_LEAF_KEY,
)

gas += coldAccessGas
Expand Down Expand Up @@ -1026,45 +1014,31 @@ export const dynamicGasHandlers: Map<number, AsyncDynamicGasHandler | SyncDynami

let selfDestructToCharge2929Gas = true
if (common.isActivatedEIP(6800)) {
// read accesses for version and code size
if (runState.interpreter._evm.getPrecompile(contractAddress) === undefined) {
gas += runState.env.accessWitness!.touchAddressOnReadAndComputeGas(
contractAddress,
0,
VERKLE_VERSION_LEAF_KEY,
)
gas += runState.env.accessWitness!.touchAddressOnReadAndComputeGas(
contractAddress,
0,
VERKLE_CODE_SIZE_LEAF_KEY,
)
}

gas += runState.env.accessWitness!.touchAddressOnReadAndComputeGas(
contractAddress,
0,
VERKLE_BALANCE_LEAF_KEY,
VERKLE_BASIC_DATA_LEAF_KEY,
)
if (balance > BIGINT_0) {
gas += runState.env.accessWitness!.touchAddressOnWriteAndComputeGas(
contractAddress,
0,
VERKLE_BALANCE_LEAF_KEY,
VERKLE_BASIC_DATA_LEAF_KEY,
)
}

let selfDestructToColdAccessGas =
runState.env.accessWitness!.touchAddressOnReadAndComputeGas(
selfdestructToAddress,
0,
VERKLE_BALANCE_LEAF_KEY,
VERKLE_BASIC_DATA_LEAF_KEY,
)
if (balance > BIGINT_0) {
selfDestructToColdAccessGas +=
runState.env.accessWitness!.touchAddressOnWriteAndComputeGas(
selfdestructToAddress,
0,
VERKLE_BALANCE_LEAF_KEY,
VERKLE_BASIC_DATA_LEAF_KEY,
)
}

Expand Down
38 changes: 10 additions & 28 deletions packages/statemanager/src/accessWitness.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import {
BIGINT_0,
VERKLE_BALANCE_LEAF_KEY,
VERKLE_BASIC_DATA_LEAF_KEY,
VERKLE_CODE_HASH_LEAF_KEY,
VERKLE_CODE_OFFSET,
VERKLE_CODE_SIZE_LEAF_KEY,
VERKLE_HEADER_STORAGE_OFFSET,
VERKLE_MAIN_STORAGE_OFFSET,
VERKLE_NODE_WIDTH,
VERKLE_NONCE_LEAF_KEY,
VERKLE_VERSION_LEAF_KEY,
bytesToBigInt,
bytesToHex,
getVerkleKey,
Expand Down Expand Up @@ -89,79 +86,64 @@ export class AccessWitness implements AccessWitnessInterface {
touchAndChargeProofOfAbsence(address: Address): bigint {
let gas = BIGINT_0

gas += this.touchAddressOnReadAndComputeGas(address, 0, VERKLE_VERSION_LEAF_KEY)
gas += this.touchAddressOnReadAndComputeGas(address, 0, VERKLE_BALANCE_LEAF_KEY)
gas += this.touchAddressOnReadAndComputeGas(address, 0, VERKLE_CODE_SIZE_LEAF_KEY)
gas += this.touchAddressOnReadAndComputeGas(address, 0, VERKLE_BASIC_DATA_LEAF_KEY)
gas += this.touchAddressOnReadAndComputeGas(address, 0, VERKLE_CODE_HASH_LEAF_KEY)
gas += this.touchAddressOnReadAndComputeGas(address, 0, VERKLE_NONCE_LEAF_KEY)

return gas
}

touchAndChargeMessageCall(address: Address): bigint {
let gas = BIGINT_0

gas += this.touchAddressOnReadAndComputeGas(address, 0, VERKLE_VERSION_LEAF_KEY)
gas += this.touchAddressOnReadAndComputeGas(address, 0, VERKLE_CODE_SIZE_LEAF_KEY)
gas += this.touchAddressOnReadAndComputeGas(address, 0, VERKLE_BASIC_DATA_LEAF_KEY)

return gas
}

touchAndChargeValueTransfer(caller: Address, target: Address): bigint {
let gas = BIGINT_0

gas += this.touchAddressOnWriteAndComputeGas(caller, 0, VERKLE_BALANCE_LEAF_KEY)
gas += this.touchAddressOnWriteAndComputeGas(target, 0, VERKLE_BALANCE_LEAF_KEY)
gas += this.touchAddressOnWriteAndComputeGas(caller, 0, VERKLE_BASIC_DATA_LEAF_KEY)
gas += this.touchAddressOnWriteAndComputeGas(target, 0, VERKLE_BASIC_DATA_LEAF_KEY)

return gas
}

touchAndChargeContractCreateInit(address: Address): bigint {
let gas = BIGINT_0

gas += this.touchAddressOnWriteAndComputeGas(address, 0, VERKLE_VERSION_LEAF_KEY)
gas += this.touchAddressOnWriteAndComputeGas(address, 0, VERKLE_NONCE_LEAF_KEY)
gas += this.touchAddressOnWriteAndComputeGas(address, 0, VERKLE_BASIC_DATA_LEAF_KEY)

return gas
}

touchAndChargeContractCreateCompleted(address: Address): bigint {
let gas = BIGINT_0

gas += this.touchAddressOnWriteAndComputeGas(address, 0, VERKLE_VERSION_LEAF_KEY)
gas += this.touchAddressOnWriteAndComputeGas(address, 0, VERKLE_BALANCE_LEAF_KEY)
gas += this.touchAddressOnWriteAndComputeGas(address, 0, VERKLE_CODE_SIZE_LEAF_KEY)
gas += this.touchAddressOnWriteAndComputeGas(address, 0, VERKLE_BASIC_DATA_LEAF_KEY)
gas += this.touchAddressOnWriteAndComputeGas(address, 0, VERKLE_CODE_HASH_LEAF_KEY)
gas += this.touchAddressOnWriteAndComputeGas(address, 0, VERKLE_NONCE_LEAF_KEY)

return gas
}

touchTxOriginAndComputeGas(origin: Address): bigint {
let gas = BIGINT_0

gas += this.touchAddressOnReadAndComputeGas(origin, 0, VERKLE_VERSION_LEAF_KEY)
gas += this.touchAddressOnReadAndComputeGas(origin, 0, VERKLE_CODE_SIZE_LEAF_KEY)
gas += this.touchAddressOnReadAndComputeGas(origin, 0, VERKLE_BASIC_DATA_LEAF_KEY)
gas += this.touchAddressOnReadAndComputeGas(origin, 0, VERKLE_CODE_HASH_LEAF_KEY)

gas += this.touchAddressOnWriteAndComputeGas(origin, 0, VERKLE_NONCE_LEAF_KEY)
gas += this.touchAddressOnWriteAndComputeGas(origin, 0, VERKLE_BALANCE_LEAF_KEY)

return gas
}

touchTxTargetAndComputeGas(target: Address, { sendsValue }: { sendsValue?: boolean } = {}) {
let gas = BIGINT_0

gas += this.touchAddressOnReadAndComputeGas(target, 0, VERKLE_VERSION_LEAF_KEY)
gas += this.touchAddressOnReadAndComputeGas(target, 0, VERKLE_CODE_SIZE_LEAF_KEY)
gas += this.touchAddressOnReadAndComputeGas(target, 0, VERKLE_CODE_HASH_LEAF_KEY)
gas += this.touchAddressOnReadAndComputeGas(target, 0, VERKLE_NONCE_LEAF_KEY)

if (sendsValue === true) {
gas += this.touchAddressOnWriteAndComputeGas(target, 0, VERKLE_BALANCE_LEAF_KEY)
gas += this.touchAddressOnWriteAndComputeGas(target, 0, VERKLE_BASIC_DATA_LEAF_KEY)
} else {
gas += this.touchAddressOnReadAndComputeGas(target, 0, VERKLE_BALANCE_LEAF_KEY)
gas += this.touchAddressOnReadAndComputeGas(target, 0, VERKLE_BASIC_DATA_LEAF_KEY)
}

return gas
Expand Down
Loading
Loading