Skip to content

Commit

Permalink
Merge branch 'main' into pr/1665
Browse files Browse the repository at this point in the history
  • Loading branch information
Trivo25 committed Jun 8, 2024
2 parents cd0964d + c573569 commit 18944e4
Show file tree
Hide file tree
Showing 27 changed files with 1,640 additions and 259 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,25 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

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

### Added

- `Experimental.IndexedMerkleMap`, a better primitive for Merkleized storage which uses 4-8x fewer constraints than `MerkleMap` https://github.com/o1-labs/o1js/pull/1666
- In contrast to `MerkleTree` and `MerkleMap`, `IndexedMerkleMap` has a high-level API that can be used in provable code.

### Deprecated

- `Int64.isPositive()` and `Int64.mod()` deprecated because they behave incorrectly on `-0` https://github.com/o1-labs/o1js/pull/1660
- This can pose an attack surface, since it is easy to maliciously pick either the `+0` or the `-0` representation
- Use `Int64.isPositiveV2()` and `Int64.modV2()` instead
- Also deprecated `Int64.neg()` in favor of `Int64.negV2()`, for compatibility with v2 version of `Int64` that will use `Int64.checkV2()`
- `Ecdsa.verify()` and `Ecdsa.verifySignedHash()` deprecated in favor of `Ecdsa.verifyV2()` and `Ecdsa.verifySignedHashV2()` due to a security vulnerability found in the current implementation https://github.com/o1-labs/o1js/pull/1669

## [1.3.0](https://github.com/o1-labs/o1js/compare/6a1012162...54d6545bf)

### Added

- Added `base64Encode()` and `base64Decode(byteLength)` methods to the `Bytes` class. https://github.com/o1-labs/o1js/pull/1659
- Added `Ecdsa.verifyV2()` and `Ecdsa.verifySignedHashV2` methods to the `Ecdsa` class. https://github.com/o1-labs/o1js/pull/1669

### Fixes

Expand Down
4 changes: 2 additions & 2 deletions src/examples/crypto/ecdsa/ecdsa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const keccakAndEcdsa = ZkProgram({
verifyEcdsa: {
privateInputs: [Ecdsa.provable, Secp256k1.provable],
async method(message: Bytes32, signature: Ecdsa, publicKey: Secp256k1) {
return signature.verify(message, publicKey);
return signature.verifyV2(message, publicKey);
},
},
},
Expand All @@ -38,7 +38,7 @@ const ecdsa = ZkProgram({
verifySignedHash: {
privateInputs: [Ecdsa.provable, Secp256k1.provable],
async method(message: Scalar, signature: Ecdsa, publicKey: Secp256k1) {
return signature.verifySignedHash(message, publicKey);
return signature.verifySignedHashV2(message, publicKey);
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions src/examples/zkapps/voting/run-berkeley.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import {
import { getResults, vote } from './voting-lib.js';

const Berkeley = Mina.Network({
mina: 'https://proxy.berkeley.minaexplorer.com/graphql',
archive: 'https://archive-node-api.p42.xyz/',
mina: 'https://api.minascan.io/node/devnet/v1/graphql',
archive: 'https://api.minascan.io/archive/devnet/v1/graphql',
});
Mina.setActiveInstance(Berkeley);

Expand Down
9 changes: 9 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ export { Gadgets } from './lib/provable/gadgets/gadgets.js';
export { Types } from './bindings/mina-transaction/types.js';

export { MerkleList, MerkleListIterator } from './lib/provable/merkle-list.js';
import {
IndexedMerkleMap,
IndexedMerkleMapBase,
} from './lib/provable/merkle-tree-indexed.js';
export { Option } from './lib/provable/option.js';

export * as Mina from './lib/mina/mina.js';
Expand Down Expand Up @@ -133,6 +137,7 @@ export { Experimental };

const Experimental_ = {
memoizeWitness,
IndexedMerkleMap,
};

/**
Expand All @@ -142,6 +147,10 @@ const Experimental_ = {
namespace Experimental {
export let memoizeWitness = Experimental_.memoizeWitness;

// indexed merkle map
export let IndexedMerkleMap = Experimental_.IndexedMerkleMap;
export type IndexedMerkleMap = IndexedMerkleMapBase;

// offchain state
export let OffchainState = OffchainState_.OffchainState;

Expand Down
20 changes: 9 additions & 11 deletions src/lib/mina/actions/offchain-contract.unit-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
SmartContract,
method,
Mina,
State,
state,
PublicKey,
UInt64,
Expand All @@ -12,23 +11,22 @@ import assert from 'assert';

const proofsEnabled = true;

const { OffchainState, OffchainStateCommitments } = Experimental;
const { OffchainState } = Experimental;

const offchainState = OffchainState({
accounts: OffchainState.Map(PublicKey, UInt64),
totalSupply: OffchainState.Field(UInt64),
});
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 {
// TODO could have sugar for this like
// @OffchainState.commitment offchainState = OffchainState.Commitment();
@state(OffchainStateCommitments) offchainState = State(
OffchainStateCommitments.empty()
);
@state(OffchainState.Commitments) offchainState = offchainState.commitments();

@method
async createAccount(address: PublicKey, amountToMint: UInt64) {
Expand Down
Loading

0 comments on commit 18944e4

Please sign in to comment.