Skip to content

Improve eth_getCode caching strategy when bytecode contains "prohibited opcode" #3634

@acuarica

Description

@acuarica

The current implementation of eth_getCode does not cache the result when bytecode contains "prohibited opcodes"

const prohibitedOpcodes = ['CALLCODE', 'DELEGATECALL', 'SELFDESTRUCT', 'SUICIDE'];
const opcodes = asm.disassemble(result?.entity.runtime_bytecode);
const hasProhibitedOpcode =
opcodes.filter((opcode) => prohibitedOpcodes.indexOf(opcode.opcode.mnemonic) > -1).length > 0;
if (!hasProhibitedOpcode) {
await this.cacheService.set(
cachedLabel,
result?.entity.runtime_bytecode,
EthImpl.ethGetCode,
requestDetails,
);
return result?.entity.runtime_bytecode;
}

This was initially put in place because some of these opcodes might change indeed the bytecode at a given address. However, the cache label already takes into account the blockNumber

const cachedLabel = `getCode.${address}.${blockNumber}`;

so these opcodes shouldn't affect the result.

Improve caching strategy for eth_getCode when blockNumber is not latest.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions