From c9237866adcb3dba9e6e43eccbb2735083a948ed Mon Sep 17 00:00:00 2001 From: Gregor Date: Wed, 10 Apr 2024 17:39:03 +0200 Subject: [PATCH 1/4] make parts of merkle tree public --- src/lib/provable/merkle-tree.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/provable/merkle-tree.ts b/src/lib/provable/merkle-tree.ts index 69236a3fda..d818d9af6e 100644 --- a/src/lib/provable/merkle-tree.ts +++ b/src/lib/provable/merkle-tree.ts @@ -26,8 +26,8 @@ type Witness = { isLeft: boolean; sibling: Field }[]; * Levels are indexed from leaves (level 0) to root (level N - 1). */ class MerkleTree { - private nodes: Record> = {}; - private zeroes: Field[]; + nodes: Record> = {}; + zeroes: Field[]; /** * Creates a new, empty [Merkle Tree](https://en.wikipedia.org/wiki/Merkle_tree). From 46ada72f41e115c2d1f08c4870085c1f935c9fcc Mon Sep 17 00:00:00 2001 From: Gregor Date: Wed, 10 Apr 2024 17:40:28 +0200 Subject: [PATCH 2/4] make circuit string methods public --- src/lib/provable/string.ts | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/src/lib/provable/string.ts b/src/lib/provable/string.ts index b5a85878a8..c07ddde593 100644 --- a/src/lib/provable/string.ts +++ b/src/lib/provable/string.ts @@ -36,6 +36,7 @@ class Character extends CircuitValue { } } +// TODO support other maxLengths class CircuitString extends CircuitValue { static maxLength = DEFAULT_STRING_LENGTH; @arrayProp(Character, DEFAULT_STRING_LENGTH) values: Character[]; @@ -51,12 +52,12 @@ class CircuitString extends CircuitValue { return new CircuitString(fillWithNull(chars, this.maxLength)); } - private maxLength() { + maxLength() { return (this.constructor as typeof CircuitString).maxLength; } // some O(n) computation that should be only done once in the circuit - private computeLengthAndMask() { + computeLengthAndMask() { let n = this.values.length; // length is the actual, dynamic length let length = Field(0); @@ -75,10 +76,10 @@ class CircuitString extends CircuitValue { (this as any)._mask = mask; return { mask, length }; } - private lengthMask(): Bool[] { + lengthMask(): Bool[] { return (this as any)._mask ?? this.computeLengthAndMask().mask; } - private length(): Field { + length(): Field { return (this as any)._length ?? this.computeLengthAndMask().length; } @@ -112,16 +113,6 @@ class CircuitString extends CircuitValue { return CircuitString.fromCharacters(result); } - // TODO - /** - * returns true if `str` is found in this `CircuitString` - */ - // contains(str: CircuitString): Bool { - // // only succeed if the dynamic length is smaller - // let otherLength = str.length(); - // otherLength.assertLessThan(this.length()); - // } - hash(): Field { return Poseidon.hash(this.values.map((x) => x.value)); } @@ -146,12 +137,6 @@ class CircuitString extends CircuitValue { } } -// TODO -// class CircuitString8 extends CircuitString { -// static maxLength = 8; -// @arrayProp(Character, 8) values: Character[] = []; -// } - // note: this used to be a custom class, which doesn't work // NullCharacter must use the same circuits as normal Characters let NullCharacter = () => new Character(Field(0)); From 7077cd3c49b7f4548305ac7d34878c132cb0ef43 Mon Sep 17 00:00:00 2001 From: Gregor Date: Wed, 10 Apr 2024 17:41:15 +0200 Subject: [PATCH 3/4] changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 278fc15440..7c9906797c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Fixes soundness of ECDSA; slightly increases its constraints from ~28k to 29k - Breaks circuits that used EC addition, like ECDSA +### Changes + +- Make `MerkleTree` data properties public + ## [0.18.0](https://github.com/o1-labs/o1js/compare/74948acac...1b6fd8b8e) - 2024-04-09 ### Breaking changes From 56b525688d4091a7b5482b939d64db16081cd24e Mon Sep 17 00:00:00 2001 From: Gregor Date: Wed, 10 Apr 2024 17:45:04 +0200 Subject: [PATCH 4/4] changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c9906797c..d146fd7676 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,7 +25,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Changes -- Make `MerkleTree` data properties public +- 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 ## [0.18.0](https://github.com/o1-labs/o1js/compare/74948acac...1b6fd8b8e) - 2024-04-09