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

[feat] modular add v2 #510

Merged
merged 9 commits into from
Oct 10, 2024
Merged

[feat] modular add v2 #510

merged 9 commits into from
Oct 10, 2024

Conversation

luffykai
Copy link
Contributor

@luffykai luffykai commented Oct 8, 2024

part of INT-2260

  • add new heap_adapter, currently assumes it's always 2 read 1 write
  • make a new version of modular add chip with the new adapter, and the field expression framework. Currently only runtime, no tracegen or eval

moved some utils functions so touched many files, but only modular_v2 and rv32_heap.rs are relevant

TODO for follow up PRs

  • make number of read/write generic? like can the same adapter handles 1read1write and 2read1write? Is there other patterns?
  • trace gen and eval of the adapter , and the new chip in general
  • Add select to field expression framework to support add or sub in the same chip

Copy link

linear bot commented Oct 8, 2024

INT-2260 Runtime for modular arithmetic and elliptic curve operations

Relies on being able to figure out moduli handling.

@luffykai luffykai marked this pull request as ready for review October 8, 2024 21:17
@luffykai luffykai requested a review from jonathanpwang October 8, 2024 21:19
let x_biguint = limbs_to_biguint(&x, LIMB_SIZE);
let y_biguint = limbs_to_biguint(&y, LIMB_SIZE);

let z_biguint = (x_biguint + y_biguint) % &self.modulus;
Copy link
Contributor

Choose a reason for hiding this comment

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

are you doing it this way for convenience for now? shouldn't this be owned by ExprBuilder? also you don't handle Sub

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. ExprBuilder currently doesn't do the "execute" part explicitly. It kinda does it as part of trace gen, but need some work to get it done more cleanly.
  2. doing sub here requires ExprBuilder to support select

Since this PR was intended for register-heap adapter, going to add the above in a followup PR

Copy link
Contributor

Choose a reason for hiding this comment

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

OK this execute thing about ExprBuilder will need to be resolved right, as that is how we will plan to use it throughout.

Copy link
Contributor

@jonathanpwang jonathanpwang left a comment

Choose a reason for hiding this comment

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

Adapter: shouldn't be using old MemoryHeap stuff because the pointer needs to come from RV32 register, not single field element cell.

Integration: only handles Add and not Sub (maybe that was a todo), but also doesn't use ExprBuilder so I'm confused.

@luffykai luffykai force-pushed the lunkai/heap-adapter branch 2 times, most recently from e9a5dbb to 243e09d Compare October 9, 2024 18:50
@luffykai luffykai requested a review from jonathanpwang October 9, 2024 19:01
pub struct Rv32HeapAdapterCols<T, const READ_SIZE: usize, const WRITE_SIZE: usize> {
pub read_aux: [Rv32RegisterHeapReadAuxCols<T, READ_SIZE>; 2],
pub write_aux: Rv32RegisterHeapWriteAuxCols<T, WRITE_SIZE>,
pub read_addresses: [HeapAddress<T, T>; 2],
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be addressed when you finish the AIR, but I don't think HeapAddress is optimal: the address space for register is fixed to 1 so it shouldn't be a column. The address space for memory is the same address read/writes so it should be at most a single column for e. Also at present for intrinsics I decided we can just fix that address space to 2. So HeapAddress can save some columns.


#[repr(C)]
#[derive(Clone, Debug, AlignedBorrow)]
pub struct Rv32RegisterHeapReadAuxCols<T, const N: usize> {
Copy link
Contributor

Choose a reason for hiding this comment

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

In general, adapter specific columns and methods should be put in the adapter file and not in memory/ since that should be kept for core memory functionality. I have moved everything for registerheap out. The old MemoryHeap__ structs and methods should eventually be moved out too.

Copy link
Contributor

Choose a reason for hiding this comment

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

Additionally, since we aren't separating by module, any naming involving register should specify RV32 register (since RV64 would be different if we ever chose to support it).

@luffykai luffykai force-pushed the lunkai/heap-adapter branch from b16146e to af2b1bd Compare October 10, 2024 16:25
@luffykai luffykai merged commit 397e282 into main Oct 10, 2024
8 checks passed
@luffykai luffykai deleted the lunkai/heap-adapter branch October 10, 2024 16:46
luffykai added a commit that referenced this pull request Dec 13, 2024
* modular add v2

* use register

* dont put range checker bits as config

* add todo

* fix test

* fix test

* refactor: move structs out of memory into adapter mod

* add todo

* fix

---------

Co-authored-by: Jonathan Wang <[email protected]>
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