-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add gate count profiling for transactions (#9632)
Part of #9299 - Added `computeGateCountForCircuit` to `bb/execute.s` and use it in `kernal_prover` to calculate gate-count per function (under a flag). - Add `dryRun` to `kernal_prover` to skip ClientIVC proof generation (useful for getting gate count without proof generation) - Add `--profile` flag to cli-wallet `simulate` command to prints the gate count per circuit, Example: <img width="888" alt="Screenshot 2024-10-31 at 9 46 10 PM" src="https://github.com/user-attachments/assets/4bbb062c-acdf-4889-aa6b-294c030b34d5"> <br/><br/> - Not reusing `ContractFunctionInteraction.simulate` as it is difficult to change its return type as its widely used. - Can also add gas estimation to simulate command (instead of `send`) so `simulate` does actual simulation of a transaction and display the full data.
- Loading branch information
Showing
14 changed files
with
271 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,40 @@ | ||
import { type AccountWalletWithSecretKey, type AztecAddress, Contract } from '@aztec/aztec.js'; | ||
import { type AccountWalletWithSecretKey, type AztecAddress, Contract, type ProfileResult } from '@aztec/aztec.js'; | ||
import { prepTx } from '@aztec/cli/utils'; | ||
import { type LogFn } from '@aztec/foundation/log'; | ||
|
||
import { format } from 'util'; | ||
|
||
function printProfileResult(result: ProfileResult, log: LogFn) { | ||
log(format('Simulation result:')); | ||
log(format('Return value: ', JSON.stringify(result.returnValues, null, 2))); | ||
|
||
log(format('Gate count: ')); | ||
let acc = 0; | ||
result.gateCounts.forEach(r => { | ||
acc += r.gateCount; | ||
log(format(' ', r.circuitName.padEnd(30), 'Gates:', r.gateCount, '\tAcc:', acc)); | ||
}); | ||
} | ||
|
||
export async function simulate( | ||
wallet: AccountWalletWithSecretKey, | ||
functionName: string, | ||
functionArgsIn: any[], | ||
contractArtifactPath: string, | ||
contractAddress: AztecAddress, | ||
profile: boolean, | ||
log: LogFn, | ||
) { | ||
const { functionArgs, contractArtifact } = await prepTx(contractArtifactPath, functionName, functionArgsIn, log); | ||
|
||
const contract = await Contract.at(contractAddress, contractArtifact, wallet); | ||
const call = contract.methods[functionName](...functionArgs); | ||
|
||
const result = await call.simulate(); | ||
log(format('\nSimulation result: ', result, '\n')); | ||
if (profile) { | ||
const result = await call.simulateWithProfile(); | ||
printProfileResult(result, log); | ||
} else { | ||
const result = await call.simulate(); | ||
log(format('\nSimulation result: ', result, '\n')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.