From d9685e89063dc7e65aa5f2f45098ee49a6ec8a0c Mon Sep 17 00:00:00 2001 From: Serhii Shymkiv Date: Mon, 15 Apr 2024 18:10:03 +0300 Subject: [PATCH] Limit the network kind support for the local ledger. --- CHANGELOG.md | 1 + src/lib/mina/local-blockchain.ts | 16 ++++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 49361303f6..dd07f2d931 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Add assertion to the foreign EC addition gadget that prevents degenerate cases https://github.com/o1-labs/o1js/pull/1545 - Fixes soundness of ECDSA; slightly increases its constraints from ~28k to 29k - Breaks circuits that used EC addition, like ECDSA +- `Mina.LocalBlockchain` no longer supports the network kind configuration https://github.com/o1-labs/o1js/pull/1581 ### Changes diff --git a/src/lib/mina/local-blockchain.ts b/src/lib/mina/local-blockchain.ts index 0d600332b5..6d24d859e3 100644 --- a/src/lib/mina/local-blockchain.ts +++ b/src/lib/mina/local-blockchain.ts @@ -38,25 +38,29 @@ import { verifyTransactionLimits, verifyAccountUpdate, } from './transaction-validation.js'; +import { prettifyStacktrace } from '../util/errors.js'; export { LocalBlockchain }; + /** * A mock Mina blockchain running locally and useful for testing. */ function LocalBlockchain({ proofsEnabled = true, enforceTransactionLimits = true, - networkId = 'testnet' as NetworkId, } = {}) { const slotTime = 3 * 60 * 1000; const startTime = Date.now(); const genesisTimestamp = UInt64.from(startTime); const ledger = Ledger.create(); let networkState = defaultNetworkState(); - let minaNetworkId: NetworkId = networkId; function addAccount(publicKey: PublicKey, balance: string) { - ledger.addAccount(Ml.fromPublicKey(publicKey), balance); + try { + ledger.addAccount(Ml.fromPublicKey(publicKey), balance); + } catch (error) { + throw prettifyStacktrace(error); + } } let testAccounts: { @@ -80,7 +84,7 @@ function LocalBlockchain({ > = {}; return { - getNetworkId: () => minaNetworkId, + getNetworkId: () => 'testnet' as NetworkId, proofsEnabled, getNetworkConstants() { return { @@ -121,7 +125,7 @@ function LocalBlockchain({ let zkappCommandJson = ZkappCommand.toJSON(txn.transaction); let commitments = transactionCommitments( TypesBigint.ZkappCommand.fromJSON(zkappCommandJson), - minaNetworkId + this.getNetworkId() ); if (enforceTransactionLimits) verifyTransactionLimits(txn.transaction); @@ -302,7 +306,7 @@ function LocalBlockchain({ }, transaction(sender: FeePayerSpec, f: () => Promise) { return toTransactionPromise(async () => { - // TODO we run the transaction twice to match the behaviour of `Network.transaction` + // TODO we run the transaction twice to match the behavior of `Network.transaction` let tx = await createTransaction(sender, f, 0, { isFinalRunOutsideCircuit: false, proofsEnabled: this.proofsEnabled,