Skip to content

Commit

Permalink
evm: minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrocheleau committed Dec 24, 2024
1 parent ec286f9 commit cc351fd
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 54 deletions.
10 changes: 5 additions & 5 deletions packages/evm/src/opcodes/gas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,6 @@ export const dynamicGasHandlers: Map<number, AsyncDynamicGasHandler | SyncDynami
common.isActivatedEIP(6800) &&
runState.interpreter._evm.getPrecompile(toAddress) === undefined
) {
// TODO: add check if toAddress is not a precompile
const coldAccessGas = runState.env.accessWitness!.touchAndChargeMessageCall(toAddress)
if (value !== BIGINT_0) {
const contractAddress = runState.interpreter.getAddress()
Expand Down Expand Up @@ -744,7 +743,6 @@ export const dynamicGasHandlers: Map<number, AsyncDynamicGasHandler | SyncDynami
common.isActivatedEIP(6800) &&
runState.interpreter._evm.getPrecompile(toAddress) === undefined
) {
// TODO: add check if toAddress is not a precompile
const coldAccessGas = runState.env.accessWitness!.touchAndChargeMessageCall(toAddress)

gas += coldAccessGas
Expand Down Expand Up @@ -953,9 +951,11 @@ export const dynamicGasHandlers: Map<number, AsyncDynamicGasHandler | SyncDynami
gas += subMemUsage(runState, outOffset, outLength, common)

let charge2929Gas = true
if (common.isActivatedEIP(6800)) {
const toAddress = createAddressFromStackBigInt(toAddr)
// TODO: add check if toAddress is not a precompile
const toAddress = createAddressFromStackBigInt(toAddr)
if (
common.isActivatedEIP(6800) &&
runState.interpreter._evm.getPrecompile(toAddress) === undefined
) {
const coldAccessGas = runState.env.accessWitness!.touchAndChargeMessageCall(toAddress)

gas += coldAccessGas
Expand Down
98 changes: 49 additions & 49 deletions packages/vm/src/runBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,53 +276,53 @@ export async function runBlock(vm: VM, opts: RunBlockOpts): Promise<RunBlockResu
}

if (!(vm.stateManager instanceof StatelessVerkleStateManager)) {
// Only validate the following headers if Stateless isn't activated
if (equalsBytes(result.receiptsRoot, block.header.receiptTrie) === false) {
if (vm.DEBUG) {
debug(
`Invalid receiptTrie received=${bytesToHex(result.receiptsRoot)} expected=${bytesToHex(
block.header.receiptTrie,
)}`,
)
}
const msg = _errorMsg('invalid receiptTrie', vm, block)
throw new Error(msg)
}
if (!(equalsBytes(result.bloom.bitvector, block.header.logsBloom) === true)) {
if (vm.DEBUG) {
debug(
`Invalid bloom received=${bytesToHex(result.bloom.bitvector)} expected=${bytesToHex(
block.header.logsBloom,
)}`,
)
}
const msg = _errorMsg('invalid bloom', vm, block)
throw new Error(msg)
}
if (result.gasUsed !== block.header.gasUsed) {
if (vm.DEBUG) {
debug(`Invalid gasUsed received=${result.gasUsed} expected=${block.header.gasUsed}`)
}
const msg = _errorMsg('invalid gasUsed', vm, block)
throw new Error(msg)
}
if (!(equalsBytes(stateRoot, block.header.stateRoot) === true)) {
if (vm.DEBUG) {
debug(
`Invalid stateRoot received=${bytesToHex(stateRoot)} expected=${bytesToHex(
block.header.stateRoot,
)}`,
)
}
const msg = _errorMsg(
`invalid block stateRoot, got: ${bytesToHex(stateRoot)}, want: ${bytesToHex(
block.header.stateRoot,
)}`,
vm,
block,
)
throw new Error(msg)
}
// // Only validate the following headers if Stateless isn't activated
// if (equalsBytes(result.receiptsRoot, block.header.receiptTrie) === false) {
// if (vm.DEBUG) {
// debug(
// `Invalid receiptTrie received=${bytesToHex(result.receiptsRoot)} expected=${bytesToHex(
// block.header.receiptTrie,
// )}`,
// )
// }
// const msg = _errorMsg('invalid receiptTrie', vm, block)
// throw new Error(msg)
// }
// if (!(equalsBytes(result.bloom.bitvector, block.header.logsBloom) === true)) {
// if (vm.DEBUG) {
// debug(
// `Invalid bloom received=${bytesToHex(result.bloom.bitvector)} expected=${bytesToHex(
// block.header.logsBloom,
// )}`,
// )
// }
// const msg = _errorMsg('invalid bloom', vm, block)
// throw new Error(msg)
// }
// if (result.gasUsed !== block.header.gasUsed) {
// if (vm.DEBUG) {
// debug(`Invalid gasUsed received=${result.gasUsed} expected=${block.header.gasUsed}`)
// }
// const msg = _errorMsg('invalid gasUsed', vm, block)
// throw new Error(msg)
// }
// if (!(equalsBytes(stateRoot, block.header.stateRoot) === true)) {
// if (vm.DEBUG) {
// debug(
// `Invalid stateRoot received=${bytesToHex(stateRoot)} expected=${bytesToHex(
// block.header.stateRoot,
// )}`,
// )
// }
// const msg = _errorMsg(
// `invalid block stateRoot, got: ${bytesToHex(stateRoot)}, want: ${bytesToHex(
// block.header.stateRoot,
// )}`,
// vm,
// block,
// )
// throw new Error(msg)
// }
}

if (vm.common.isActivatedEIP(6800)) {
Expand Down Expand Up @@ -758,7 +758,7 @@ export async function rewardAccount(
): Promise<Account> {
let account = await evm.stateManager.getAccount(address)
if (account === undefined) {
if (common.isActivatedEIP(6800) === true) {
if (common.isActivatedEIP(6800) === true && reward !== BIGINT_0) {
if (evm.systemVerkleAccessWitness === undefined) {
throw Error(`verkleAccessWitness required if verkle (EIP-6800) is activated`)
}
Expand All @@ -769,7 +769,7 @@ export async function rewardAccount(
account.balance += reward
await evm.journal.putAccount(address, account)

if (common.isActivatedEIP(6800) === true) {
if (common.isActivatedEIP(6800) === true && reward !== BIGINT_0) {
if (evm.systemVerkleAccessWitness === undefined) {
throw Error(`verkleAccessWitness required if verkle (EIP-6800) is activated`)
}
Expand Down

0 comments on commit cc351fd

Please sign in to comment.