-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
revert absolute import path and update CI flow
- Loading branch information
Showing
19 changed files
with
1,980 additions
and
1,239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ node_modules | |
build | ||
coverage | ||
.husky | ||
.yml | ||
|
||
# Editor | ||
.vscode | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,62 @@ | ||
import { Bool, Field, Poseidon, Scalar, Struct } from 'o1js'; | ||
|
||
export class CustomScalar extends Struct({ | ||
head: Field, | ||
tail: Field, | ||
head: Field, | ||
tail: Field, | ||
}) { | ||
static fromScalar(scalar: Scalar): CustomScalar { | ||
let bits = scalar.toFields().map((e) => Bool.fromFields([e])); | ||
return new CustomScalar({ | ||
head: Field.fromBits(bits.slice(0, 127)), | ||
tail: Field.fromBits(bits.slice(127)), | ||
}); | ||
} | ||
|
||
static fromFields(fields: Field[]): CustomScalar { | ||
return new CustomScalar({ | ||
head: fields[0], | ||
tail: fields[1], | ||
}); | ||
} | ||
|
||
static toScalar(scalar: CustomScalar): Scalar { | ||
return Scalar.fromBits( | ||
scalar.head | ||
.toBits() | ||
.slice(0, 127) | ||
.concat(scalar.tail.toBits().slice(0, 128)) | ||
); | ||
} | ||
|
||
static toFields(value: { head: Field; tail: Field }): Field[] { | ||
return [value.head].concat([value.tail]); | ||
} | ||
|
||
static sizeInFields(): number { | ||
return 2; | ||
} | ||
|
||
hash(): Field { | ||
return Poseidon.hash(this.toScalar().toFields()); | ||
} | ||
|
||
equals(s: CustomScalar): Bool { | ||
return this.head.equals(s.head).and(this.tail.equals(s.tail)); | ||
} | ||
|
||
assertEquals(s: CustomScalar): void { | ||
this.equals(s).assertTrue(); | ||
} | ||
|
||
toScalar(): Scalar { | ||
return CustomScalar.toScalar(this); | ||
} | ||
|
||
toFields(): Field[] { | ||
return CustomScalar.toFields(this); | ||
} | ||
|
||
fromFields(fields: Field[]): CustomScalar { | ||
return CustomScalar.fromFields(fields); | ||
} | ||
static fromScalar(scalar: Scalar): CustomScalar { | ||
let bits = scalar.toFields().map((e) => Bool.fromFields([e])); | ||
return new CustomScalar({ | ||
head: Field.fromBits(bits.slice(0, 127)), | ||
tail: Field.fromBits(bits.slice(127)), | ||
}); | ||
} | ||
|
||
static fromFields(fields: Field[]): CustomScalar { | ||
return new CustomScalar({ | ||
head: fields[0], | ||
tail: fields[1], | ||
}); | ||
} | ||
|
||
static toScalar(scalar: CustomScalar): Scalar { | ||
return Scalar.fromBits( | ||
scalar.head | ||
.toBits() | ||
.slice(0, 127) | ||
.concat(scalar.tail.toBits().slice(0, 128)) | ||
); | ||
} | ||
|
||
static toFields(value: { head: Field; tail: Field }): Field[] { | ||
return [value.head].concat([value.tail]); | ||
} | ||
|
||
static sizeInFields(): number { | ||
return 2; | ||
} | ||
|
||
hash(): Field { | ||
return Poseidon.hash(this.toScalar().toFields()); | ||
} | ||
|
||
equals(s: CustomScalar): Bool { | ||
return this.head.equals(s.head).and(this.tail.equals(s.tail)); | ||
} | ||
|
||
assertEquals(s: CustomScalar): void { | ||
this.equals(s).assertTrue(); | ||
} | ||
|
||
toScalar(): Scalar { | ||
return CustomScalar.toScalar(this); | ||
} | ||
|
||
toFields(): Field[] { | ||
return CustomScalar.toFields(this); | ||
} | ||
|
||
fromFields(fields: Field[]): CustomScalar { | ||
return CustomScalar.fromFields(fields); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
import { Bool, Field, Poseidon, Provable } from 'o1js'; | ||
|
||
export type HashableProvable<T> = Provable<T> & { | ||
hash(x: T): Field; | ||
equals(x: T, other: T): Bool; | ||
hash(x: T): Field; | ||
equals(x: T, other: T): Bool; | ||
}; | ||
|
||
export function hashable<T>(type: Provable<T>): HashableProvable<T> { | ||
return { | ||
...type, | ||
hash(x: T): Field { | ||
return Poseidon.hash(type.toFields(x)); | ||
}, | ||
equals(x: T, other: T): Bool { | ||
return this.hash(x).equals(this.hash(other)); | ||
}, | ||
}; | ||
return { | ||
...type, | ||
hash(x: T): Field { | ||
return Poseidon.hash(type.toFields(x)); | ||
}, | ||
equals(x: T, other: T): Bool { | ||
return this.hash(x).equals(this.hash(other)); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.