747 Commits

Author SHA1 Message Date
Hamish Ivey-Law
d7bb47318c
Modular operations for the EVM arithmetic unit (#755)
* First draft of 256-bit addition.

* Update comment.

* cargo fmt

* Rename addition evaluation file.

* Port ALU logic from SZ.

* Give a name to some magic numbers.

* `addition.rs` -> `add.rs`; fix carry propagation in add; impl sub.

* Clippy.

* Combine hi and lo parts of the output.

* Implement MUL.

* Suppress Clippy's attempt to make my code even harder to read.

* Next draft of MUL.

* Make all limbs (i.e. input and output) 16-bits.

* Tidying.

* Use iterators instead of building arrays.

* Documentation.

* Clippy is wrong; also cargo fmt.

* Un-refactor equality checking, since it was wrong for sub.

* Daniel comments.

* Daniel comments.

* Rename folder 'alu' -> 'arithmetic'.

* Rename file.

* Finish changing name ALU -> Arithmetic Unit.

* Finish removing dependency on array_zip feature.

* Remove operations that will be handled elsewhere.

* Rename var; tidy up.

* Clean up columns; mark places where range-checks need to be done.

* Import all names in 'columns' to reduce verbiage.

* cargo fmt

* Fix aux_in calculation in mul.

* Remove redundant 'allow's; more precise range-check size.

* Document functions.

* Document MUL instruction verification technique.

* Initial tests for ADD.

* Minor test fixes; add test for SUB.

* Fix bugs in generate functions.

* Fix SUB verification; refactor equality verification.

* cargo fmt

* Add test for MUL and fix some bugs.

* Update doc.

* Quiet incorrect clippy error.

* Initial implementation of ADDMOD and MOD.

* Fixes to addmod.

* Update doc.

* Do 1000 random tests instead of just 1.

* Documentation fix.

* Working version of ADDMOD.

* Working version of MOD.

* Name magic number; do multiple MUL tests.

* Add code and test for special case; add some docs.

* Fix spelling mistake.

* Simplify asserts.

* Tidy comment.

* Remove unused module.

* cargo fmt

* Check that output is reduced.

* Add conversion of canonical `i64` to a `Field64`.

* Handle zero modulus within degree constraint.

* cargo fmt

* Fix some comments.

* Check that the top half of the product is zero!

* Start of refactor.

* Refactoring.

* Remove zero and reduction handling from addmod.

* Refactoring; renaming; bug fixes.

* Reuse intermediate calculations across all modular operations; don't negate quot poly unnecessarily.

* Fix bug where last elt of q*m wasn't checked.

* Refactoring.

* Move circuit poly functions to utils.rs.

* Rename ADDMOD stuff to MODULAR.

* Rename module addmod -> modular.

* Handle zero modulus.

* Verify that output is reduced.

* Implement recursive version of modular circuits.

* clippy

* Tidy up i64 -> Field conversion following Jacqui's comments.

* cargo fmt

* Improved documentation.

* Address Jacqui's comments.

* Save some gates by using builder.arithmetic_extension().
2022-10-07 17:15:50 +11:00
Daniel Lubarov
f8c104033c Hash MPT extension nodes 2022-10-06 20:50:32 -07:00
Daniel Lubarov
b832c6abaf Update spec 2022-10-06 17:29:58 -07:00
Daniel Lubarov
ed2aac3af3 MPT fixes 2022-10-06 16:28:52 -07:00
Daniel Lubarov
0424fe680d mload_packing 2022-10-06 14:27:36 -07:00
Daniel Lubarov
f2cb42bbe8 MPT logic to hash branch nodes 2022-10-05 20:46:49 -07:00
Daniel Lubarov
0c9847abf3 Rework MPT hashing to support inlining <32 byte children 2022-10-05 15:23:06 -07:00
Dmitry Vagner
7c7084a8d3 clean up and format 2022-10-05 12:11:10 -07:00
Dmitry Vagner
0afb9b0cf4 fmt 2022-10-05 10:10:45 -07:00
Dmitry Vagner
9ebbc033bc fix padlength issue 2022-10-05 09:45:38 -07:00
BGluth
bf57fe9835 Now uses eth_trie_utils on crates.io 2022-10-04 22:07:43 -06:00
Daniel Lubarov
d8bf30150f
Merge pull request #756 from mir-protocol/rlp_fixes
RLP related fixes
2022-10-04 15:34:38 -07:00
Daniel Lubarov
0ccb340e40 RLP related fixes 2022-10-04 15:18:31 -07:00
Dima V
dd6c5a0d1a
Merge pull request #640 from mir-protocol/ripeMD
RipeMD
2022-10-03 15:49:04 -07:00
Dmitry Vagner
95128cbbf5 done 2022-10-03 15:32:47 -07:00
Dmitry Vagner
53014b732f almost done 2022-10-03 15:30:17 -07:00
Nicholas Ward
d48f63142f
Merge pull request #754 from mir-protocol/sha2_inline_consts
Inline some SHA2 constants
2022-10-03 15:20:34 -07:00
Dmitry Vagner
1475cddb3d rearrange 2022-10-03 15:01:59 -07:00
Daniel Lubarov
c03773bab1 Inline some SHA2 constants
I think `%mload_kernel_code_u32` is good when we need to do random access, but since the indices are constant here, let's just hardcode them like this.

This reduces the assembled size of `compression.asm` from 1827 to 1454 bytes. I think there's still a lot more we could do to shrink it, though it's not that important.
2022-10-03 14:59:33 -07:00
Dmitry Vagner
54885fefa0 fix merge problem 2022-10-03 14:57:04 -07:00
Daniel Lubarov
66c28e953d Unroll num_bytes
Since it's in some code paths where speed is critical.
2022-10-03 14:42:11 -07:00
Dmitry Vagner
6e5fe43c7e delete duplicates 2022-10-03 14:31:56 -07:00
Daniel Lubarov
295bd60ee7
Merge pull request #752 from mir-protocol/hash_kernel
Fill in `hash_kernel`
2022-10-03 14:28:46 -07:00
Dmitry Vagner
d42250d677 merge 2022-10-03 14:25:33 -07:00
Daniel Lubarov
5e32241543 Fill in hash_kernel 2022-10-03 14:12:05 -07:00
Nicholas Ward
43df58ea18 alphabetical 2022-10-03 14:10:10 -07:00
Nicholas Ward
9919562a64 clippy 2022-10-03 14:08:09 -07:00
Nicholas Ward
99fb730aea rearranging and cleanup 2022-10-03 14:07:21 -07:00
Dmitry Vagner
681b6e31e7 minor 2022-10-03 14:01:47 -07:00
Nicholas Ward
9ee861fb15 minor fixes 2022-10-03 13:43:03 -07:00
Nicholas Ward
6ff0b84e59 fix 2022-10-03 13:34:16 -07:00
Nicholas Ward
249fc6c1e4 fix 2022-10-03 13:34:16 -07:00
Nicholas Ward
416a7a868b fmt 2022-10-03 13:34:16 -07:00
Nicholas Ward
69e33eff72 fix 2022-10-03 13:34:16 -07:00
Nicholas Ward
9f49521e22 label name simplification 2022-10-03 13:34:16 -07:00
Nicholas Ward
1e03c438e0 moved memory functions to memory ASM file (not sha2) 2022-10-03 13:34:16 -07:00
Nicholas Ward
1f3ee6dae2 remove prover_inputs from Interpreter 2022-10-03 13:34:16 -07:00
Nicholas Ward
fa01f83e65 Update evm/src/cpu/kernel/tests/sha2.rs
Co-authored-by: Dima V <50062893+typ3c4t@users.noreply.github.com>
2022-10-03 13:34:16 -07:00
Nicholas Ward
19b14c2723 Update evm/src/cpu/kernel/tests/sha2.rs
Co-authored-by: Dima V <50062893+typ3c4t@users.noreply.github.com>
2022-10-03 13:34:16 -07:00
Nicholas Ward
cfbc029e7b cleaned up test: compare as U256, not string 2022-10-03 13:34:16 -07:00
Nicholas Ward
42320d815e fix 2022-10-03 13:34:16 -07:00
Nicholas Ward
65b8993b6f addressed comments 2022-10-03 13:34:16 -07:00
Nicholas Ward
c11c526462 cleanup and comments 2022-10-03 13:34:16 -07:00
Nicholas Ward
5d7edb33d4 comment 2022-10-03 13:34:16 -07:00
Nicholas Ward
7eba422792 addressed comments 2022-10-03 13:34:16 -07:00
Nicholas Ward
78a4b92e83 in %stack, treat identifiers as 1-length blocks 2022-10-03 13:34:16 -07:00
Nicholas Ward
7eadfee580 removed parentheses 2022-10-03 13:34:16 -07:00
Nicholas Ward
d1d404b989 addressed comments 2022-10-03 13:34:16 -07:00
Nicholas Ward
5cf8bf2ba3 more %stack sha2 cleanup 2022-10-03 13:34:16 -07:00
Nicholas Ward
140242c556 more %stack sha2 cleanup 2022-10-03 13:34:16 -07:00