-
Notifications
You must be signed in to change notification settings - Fork 133
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
Encode how to map provables to normal values #1271
Conversation
@@ -71,6 +71,7 @@ function inCompileMode() { | |||
|
|||
function asProver(f: () => void) { | |||
if (inCheckedComputation()) { | |||
// TODO make this start a "witness block" context |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make an issue and reference it to the comment to tackle later? (if you don't mind, of course)
I'd like to see more issues in TODO comments like this to make it easier to pick up :D
fromValue(symbol: string | TokenSymbol) { | ||
if (typeof symbol !== 'string') return symbol; | ||
let bytesLength = new TextEncoder().encode(symbol).length; | ||
if (bytesLength > 6) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you think it's a better idea, can you put 6
into https://github.com/o1-labs/o1js/blob/main/src/lib/mina/constants.ts? It's a minor change, but it could really help explain later why it's this value.
TODO: forgot to add changelog for this |
bindings: o1-labs/o1js-bindings#213
this adds a new generic type argument and two new functions to
Provable<T>
:the idea is that we can automatically convert between provable types and their normal JS equivalents, and stop leaking provable types outside actual provable code.
Motivation:
Some notes:
From<Provable<T>>
type, e.g.From<typeof Field> = Field | bigint | string | number
, which is automatically derived from deeply inspecting provable types and theirfromValue()
methods. The DX of using it is surprisingly nice -- the type is fully resolved in IntellisensefromValue
for making the return value of thewitness()
callback accept JS values. This is super nice IMO and hints at what we could do with this going forward. For example, we could have a wrapper for all gadgets / provable methods which takes both a provable implementation (as before) and a constant implementation which receives js values, and the result takes the flexibleFrom<>
typeTo make the example above work, I reimplemented
CircuitString
withStruct
and a JS type ofstring
. It also works withCircuitValue
but I wanted to have an example for how to override the JS value type for Structs, it's a bit more involved sinceStruct
wants to infer everything for you (whileCircuitValue
is somewhat weakly typed)For backwards compatibility, the
V
type parameter is optional in the exportedProvable
, so you can still writeProvable<T>
in situations where the JS value doesn't matter