94 Commits

Author SHA1 Message Date
Robin Salen
2dacbfe2ff
Address bundling (#1426)
* Start

* Scale TxnFields

* Speed-up

* Misc fixes

* Other fixes

* Fix

* Fix offset

* One more fix

* And one more fix

* Fix

* Fix

* Fix init

* More interpreter fixes

* Final fixes

* Add helper methods

* Clippy

* Apply suggestions

* Comments

* Update documentation

* Regenerate pdf

* minor

* Rename some macros for consistency

* Add utility method for unscaling segments and scaled metadata

* Address comments
2024-01-08 10:46:26 +00:00
Hamy Ratoanina
68b9f0ad1c
Add ERC721 test (#1425)
* Add ERC721 test

* Add IS_READ column to BytePacking CTL

* Apply comment
2023-12-15 19:44:59 -05:00
Linda Guiga
bc1a3c4851
Merge push and prover_input flags (#1417)
* Merge PUSH and PROVER_INPUT flags

* Apply comment
2023-12-13 16:21:24 +01:00
Hamy Ratoanina
3195c205df
Merge MSTORE_32BYTES and MLOAD_32BYTES columns (#1414)
* Merge MSTORE_32BYTES and MLOAD_32BYTES columns

* Fix circuit functions

* Apply comments
2023-12-08 17:57:45 -05:00
Hamy Ratoanina
edfc86c393
Remove is_keccak_sponge (#1410)
* Remove is_keccak_sponge

* Apply comment
2023-12-07 13:07:06 -05:00
Hamy Ratoanina
46b6aa108d
Implement degree 2 filters (#1404)
* Implement degree 2 filters

* Apply comments
2023-12-05 17:02:37 -05:00
Hamy Ratoanina
30c944f778
Remove bootstrapping (#1390)
* Start removing bootstrapping

* Change the constraint for kernel code initializing

* Update specs

* Apply comments

* Add new global metadata to circuit methods

* Change zero-initializing constraint

* Apply comment

* Update circuit size range for recursive test
2023-11-30 10:04:08 -05:00
Hamy Ratoanina
64cc1000e7
Move stack_len_bounds_aux to general columns (#1360)
* Move stack_len_bounds_aux to general columns

* Update specs

* Apply comments

* Apply comment
2023-11-28 14:14:47 -05:00
Robin Salen
b9328815e6
Reduce visibility (#1364) 2023-11-17 15:45:38 -05:00
Robin Salen
01f229a8e1
Add push constraints (#1352)
* Add push constraints

* Fix ranges

* Add stack constraints
2023-11-15 11:15:14 -05:00
Hamy Ratoanina
6d751b13c1
Remove values of last memory channel (#1291)
* Remove values of last memory channel

Co-authored-by: Linda Guiga <lindaguiga3@gmail.com>

* Fix merge

* Apply comments

* Fix ASM

* Top stack documentation (#7)

* Add doc file

* Apply comments

* Apply comments

* Fix visibility

* Fix visibility

---------

Co-authored-by: Linda Guiga <lindaguiga3@gmail.com>
2023-11-13 11:03:50 -05:00
Robin Salen
88fcc32983
Reduce visibility for a bunch of structs and methods in EVM crate (#1289)
* Reduce visibility for a bunch of structs and methods

* Remove redundant
2023-11-13 09:26:56 -05:00
Hamy Ratoanina
01bbf1a058
Constrain clock (#1343) 2023-11-09 16:42:18 -05:00
Linda Guiga
e41435e927
Add memory checks for prover_input, as well as range_checks for prover_input, syscalls/exceptions (#1168)
* Add memory checks for prover_input and range_checks for prover_input, syscalls and exceptions

* Replace u32 by U256, and remove extra CTLs

* Add column in ArithmeticStark to use ctl_arithmetic_base_rows for is_range_check

* Fix CTLs and circuit constraint.

* Fix CTLs
2023-11-07 15:52:00 -05:00
Robin Salen
0d97b93af5
Add some documentation in EVM crate (#1295)
Co-authored-by: Linda Guiga <linda.guiga@toposware.com>
2023-10-30 14:28:24 -04:00
Linda Guiga
666a155d4a
Remove new_stack_top_channel from StackBehavior (#1296) 2023-10-26 17:52:54 -04:00
Hamy Ratoanina
1d60431992
Store top of the stack in memory channel 0 (#1215)
* Store top of the stack in memory channel 0

* Fix interpreter

* Apply comments

* Remove debugging code

* Merge commit

* Remove debugging comments

* Apply comments

* Fix witness generation for exceptions

* Fix witness generation for exceptions (again)

* Fix modfp254 constraint
2023-10-11 16:28:49 -04:00
Robin Salen
41a29f069b
Remove some dead_code in EVM crate (#1281)
* Remove unnecessary CpuArithmeticView.

* Remove AllChallengerState

* Remove RecursiveAllProof

* Remove unused generate methods

* Remove dead_code from cpu/columns

* Remove todo

---------

Co-authored-by: Linda Guiga <lindaguiga3@gmail.com>
2023-10-09 09:07:01 -04:00
Linda Guiga
0de6f94962
Remove extra SHL/SHR CTL. (#1270)
* Remove extra shift CTL.

* Change order of inputs for the arithmetic shift operations. Add SHR test. Fix max number of bit shifts. Cleanup.

* Fix SHR in the case shift >= 256

* Limit visibility of helper functions
2023-10-05 09:56:56 -04:00
Robin Salen
0abc3b9210
Apply comments (#1248) 2023-09-22 10:14:47 -04:00
Robin Salen
d6be2b987b
Remove generic_const_exprs feature from EVM crate (#1246)
* Remove const_generic_exprs feature from EVM crate

* Get a generic impl of StarkFrame
2023-09-22 09:19:13 -04:00
Robin Salen
8903aec129
Change padding rule for CPU (#1234)
* Change padding rule for CPU

* Disable memory channels for padding rows

* Apply some of Jacqueline's comments

* Update halt routine

* Add clarifying comment

* Redundant constraints and padding bug

* Revert "Remove is_bootstrap_kernel column"

This reverts commit 49d92cb8f1b0ae9de76872f76af4429699ff692f.

* Make halt_state implicit

* Move halting logic constraints to dedicated module

* Include new module

* Update some comments
2023-09-15 17:46:58 -04:00
Linda Guiga
d4a8026bf9
Combine mstore_general and mload_general into one flag (#1188)
* Combine mstore_general and mload_general into one flag

* Add comments and make stack constraints cleaner.

* Fix number of native instructions

* Ordering

* Cleanup

* Update calls to stack eval from latest main

---------

Co-authored-by: Robin Salen <salenrobin@gmail.com>
2023-09-14 19:51:02 -04:00
Hamy Ratoanina
0b5ac312c0
Merge pull request #1203 from topos-protocol/constrain_nv_stack_len
Constrain next row's stack length
2023-09-14 22:42:32 +02:00
Robin Salen
06bc73f7ea
Combine arithmetic flags on the CPU side (#1187)
* Combine FP254 flags

* Combine basic binary ops together and do CTL with opcode value

* Combine ternary ops together

* Combine MUL DIV and MOD

* Combine shift operations

* Combine byte with other binary ops

* Fix tests

* Clean leftover comment

* Update from latest main

* Put the 'is_simulated' flag inside the Operation enum

* Cleaner way to handle "simulated" operations SHL and SHR.

* Fix comments.

* Minor: suggestion for re-expressing `combined_ops`.

* Update comment

---------

Co-authored-by: Hamish Ivey-Law <hamish@ivey-law.name>
2023-09-14 10:36:48 -04:00
Robin Salen
9508b49090
Move byte packing / unpacking to a distinct table (#1212)
* Duplicate Memory trace into BytePacking one

* Add mload_32bytes instruction

* Use dedicated ops for byte packing trace

* Change witness generation to reduce memory reads for MLOAD_32BYTES

* Remove segments

* Fix stack

* Fix extra product when fixing CTL for byte_packing

* Write output value in trace

* Add constraints for BYTE_PACKING table

* Add recursive constraints for BYTE_PACKING table

* Fix constraints

* Add address in trace and constraints

* Add timestamp and batch inputs into BytePackingOp struct

* Add extra column

* Fix BytePackingStark CTL

* Tiny fix in witness generation

* Fix the Memory CTL

* Add constraints for the new columns

* Remove 1 column

* Remove limb columns

* Fix

* Fix recursive circuit of BytePackingTable

* Fix constraints

* Fix endianness

* Add MSTORE_32BYTES instruction and move decomposition to packing table

* Add missing constraint

* Add range-check for all bytes

* Add extra constraint

* Cleanup

* Remove REMAINING_LEN column

* Add corresponding implementations in interpreter

* Fix recursive version

* Remove debug assertion because of CI

* Remove FILTER column

* Update new test from rebasing

* Reorder STARK modules to match TraceCheckPoint ordering

* Address comments

* Pacify clippy

* Add documentation to the packing module

* Fix doctest
2023-09-13 04:45:37 +10:00
Hamy Ratoanina
8beba56903
Constrain next row's stack length 2023-08-28 16:32:04 -04:00
Hamy Ratoanina
815a02ab75
Remove is_cpu_cycle 2023-08-15 15:22:41 -04:00
Robin Salen
654f7cac42
Comment 2023-08-11 16:07:02 -04:00
Robin Salen
e10eaad09b
Combine all logic flags together 2023-08-11 10:17:45 -04:00
Robin Salen
437f57a862
Fix logic CTL 2023-08-11 09:23:58 -04:00
Robin Salen
ee9ce4c59d
Combine AND and OR flags in CpuStark 2023-08-09 16:05:24 -04:00
Robin Salen
5f4b15af7a
Connect SHL/SHR operations to the Arithmetic table (#1166)
* Add corresponding arithmetic operations to shift ones

* Include SHL/SHR in the arithmetic CTL

* Prevent overflow

* Expand documentation for ctl_data_ternops()
2023-08-09 23:17:06 +10:00
Linda Guiga
16227f90b9
Merge syscall and exceptions constraints. 2023-07-24 15:40:48 +01:00
Jacqueline Nabaglo
cedeff5219 PUSH0 2023-06-13 13:29:30 -07:00
Jacqueline Nabaglo
6920992e01 Simplify stack bounds constraints 2023-06-07 18:27:23 -07:00
Jacqueline Nabaglo
7ab0bba559
Merge branch 'main' into jacqui/bad-opcode-witness-generation 2023-06-02 21:34:52 -07:00
Jacqueline Nabaglo
b7220428b3 Error handling 2023-06-02 15:51:26 -07:00
Hamish Ivey-Law
0d819cf888
Implement EVM BYTE operation (#1059)
* Initial implementation of BYTE.

* Large index constraints; byte range check (hat-tip to Jacqui)

* Implement recursive circuit version.

* Rebind variable to avoid exceeding degree limit.

* Integrate BYTE with arithmetic stark and witness generation.

* Clippy.

* Document verification proof; miscellaneous tidying.

* Update CTL mapping.

* Reverse argument order.

* Avoid undesired doctest.

* Address Jacqui's comments.

* Address remaining comments from Jacqui.
2023-06-03 02:16:45 +10:00
Hamish Ivey-Law
c134b59763
Cross-table lookup for arithmetic stark (#905)
* First draft of linking arithmetic Stark into the CTL mechanism.

* Handle {ADD,SUB,MUL}FP254 operations explicitly in `modular.rs`.

* Adjust argument order; add tests.

* Add CTLs for ADD, MUL, SUB, LT and GT.

* Add CTLs for {ADD,MUL,SUB}MOD, DIV and MOD.

* Add CTLs for {ADD,MUL,SUB}FP254 operations.

* Refactor the CPU/arithmetic CTL mapping; add some documentation.

* Minor comment fixes.

* Combine addcy CTLs at the expense of repeated constraint evaluation.

* Combine addcy CTLs at the expense of repeated constraint evaluation.

* Merge `*FP254` CTL into main CTL; rename some registers.

* Connect extra argument from CPU in binary ops to facilitate combining with ternary ops.

* Merge modular ops CTL into main CTL.

* Refactor DIV and MOD code into its own module.

* Merge DIV and MOD into arithmetic CTL.

* Clippy.

* Fixes related to merge.

* Simplify register naming.

* Generate u16 BN254 modulus limbs at compile time.

* Clippy.

* Add degree bits ranges for Arithmetic table.
2023-05-11 03:29:06 +10:00
Hamy Ratoanina
c8637635b9
Remove dummy_yield_constr 2023-04-13 15:55:46 -04:00
Hamy Ratoanina
4946c3d5fd
Merge branch 'main' into stack_bound 2023-04-13 15:47:27 -04:00
4l0n50
ba844a2403 Change shl/shr behavior as well as BASIC_TERNARY_OP 2023-04-12 17:35:32 +02:00
Hamy Ratoanina
938e3bd5da
Set stack_len_bounds_aux properly 2023-04-11 16:38:59 -04:00
Hamy Ratoanina
310107f218
Fix decode constraint 2023-04-07 17:06:57 -04:00
Jacqueline Nabaglo
f3946f75bf
Gas constraints (#880)
* Gas constraints

* Bugfix

* make test pass post rebase
2023-02-14 22:30:19 -08:00
Daniel Lubarov
b8e97aaaf8 Fix logic and Keccak CTLs
Lots of little bugs!

- The Keccak sponge table's padding logic was wrong, it was mixing up the number of rows with the number of hashes.
- The Keccak sponge table's Keccak-looking data was wrong - input to Keccak-f should be after xor'ing in the block.
- The Keccak sponge table's logic-looking filter was wrong. We do 5 logic CTLs for any final-block row, even if some of the xors are with 0s from Keccak padding.
- The CPU was using the wrong/outdated output memory channel for its Keccak sponge and logic CTLs.
- The Keccak table just didn't have a way to filter out padding rows. I added a filter column for this.
- The Keccak table wasn't remembering the original preimage of a permutation; lookers were seeing the preimage of the final step. I added columns for the original preimage.
- `ctl_data_logic` was using the wrong memory channel
- Kernel bootloading generation was using the wrong length for its Keccak sponge CTL, and its `keccak_sponge_log` was seeing the wrong clock since it was called after adding the final bootloading row.
2022-12-19 15:42:59 -08:00
Jacqueline Nabaglo
b6bc018cba
Simplify JUMP/JUMPI constraints and finish witness generation (#846)
* Simplify `JUMP`/`JUMPI` constraints and finish witness generation

* Constrain stack
2022-12-11 11:08:33 -08:00
Jacqueline Nabaglo
249e50ebcb
Get/set context (#843) 2022-12-11 10:59:14 -08:00
Jacqueline Nabaglo
29644e5111
Implement PC instruction (#847)
* Implement `PC` instruction

* lints
2022-12-11 10:41:32 -08:00