Skip to content

Commit

Permalink
Merge branch 'main' into test-user-types
Browse files Browse the repository at this point in the history
  • Loading branch information
harrysolovay authored Apr 15, 2024
2 parents 575096c + 4e36d3c commit fae4b9a
Show file tree
Hide file tree
Showing 30 changed files with 214 additions and 194 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- name: Build o1js and execute benchmarks on ${{ matrix.os }} and Node.JS ${{ matrix.node }}
- name: Build o1js and execute benchmarks on ${{ matrix.runners }} and Node.JS ${{ matrix.node }}
env:
GIT_BRANCH: ${{ github.head_ref || github.ref_name }}
INFLUXDB_URL: ${{ secrets.INFLUXDB_URL }}
Expand Down
57 changes: 2 additions & 55 deletions .github/workflows/live-tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test o1js against the real network
name: Test o1js against lightnet
on:
push:
branches:
Expand All @@ -13,36 +13,9 @@ on:
workflow_dispatch: {}

jobs:
main-branch:
berkeley:
timeout-minutes: 45
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' || (github.event_name == 'pull_request' && github.base_ref == 'main')
services:
mina-local-network:
image: o1labs/mina-local-network:o1js-main-latest-lightnet
env:
NETWORK_TYPE: 'single-node'
PROOF_LEVEL: 'none'
ports:
- 3085:3085
- 5432:5432
- 8080:8080
- 8181:8181
- 8282:8282
volumes:
- /tmp:/root/logs
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Use shared steps for live testing jobs
uses: ./.github/actions/live-tests-shared
with:
mina-branch-name: o1js-main

berkeley-branch:
timeout-minutes: 45
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/berkeley' || (github.event_name == 'pull_request' && github.base_ref == 'berkeley')
services:
mina-local-network:
image: o1labs/mina-local-network:berkeley-latest-lightnet
Expand All @@ -64,29 +37,3 @@ jobs:
uses: ./.github/actions/live-tests-shared
with:
mina-branch-name: berkeley

develop-branch:
timeout-minutes: 45
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/develop' || (github.event_name == 'pull_request' && github.base_ref == 'develop')
services:
mina-local-network:
image: o1labs/mina-local-network:develop-latest-lightnet
env:
NETWORK_TYPE: 'single-node'
PROOF_LEVEL: 'none'
ports:
- 3085:3085
- 5432:5432
- 8080:8080
- 8181:8181
- 8282:8282
volumes:
- /tmp:/root/logs
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Use shared steps for live testing jobs
uses: ./.github/actions/live-tests-shared
with:
mina-branch-name: develop
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,29 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
_Security_ in case of vulnerabilities.
-->

## [Unreleased](https://github.com/o1-labs/o1js/compare/1b6fd8b8e...HEAD)

### Breaking changes

- 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

- Make `MerkleTree.{nodes,zeroes}` public properties https://github.com/o1-labs/o1js/pull/1555
- This makes it possible to clone merkle trees, which is often needed

### Added

- Export `Events` under `AccountUpdate.Events`. https://github.com/o1-labs/o1js/pull/1563

### Fixed

- Fix error when computing Merkle map witnesses, introduced in the last version due to the `toBits()` change https://github.com/o1-labs/o1js/pull/1559
- Improved error message when compiling a program that has no methods. https://github.com/o1-labs/o1js/pull/1563

## [0.18.0](https://github.com/o1-labs/o1js/compare/74948acac...1b6fd8b8e) - 2024-04-09

### Breaking changes
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"snarky-run": "src/build/run.js"
},
"engines": {
"node": ">=16.4.0"
"node": ">=18.14.0"
},
"scripts": {
"dev": "npx tsc -p tsconfig.test.json && node src/build/copy-to-dist.js",
Expand Down
2 changes: 1 addition & 1 deletion run-ci-tests.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
set -e

case $TEST_TYPE in
Expand Down
2 changes: 1 addition & 1 deletion run-integration-tests.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
set -e

./run src/examples/zkapps/hello-world/run.ts --bundle
Expand Down
2 changes: 1 addition & 1 deletion run-jest-tests.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
set -e
shopt -s globstar # to expand '**' into nested directories

Expand Down
2 changes: 1 addition & 1 deletion run-minimal-mina-tests.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
set -e

npm run dev
Expand Down
2 changes: 1 addition & 1 deletion run-unit-tests.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
set -e
shopt -s globstar # to expand '**' into nested directories./

Expand Down
4 changes: 3 additions & 1 deletion src/examples/zkapps/hello-world/hello-world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import {
state,
} from 'o1js';

export const adminPrivateKey = PrivateKey.random();
export const adminPrivateKey = PrivateKey.fromBase58(
'EKFcef5HKXAn7V2rQntLiXtJr15dkxrsrQ1G4pnYemhMEAWYbkZW'
);
export const adminPublicKey = adminPrivateKey.toPublicKey();

export class HelloWorld extends SmartContract {
Expand Down
1 change: 1 addition & 0 deletions src/lib/mina/account-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ class AccountUpdate implements Types.AccountUpdate {
private isSelf: boolean;

static Actions = Actions;
static Events = Events;

constructor(body: Body, authorization?: Control);
constructor(body: Body, authorization: Control = {}, isSelf = false) {
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 @@ -39,6 +39,7 @@ import {
verifyTransactionLimits,
verifyAccountUpdate,
} from './transaction-validation.js';
import { prettifyStacktrace } from '../util/errors.js';

export { LocalBlockchain, TestPublicKey };

Expand All @@ -58,23 +59,26 @@ namespace TestPublicKey {
) as never;
}
}

/**
* 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 = [] as never as TupleN<TestPublicKey, 100>;
Expand All @@ -94,7 +98,7 @@ function LocalBlockchain({
> = {};

return {
getNetworkId: () => minaNetworkId,
getNetworkId: () => 'testnet' as NetworkId,
proofsEnabled,
getNetworkConstants() {
return {
Expand Down Expand Up @@ -135,7 +139,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 @@ -316,7 +320,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
11 changes: 7 additions & 4 deletions src/lib/mina/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,13 @@ function createState<T>(): InternalStateType<T> {
let stateAsFields = this._contract.stateType.toFields(state);
let accountUpdate = this._contract.instance.self;
stateAsFields.forEach((x, i) => {
AccountUpdate.setValue(
accountUpdate.body.update.appState[layout.offset + i],
x
);
let appStateSlot =
accountUpdate.body.update.appState[layout.offset + i];
if (!appStateSlot)
throw Error(
`Attempted to set on-chain state variable \`${this._contract?.key}\`. Currently, only a total of 8 fields elements of on-chain state are supported.`
);
AccountUpdate.setValue(appStateSlot, x);
});
},

Expand Down
5 changes: 5 additions & 0 deletions src/lib/proof-system/zkprogram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,11 @@ async function compileProgram({
forceRecompile: boolean;
overrideWrapDomain?: 0 | 1 | 2;
}) {
if (methodIntfs.length === 0)
throw Error(`The Program you are trying to compile has no methods.
Try adding a method to your ZkProgram or SmartContract.
If you are using a SmartContract, make sure you are using the @method decorator.`);

let rules = methodIntfs.map((methodEntry, i) =>
picklesRuleFromFunction(
publicInputType,
Expand Down
25 changes: 20 additions & 5 deletions src/lib/provable/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
assertSquare,
assertBoolean,
} from './gadgets/compatible.js';
import { toLinearCombination } from './gadgets/basic.js';
import { assertBilinear, toLinearCombination } from './gadgets/basic.js';
import {
FieldType,
FieldVar,
Expand All @@ -29,6 +29,7 @@ import {
lessThanFull,
lessThanOrEqualFull,
} from './gadgets/comparison.js';
import { toVar } from './gadgets/common.js';

// external API
export { Field };
Expand Down Expand Up @@ -218,7 +219,7 @@ class Field {
}

/**
* Add a "field-like" value to this {@link Field} element.
* Add a field-like value to this {@link Field} element.
*
* @example
* ```ts
Expand Down Expand Up @@ -768,6 +769,16 @@ class Field {
}
// inv() proves that a field element is non-zero, using 1 constraint.
// so this takes 1-2 generic gates, while x.equals(y).assertTrue() takes 3-5
if (isConstant(y)) {
// custom single generic gate for (x - y) * z = 1
// TODO remove once assertMul() handles these cases
let x = toVar(this);
let y0 = toFp(y);
let z = existsOne(() => Fp.inverse(this.toBigInt() - y0) ?? 0n);
// 1*x*z + 0*x + (-y)*z + (-1) = 0
assertBilinear(x, z, [1n, 0n, -y0, -1n]);
return;
}
this.sub(y).inv();
} catch (err) {
throw withMessage(err, message);
Expand Down Expand Up @@ -874,12 +885,12 @@ class Field {
*
* @return A {@link Field} element that is equal to the result of AST that was previously on this {@link Field} element.
*/
seal() {
seal(): VarField | ConstantField {
let { constant, terms } = toLinearCombination(this.value);
if (terms.length === 0) return new Field(constant);
if (terms.length === 0) return ConstantField(constant);
if (terms.length === 1 && constant === 0n) {
let [c, x] = terms[0];
if (c === 1n) return new Field(x);
if (c === 1n) return VarField(x);
}
let x = existsOne(() => this.toBigInt());
this.assertEquals(x);
Expand Down Expand Up @@ -1226,3 +1237,7 @@ Warning: whatever happens inside asProver() will not be part of the zk proof.
function VarField(x: VarFieldVar): VarField {
return new Field(x) as VarField;
}

function ConstantField(x: ConstantFieldVar | bigint): ConstantField {
return new Field(x) as ConstantField;
}
Loading

0 comments on commit fae4b9a

Please sign in to comment.