Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make MerkleTree props public #1555

Merged
merged 5 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ 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.{nodes,zeroes}` public properties https://github.com/o1-labs/o1js/pull/1555
- This makes it possible to clone merkle trees, which is often needed

### 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
Expand Down
2 changes: 1 addition & 1 deletion src/bindings
Submodule bindings updated 0 files
4 changes: 2 additions & 2 deletions src/lib/provable/merkle-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number, Record<string, Field>> = {};
private zeroes: Field[];
nodes: Record<number, Record<string, Field>> = {};
zeroes: Field[];

/**
* Creates a new, empty [Merkle Tree](https://en.wikipedia.org/wiki/Merkle_tree).
Expand Down
25 changes: 5 additions & 20 deletions src/lib/provable/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand All @@ -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);
Expand All @@ -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;
}

Expand Down Expand Up @@ -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));
}
Expand All @@ -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));
Expand Down
Loading