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

Dynamic arrays in o1js #1848

Draft
wants to merge 30 commits into
base: main
Choose a base branch
from
Draft

Dynamic arrays in o1js #1848

wants to merge 30 commits into from

Conversation

querolita
Copy link
Member

@querolita querolita commented Oct 2, 2024

Addressing #1086, based on #633

Making this public as WIP to receive early feedback

@querolita querolita changed the title DynamicArrays in o1js ArrayLists in o1js Oct 7, 2024
@mitschabaude
Copy link
Contributor

mitschabaude commented Oct 11, 2024

@querolita @Trivo25 maybe of interest: I created quite polished general-purpose types for both static and dynamic arrays in this PR: zksecurity/mina-attestations#25

They made it pretty easy to implement dynamic-length sha256.

I think they could serve as a starting point for arrays in o1js that are (even) better designed than the D. Gretzke repo!

@querolita querolita changed the title ArrayLists in o1js Dynamic arrays in o1js Oct 17, 2024
@querolita querolita marked this pull request as ready for review October 17, 2024 17:51
@querolita querolita changed the base branch from v1 to main November 7, 2024 08:41
@querolita querolita requested review from a team as code owners November 7, 2024 08:41
@querolita
Copy link
Member Author

querolita commented Nov 12, 2024

TODO

  • Include complexity of each function
  • Improve efficiency making further use of cached masked positions
  • Randomized tests

@Shigoto-dev19
Copy link
Contributor

Is it possible to use DynamicArray as a method input? I believe this is feasible for zkApps but not yet for ZkProgram, as Yoni is addressing it in #1828.

Additionally, it would be great to get some insights into the constraint optimization for dynamic array indexing or updates. For example, how does its efficiency compare to classic techniques for an array of 100 elements versus using dynamic arrays?

@mitschabaude
Copy link
Contributor

mitschabaude commented Nov 21, 2024

Is it possible to use DynamicArray as a method input? I believe this is feasible for zkApps but not yet for ZkProgram, as Yoni is addressing it in #1828.

zkApps and ZkProgram are the same actually.
In both of them, you can use non-pure provable types for private inputs.
However, you can't use them for public inputs. In zkApps, the public input type is fixed / not configurable, so that's not a noticeable limitation for users.

This limitation shouldn't be relevant to dynamic arrays since it's pure whenever the element type is pure. However, this might not be currently reflected in the type signature!

Copy link
Member

@Trivo25 Trivo25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good so far! Let's wait for the runtime tables before we finish and merge this PR, otherwise we would have to break backwards compatilbility later which is a bit meh

methods: {
pushAndPop: {
privateInputs: [],
async method() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall the tested cases look good to me, but we should restructure the tests a bit differently - lets talk about that next time!

Copy link
Member

@Geometer1729 Geometer1729 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@Shigoto-dev19 Shigoto-dev19 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@querolita querolita marked this pull request as draft December 3, 2024 12:48
@Trivo25
Copy link
Member

Trivo25 commented Mar 13, 2025

soft blocked on #2079

This was referenced Mar 27, 2025
@querolita querolita changed the base branch from main to feature/lookup-runtime-tables March 31, 2025 16:58
Base automatically changed from feature/lookup-runtime-tables to main April 1, 2025 05:09
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.

5 participants