-
Notifications
You must be signed in to change notification settings - Fork 145
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
Support UTF-8 encode/decode for CircuitString #2020
Support UTF-8 encode/decode for CircuitString #2020
Conversation
lgtm! I just want to mention that this is breaking for circuits that use constant |
Co-authored-by: Gregor Mitscha-Baude <[email protected]>
Actually, our teams also treats all unicode strings as invalid strings and work around with |
In the past when we made updates to stable APIs, we created new versions targeting the next major o1js version and deprecated the existing version (but didn't modiify it). I wonder if we could do the same thing here and make a new class called I'm not sure how many are currently using circuitString, but breaking VKs is really annoying. |
@45930 What do you think about adding new encoding parameter in e.g: type CircuitStringEncoding = 'utf-8' | 'ascii';
fromString(str: string, encoding: CircuitStringEncoding = 'ascii');
toString(str: string, encoding: CircuitStringEncoding = 'ascii'); This change will maintain the backward compatibility. |
@chiro-hiro I like that as an API, but your current changes modify the toValue and fromValue code in the raw circuit string, so both branches would use your new code, so it would still be a breaking change. If you can update the fromString and toString methods instead, and leave the value conversion methods unchanged, I think that would work and not be breaking. |
@45930 I've updated my code to support both ASCII and UTF-8 following your suggestion (minimizing the modifications in Add import { CircuitString } from 'o1js';
const a = CircuitString.fromString('Xin chào O1js!'); // Xin cho O1js! 14
console.log(a.toString(), a.length().toString());
CircuitString.setEncoding('utf-8');
const b = CircuitString.fromString('Xin chào O1js!'); // Xin chào O1js! 15
console.log(b.toString(), b.length().toString()); |
@45930 Can you check this PR? is it work for u?. |
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.
It looks good to me!
Can you add a changelog entry and fix the styling issues (https://github.com/o1-labs/o1js/blob/main/README-dev.md#style-guide)? Then I can merge.
I updated the changelog following your suggestion.
Checked the lint and format as well, probably a false positive. Github action shown errors and warnings in 250 files. |
Running |
…into feature/uft8_in_circuit_string # Conflicts: # src/lib/mina/transaction-validation.ts # src/lib/mina/transaction.test.ts # src/lib/mina/transaction.ts
Hi @boray, I updated the given code. Didn't aware that the prettier rules were changed. |
You can follow README-dev.md#bindings-check-in-ci to fix the failing bindings check. |
@boray My branch is out date and it was generate a huge patch, just sync with |
@boray I can't reproduce the issue in Github action.Node.js v22.12.0 |
Thanks @chiro-hiro, the change looks good to me! Since there are no bindings diffs, I think it's ok to merge. |
We're working on zkDatabase project and found an issue with unicode characters, I think this patch could help.
Before this patch:
After this patch: