Skip to content

Commit

Permalink
Merge pull request #1581 from o1-labs/chore/local-ledger-upd
Browse files Browse the repository at this point in the history
  • Loading branch information
shimkiv committed Apr 15, 2024
2 parents b765707 + d9685e8 commit 4e36d3c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 10 additions & 6 deletions src/lib/mina/local-blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -80,7 +84,7 @@ function LocalBlockchain({
> = {};

return {
getNetworkId: () => minaNetworkId,
getNetworkId: () => 'testnet' as NetworkId,
proofsEnabled,
getNetworkConstants() {
return {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -302,7 +306,7 @@ function LocalBlockchain({
},
transaction(sender: FeePayerSpec, f: () => Promise<void>) {
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,
Expand Down

0 comments on commit 4e36d3c

Please sign in to comment.