From cb9fdc6b5069ee2ab8fb1f68f369e360039fa18b Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Thu, 7 Mar 2024 16:07:35 -0300 Subject: [PATCH] feat: Show bytecode size per function in CLI inspect-contract (#5059) Useful for debugging which functions are the worst offenders when we exceed maximum contract size. --- yarn-project/cli/src/cmds/inspect_contract.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/yarn-project/cli/src/cmds/inspect_contract.ts b/yarn-project/cli/src/cmds/inspect_contract.ts index 8f102631152..a5fb4ca5263 100644 --- a/yarn-project/cli/src/cmds/inspect_contract.ts +++ b/yarn-project/cli/src/cmds/inspect_contract.ts @@ -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'; @@ -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})`, ); }