Skip to content

Commit

Permalink
Merge branch 'main' into feature/lookup-runtime-tables
Browse files Browse the repository at this point in the history
  • Loading branch information
querolita committed Oct 18, 2024
2 parents eee88e0 + fc16ce3 commit 8145c9e
Show file tree
Hide file tree
Showing 24 changed files with 953 additions and 485 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/changelog-entry.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Check Changelog for changes
on:
pull_request:
types: [assigned, opened, synchronize, reopened, labeled, unlabeled]
branches:
- main
jobs:
Check-Changelog:
name: Check Changelog Action
runs-on: ubuntu-20.04
steps:
- uses: tarides/changelog-check-action@v2
with:
changelog: CHANGELOG.md
17 changes: 14 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ 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/450943...HEAD)
## [Unreleased](https://github.com/o1-labs/o1js/compare/f15293a69...HEAD)

### Fixes

- Decouple offchain state instances from their definitions https://github.com/o1-labs/o1js/pull/1834

## [1.9.0](https://github.com/o1-labs/o1js/compare/450943...f15293a69) - 2024-10-15

### Added

Expand All @@ -27,17 +33,22 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- ZkProgram and SmartContract now also support private inputs that are not proofs themselves, but contain proofs nested within a Struct or array
- Only `SelfProof` can still not be nested because it needs special treatment

### Fixes

- Fix verification of serialized proofs done before compiling any circuits https://github.com/o1-labs/o1js/pull/1857

## [1.8.0](https://github.com/o1-labs/o1js/compare/5006e4f...450943) - 2024-09-18

### Added

- Added `verifyEthers` method to verify Ethereum signatures using the EIP-191 message hashing standard https://github.com/o1-labs/o1js/pull/1815
- Added `verifyEthers` method to verify Ethereum signatures using the EIP-191 message hashing standard. https://github.com/o1-labs/o1js/pull/1815
- Added `fromEthers` method for parsing and converting Ethereum public keys into `ForeignCurve` points, supporting both compressed and uncompressed formats.
- Added `fromHex` method for converting hexadecimal strings into `ForeignCurve` points.

### Fixes

- Fix incorrect behavior of optional proving for zkPrograms where `myProgram.setProofsEnabled(false)` wouldn't work when called before `myProgram.compile()` https://github.com/o1-labs/o1js/pull/1827
- Fix incorrect behavior of optional proving for zkPrograms where `myProgram.setProofsEnabled(false)` wouldn't work when called before `myProgram.compile()`. https://github.com/o1-labs/o1js/pull/1827
- Fix incorrect behavior of `state.fetch()` for custom token contracts. [@rpanic](https://github.com/rpanic) https://github.com/o1-labs/o1js/pull/1853

## [1.7.0](https://github.com/o1-labs/o1js/compare/d6abf1d97...5006e4f) - 2024-09-04

Expand Down
48 changes: 31 additions & 17 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "o1js",
"description": "TypeScript framework for zk-SNARKs and zkApps",
"version": "1.8.0",
"version": "1.9.0",
"license": "Apache-2.0",
"homepage": "https://github.com/o1-labs/o1js/",
"repository": {
Expand Down Expand Up @@ -74,7 +74,7 @@
"devDependencies": {
"@influxdata/influxdb-client": "^1.33.2",
"@noble/hashes": "^1.3.2",
"@playwright/test": "^1.25.2",
"@playwright/test": "^1.48.0",
"@types/isomorphic-fetch": "^0.0.36",
"@types/jest": "^27.0.0",
"@types/node": "^18.14.2",
Expand Down
8 changes: 7 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { TupleN } from './lib/util/types.js';
export type { ProvablePure } from './lib/provable/types/provable-intf.js';
export { Ledger, initializeBindings } from './snarky.js';
export { Field, Bool, Group, Scalar } from './lib/provable/wrapped.js';
Expand Down Expand Up @@ -37,7 +38,12 @@ export type {
FlexibleProvablePure,
InferProvable,
} from './lib/provable/types/struct.js';
export { From } from './bindings/lib/provable-generic.js';
export {
From,
InferValue,
InferJson,
IsPure,
} from './bindings/lib/provable-generic.js';
export { ProvableType } from './lib/provable/types/provable-intf.js';
export {
provable,
Expand Down
89 changes: 89 additions & 0 deletions src/lib/mina/actions/offchain-contract-tests/ExampleContract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import {
SmartContract,
method,
state,
PublicKey,
UInt64,
Experimental,
} from '../../../../index.js';

export { offchainState, StateProof, ExampleContract };

const { OffchainState } = Experimental;

const offchainState = OffchainState(
{
accounts: OffchainState.Map(PublicKey, UInt64),
totalSupply: OffchainState.Field(UInt64),
},
{ logTotalCapacity: 10, maxActionsPerProof: 5 }
);

class StateProof extends offchainState.Proof {}

// example contract that interacts with offchain state
class ExampleContract extends SmartContract {
@state(OffchainState.Commitments) offchainStateCommitments =
offchainState.emptyCommitments();

// o1js memoizes the offchain state by contract address so that this pattern works
offchainState = offchainState.init(this);

@method
async createAccount(address: PublicKey, amountToMint: UInt64) {
// setting `from` to `undefined` means that the account must not exist yet
this.offchainState.fields.accounts.update(address, {
from: undefined,
to: amountToMint,
});

// TODO using `update()` on the total supply means that this method
// can only be called once every settling cycle
let totalSupplyOption = await this.offchainState.fields.totalSupply.get();
let totalSupply = totalSupplyOption.orElse(0n);

this.offchainState.fields.totalSupply.update({
from: totalSupplyOption,
to: totalSupply.add(amountToMint),
});
}

@method
async transfer(from: PublicKey, to: PublicKey, amount: UInt64) {
let fromOption = await this.offchainState.fields.accounts.get(from);
let fromBalance = fromOption.assertSome('sender account exists');

let toOption = await this.offchainState.fields.accounts.get(to);
let toBalance = toOption.orElse(0n);

/**
* Update both accounts atomically.
*
* This is safe, because both updates will only be accepted if both previous balances are still correct.
*/
this.offchainState.fields.accounts.update(from, {
from: fromOption,
to: fromBalance.sub(amount),
});

this.offchainState.fields.accounts.update(to, {
from: toOption,
to: toBalance.add(amount),
});
}

@method.returns(UInt64)
async getSupply() {
return (await this.offchainState.fields.totalSupply.get()).orElse(0n);
}

@method.returns(UInt64)
async getBalance(address: PublicKey) {
return (await this.offchainState.fields.accounts.get(address)).orElse(0n);
}

@method
async settle(proof: StateProof) {
await this.offchainState.settle(proof);
}
}
Loading

0 comments on commit 8145c9e

Please sign in to comment.