Skip to content

Commit

Permalink
compute empty account update hash lazily
Browse files Browse the repository at this point in the history
  • Loading branch information
mitschabaude committed Apr 10, 2024
1 parent 3852aeb commit 336513c
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/lib/provable/packed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,19 +186,18 @@ class Hashed<T> {
} {
let _hash = hash ?? ((t: T) => Poseidon.hashPacked(type, t));

let dummyHash = _hash(type.empty());

return class Hashed_ extends Hashed<T> {
static _innerProvable = type;
static _provable = provableFromClass(Hashed_, {
hash: modifiedField({ empty: () => dummyHash }),
hash: modifiedField({ empty: () => _hash(type.empty()) }),
value: Unconstrained.provable,
}) as ProvableHashable<Hashed<T>>;

static _hash = _hash satisfies (t: T) => Field;

static empty(): Hashed<T> {
return new this(dummyHash, Unconstrained.from(type.empty()));
let empty = type.empty();
return new this(_hash(empty), Unconstrained.from(empty));
}

static get provable() {
Expand Down

0 comments on commit 336513c

Please sign in to comment.