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

Ensure safe Uint64/32 instanciations, with new Unsafe.fromField() #1438

Merged
merged 13 commits into from
Mar 7, 2024

Conversation

julio4
Copy link
Contributor

@julio4 julio4 commented Feb 16, 2024

Related to #1286
Wanted to explore the o1js repository and tried to tackle this issue.

  • Changed Field to FieldVar in constructors
  • Removed Field from from() functions
  • Added Unsafe.fromField()

The sha256 gadget still rely on a lots of integers directly from field, so this may be a follow up issue as well.

@mitschabaude
Copy link
Collaborator

Awesome!

@mitschabaude
Copy link
Collaborator

mitschabaude commented Feb 16, 2024

The sha256 gadget still rely on a lots of integers directly from field, so this may be a follow up issue as well.

not needed, sha256 is a low-level gadget and has to reach beyond the safe abstraction of a UInt32

@julio4
Copy link
Contributor Author

julio4 commented Feb 16, 2024

The sha256 gadget still rely on a lots of integers directly from field, so this may be a follow up issue as well.

not needed, sha256 is a low-level gadget and has to reach beyond the safe abstraction of a UInt32

Ok, then I can safely use the FieldVar value of the Field (or the new Unsafe.fromField).
Could you please review the changes inside the methods of integers to be sure that there is nothing unsafe (As I only used Field.value internally)?

@julio4 julio4 marked this pull request as draft February 16, 2024 09:47
@mitschabaude
Copy link
Collaborator

Hey @julio4 this is really valuable work that we'd love to include in a release soon. Any way we can help land this?
If you don't have time to finish it, I'm offering to find someone on our team to do so!

@julio4
Copy link
Contributor Author

julio4 commented Feb 27, 2024

Hey @julio4 this is really valuable work that we'd love to include in a release soon. Any way we can help land this? If you don't have time to finish it, I'm offering to find someone on our team to do so!

Hello! I planned to work on it this week. But I think it should be ready, I would just need some help to run pipelines and build locally. I followed the local dev env setup but I encountered some issues.

@mitschabaude
Copy link
Collaborator

I would just need some help to run pipelines and build locally.

@julio4 sure, try to run the following steps. does it fail somewhere?

# ensure packages are up to date
npm i

# pull in dependencies in git submodules
git submodule update --init --recursive

# ts build of the main code base
npm run build

# check that all examples still build
npm run build:examples

# check that integration tests work (takes long, feel free to stop after a minute or so if it seems to work)
npm run test:integration

# run unit tests (this takes super long unfortunately, feel free to let ci do this if you got this far)
npm run test:unit

src/lib/int.ts Outdated Show resolved Hide resolved
src/lib/int.ts Outdated Show resolved Hide resolved
@julio4
Copy link
Contributor Author

julio4 commented Feb 28, 2024

@julio4 sure, try to run the following steps. does it fail somewhere?

# ensure packages are up to date
npm i

# pull in dependencies in git submodules
git submodule update --init --recursive

# ts build of the main code base
npm run build

# check that all examples still build
npm run build:examples

# check that integration tests work (takes long, feel free to stop after a minute or so if it seems to work)
npm run test:integration

# run unit tests (this takes super long unfortunately, feel free to let ci do this if you got this far)
npm run test:unit

Thank you! But I already followed the README-dev and it fail at the main ts build:

building cjs version of ./src/index.ts
using bindings from ./src/bindings/compiled/node_bindings/
▲ [WARNING] "import.meta" is not available with the "cjs" output format and will be empty [empty-import-meta]

    dist/node/bindings/js/node/node-backend.js:6:10:
      6 │ let url = import.meta.url;
        ╵           ~~~~~~~~~~~

  You need to set the output format to "esm" for "import.meta" to work correctly.

Do you know what node version is used?

@mitschabaude
Copy link
Collaborator

Thank you! But I already followed the README-dev and it fail at the main ts build:

@julio4 the command line output you show isn't a failure. It's a warning, which does not point to an actual problem

@mitschabaude
Copy link
Collaborator

mitschabaude commented Feb 28, 2024

you can also see in the CI tests that the build works fine, but something about UInt construction still fails in every single test, at runtime

@julio4
Copy link
Contributor Author

julio4 commented Mar 2, 2024

@julio4 the command line output you show isn't a failure. It's a warning, which does not point to an actual problem

Oh yes, I didn't noticed but all builds are working. The error comes from account-update, but I'm having some troubles finding where's the UInt are created.

@mitschabaude
Copy link
Collaborator

@julio4 it seems that every construction of uints is failing. So if the account update file is hard to parse, I recommend to just create a trivial test or run the integer test with ./jest src/lib/int.test.ts

@mitschabaude mitschabaude marked this pull request as ready for review March 7, 2024 10:42
@mitschabaude mitschabaude requested a review from a team as a code owner March 7, 2024 10:42
@mitschabaude
Copy link
Collaborator

@julio4 thanks so much for doing most of this heavy change! I pushed the last remaining fixes, it's ready to go!

@mitschabaude mitschabaude merged commit 46efed4 into o1-labs:main Mar 7, 2024
13 checks passed
@julio4
Copy link
Contributor Author

julio4 commented Mar 10, 2024

@julio4 thanks so much for doing most of this heavy change! I pushed the last remaining fixes, it's ready to go!

Thank you for fixing the issue. I tried to dig a little bit on it and didn't found what was causing the error.

@julio4 julio4 deleted the feat/safe-int branch April 14, 2024 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants