-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1612 from o1-labs/benchmark/txn-construction
Benchmark transaction construction time.
- Loading branch information
Showing
3 changed files
with
95 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/** | ||
* ECDSA benchmark | ||
* ECDSA benchmarks | ||
*/ | ||
|
||
import { Provable } from 'o1js'; | ||
|
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 |
---|---|---|
@@ -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 } | ||
); |
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