Skip to content
Closed
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
22 changes: 5 additions & 17 deletions packages/relay/src/lib/services/contractService/ContractService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ export class ContractService implements IContractService {
}

/**
* Processes and caches contract bytecode if it doesn't contain prohibited opcodes.
* Processes and caches contract bytecode
*
* @param {IContractResult} result - The contract result containing bytecode
* @param {string} cachedLabel - The cache key to store the bytecode
Expand All @@ -703,18 +703,19 @@ export class ContractService implements IContractService {
private async handleContractBytecode(
result: IContractResult,
cachedLabel: string,
blockNumber: string | null,
requestDetails: RequestDetails,
): Promise<string | null> {
if (result?.entity.runtime_bytecode !== CommonService.emptyHex) {
if (!this.hasProhibitedOpcodes(result.entity.runtime_bytecode)) {
if (blockNumber !== 'latest') {
await this.cacheService.set(
cachedLabel,
result.entity.runtime_bytecode,
CommonService.ethGetCode,
requestDetails,
);
return result.entity.runtime_bytecode;
}
return result.entity.runtime_bytecode;
}
return null;
}
Expand Down Expand Up @@ -912,19 +913,6 @@ export class ContractService implements IContractService {
return `${ContractService.redirectBytecodePrefix}${address.slice(2)}${ContractService.redirectBytecodePostfix}`;
}

/**
* Checks if the provided bytecode contains any prohibited EVM opcodes.
*
* @param {string} bytecode - The bytecode to check
* @returns {boolean} True if prohibited opcodes are found, false otherwise
* @private
*/
private hasProhibitedOpcodes(bytecode: string): boolean {
const prohibitedOpcodes = ['CALLCODE', 'DELEGATECALL', 'SELFDESTRUCT', 'SUICIDE'];
const opcodes = disassemble(bytecode);
return opcodes.filter((opcode) => prohibitedOpcodes.indexOf(opcode.opcode.mnemonic) > -1).length > 0;
}

/**
* Checks if the address is the HTS precompile address.
*
Expand Down Expand Up @@ -1134,7 +1122,7 @@ export class ContractService implements IContractService {
}

if (result.type === constants.TYPE_CONTRACT) {
return await this.handleContractBytecode(result, cachedLabel, requestDetails);
return await this.handleContractBytecode(result, cachedLabel, blockNumber, requestDetails);
}

return null;
Expand Down