Skip to content

Commit

Permalink
feat: Show bytecode size per function in CLI inspect-contract (#5059)
Browse files Browse the repository at this point in the history
Useful for debugging which functions are the worst offenders when we
exceed maximum contract size.
  • Loading branch information
spalladino authored Mar 7, 2024
1 parent f2fdefd commit cb9fdc6
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion yarn-project/cli/src/cmds/inspect_contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
decodeFunctionSignature,
decodeFunctionSignatureWithParameterNames,
} from '@aztec/foundation/abi';
import { sha256 } from '@aztec/foundation/crypto';
import { DebugLogger, LogFn } from '@aztec/foundation/log';

import { getContractArtifact } from '../utils.js';
Expand Down Expand Up @@ -34,7 +35,9 @@ function logFunction(fn: FunctionArtifact, log: LogFn) {
const signatureWithParameterNames = decodeFunctionSignatureWithParameterNames(fn.name, fn.parameters);
const signature = decodeFunctionSignature(fn.name, fn.parameters);
const selector = FunctionSelector.fromSignature(signature);
const bytecodeSize = Buffer.from(fn.bytecode, 'base64').length;
const bytecodeHash = sha256(Buffer.from(fn.bytecode, 'base64')).toString('hex');
log(
`${fn.functionType} ${signatureWithParameterNames} \n\tfunction signature: ${signature}\n\tselector: ${selector}`,
`${fn.functionType} ${signatureWithParameterNames} \n\tfunction signature: ${signature}\n\tselector: ${selector}\n\tbytecode: ${bytecodeSize} bytes (sha256 ${bytecodeHash})`,
);
}

0 comments on commit cb9fdc6

Please sign in to comment.