Skip to content

Commit

Permalink
Merge pull request #1612 from o1-labs/benchmark/txn-construction
Browse files Browse the repository at this point in the history
Benchmark transaction construction time.
  • Loading branch information
shimkiv committed Apr 24, 2024
2 parents ea199ef + 32c70e3 commit d53f926
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 1 deletion.
2 changes: 1 addition & 1 deletion benchmark/benchmarks/ecdsa.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* ECDSA benchmark
* ECDSA benchmarks
*/

import { Provable } from 'o1js';
Expand Down
92 changes: 92 additions & 0 deletions benchmark/benchmarks/transaction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/**
* Transaction benchmarks
*/

import {
AccountUpdate,
Field,
Mina,
PrivateKey,
SmartContract,
State,
method,
state,
} from 'o1js';
import { benchmark } from '../benchmark.js';

export { TxnBenchmarks };

class SimpleZkapp extends SmartContract {
@state(Field) x = State<Field>();

init() {
super.init();
this.x.set(Field(1));
}

@method async noOp() {}

@method async update(y: Field) {
const x = this.x.getAndRequireEquals();
this.x.set(x.add(y));
}
}

let Local = await Mina.LocalBlockchain({
proofsEnabled: true,
enforceTransactionLimits: true,
});
Mina.setActiveInstance(Local);

const transactionFee = 100_000_000;
const [feePayer] = Local.testAccounts;
const { verificationKey } = await SimpleZkapp.compile();

let transaction;

const TxnBenchmarks = benchmark(
'txn',
async (tic, toc) => {
const zkappPrivateKey = PrivateKey.random();
const zkapp = new SimpleZkapp(zkappPrivateKey.toPublicKey());

tic('simple zkapp deploy transaction construction');
transaction = await Mina.transaction(
{ sender: feePayer, fee: transactionFee },
async () => {
AccountUpdate.fundNewAccount(feePayer);
await zkapp.deploy({ verificationKey });
}
);
toc();

tic('simple zkapp deploy transaction signing');
transaction.sign([feePayer.key, zkappPrivateKey]);
toc();

tic('simple zkapp deploy transaction local sending');
await transaction.send();
toc();

tic('simple zkapp call transaction construction');
transaction = await Mina.transaction(
{ sender: feePayer, fee: transactionFee },
async () => await zkapp.noOp()
);
toc();

tic('simple zkapp call transaction proving');
await transaction.prove();
toc();

tic('simple zkapp call transaction signing');
transaction.sign([feePayer.key]);
toc();

tic('simple zkapp call transaction local sending');
await transaction.send();
toc();
},
// two warmups to ensure full caching
{ numberOfWarmups: 2, numberOfRuns: 5 }
);
2 changes: 2 additions & 0 deletions benchmark/runners/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@

import { initializeBindings } from 'o1js';
import { EcdsaBenchmarks } from '../benchmarks/ecdsa.js';
import { TxnBenchmarks } from '../benchmarks/transaction.js';
import { processAndLogBenchmarkResults } from '../utils/result-utils.js';

const results = [];
await initializeBindings();

// Run benchmarks and collect results
results.push(...(await EcdsaBenchmarks.run()));
results.push(...(await TxnBenchmarks.run()));

// Process and log results
await processAndLogBenchmarkResults(results);

0 comments on commit d53f926

Please sign in to comment.