50 Commits

Author SHA1 Message Date
Daniel Lubarov
c721155e23 Main function, txn processing loop 2022-09-29 23:15:33 -07:00
Daniel Lubarov
c7b03cfe9a More MPT logic 2022-09-24 20:49:19 -07:00
Daniel Lubarov
37d92b55ac Basic MPT logic
For now this contains most of the basic framework/structure. Logic for things like insertions will come later.
2022-09-22 11:25:37 -07:00
Jacqueline Nabaglo
4c52d37546
Save columns by verifying invalid opcodes in software (#701)
* Save columns by verifying invalid opcodes in software

* Autogenerate invalid opcode bitfield (Daniel comment)

* Remove unnecessary panic label
2022-08-30 13:06:03 -07:00
Daniel Lubarov
cc61c7211c Core transaction processing logic
With lots of TODOs to fill in afterward; this is just a start.
2022-08-12 17:20:18 -07:00
Daniel Lubarov
ccc4202de3 Packing memory operations 2022-08-05 13:44:08 -04:00
Daniel Lubarov
7423124e36 Split up memory asm and add more helper functions 2022-08-03 22:18:29 -07:00
Daniel Lubarov
90be4749ef Merge branch 'main' into optimizer 2022-08-03 09:58:54 -07:00
Daniel Lubarov
3f08cca116 More constants for kernel ASM
- `GlobalMetadata` - offsets for global kernel variables in memory
- `ContextMetadata` - offsets for context-specific kernel variables in memory
- `GAS_CONSTANTS`, based on the yellowpaper

Also move constants to a separate module since `aggregator` was getting long.
2022-08-01 18:18:22 -07:00
Daniel Lubarov
497b26dee6 Some simple optimization rules
Depends on #647.
2022-07-31 13:00:27 -07:00
Daniel Lubarov
7a6d996fe7 Move couple asm files 2022-07-31 09:28:16 -07:00
Daniel Lubarov
718b3c0961 Move ecrecover 2022-07-31 09:24:04 -07:00
Daniel Lubarov
56d814e467 fix 2022-07-31 09:22:13 -07:00
Daniel Lubarov
f49170a8b8 fix 2022-07-30 22:31:07 -07:00
Daniel Lubarov
86a797b1db Add a asm/curve/ directory 2022-07-30 22:24:11 -07:00
wborgeaud
2bae8f92f0
Merge pull request #635 from mir-protocol/nondeterministic_ec_ops
Use non-determinism in EC ops
2022-07-29 13:05:12 +02:00
wborgeaud
87640d7e98 PR feedback 2022-07-28 10:35:53 +02:00
Jacqueline Nabaglo
c160c4032d
Inter-row program counter constraints (#639)
* Beginning of control flow support

* Fixes to halt spin loop
2022-07-27 11:36:33 -07:00
wborgeaud
8053215841 Inverse for other fields 2022-07-27 16:49:26 +02:00
Daniel Lubarov
0ba6078984 Merge branch 'main' into rlp_3 2022-07-25 19:47:43 -07:00
Daniel Lubarov
1db5b7374d Move storage asm 2022-07-24 08:42:06 -07:00
Daniel Lubarov
544c84b420 Transaction (RLP) parsing
Will add tests once we have the interpreter support for other segmnets.
2022-07-23 21:39:01 -07:00
Daniel Lubarov
78fb34a9b6 Minor 2022-07-20 00:10:52 -07:00
Daniel Lubarov
80d32f89b6 fixes 2022-07-18 15:58:12 -07:00
Daniel Lubarov
50144a638f Enable assertions, now working 2022-07-18 13:48:51 -07:00
Daniel Lubarov
71b9705a0d
Merge pull request #618 from mir-protocol/asm_assertions
More basic ASM macros
2022-07-18 09:31:34 -07:00
wborgeaud
a268677936 Merge branch 'main' into ecrecover_kernel
# Conflicts:
#	evm/src/cpu/kernel/aggregator.rs
2022-07-18 14:01:10 +02:00
wborgeaud
fd991a4eef
Merge pull request #614 from mir-protocol/evm_interpreter_memory
Implement memory for the EVM interpreter
2022-07-18 13:52:39 +02:00
Daniel Lubarov
4aaceabd18 Include assertions, disabled for now 2022-07-17 16:08:58 -07:00
Daniel Lubarov
ab5abc391d Organize segments in an enum
It's a bit more type-safe (can't mix up segment with context or virtual addr), and this way uniqueness of ordinals is enforced, partially addressing a concern raised in #591.

To avoid making `Segment` public (which I don't think would be appropriate), I had to make some other visibility changes, and had to move `generate_random_memory_ops` into the test module.
2022-07-16 10:16:12 -07:00
wborgeaud
292bb4a024 Implement memory for the interpreter 2022-07-15 11:10:10 +02:00
Daniel Lubarov
0802d6c021 Continue work on bootstrapping
The kernel is hashed using a Keccak based sponge for now. We could switch to Poseidon later if our kernel grows too large.

Note that we use simple zero-padding (pad0*) instead of the standard pad10* rule. It's simpler, and we don't care that the prover can add extra 0s at the end of the code. The program counter can never reach those bytes, and even if it could, they'd be 0 anyway given the EVM's zero-initialization rule.

In one CPU row, we can do a whole Keccak hash (via the CTL), absorbing 136 bytes. But we can't actually bootstrap that many bytes of kernel code in one row, because we're also limited by memory bandwidth. Currently we can write 4 bytes of the kernel to memory in one row.

So we treat the `keccak_input_limbs` columns as a buffer. We gradually fill up this buffer, 4 bytes (one `u32` word) at a time. Every `136 / 4 = 34` rows, the buffer will be full, so at that point we activate the Keccak CTL to absorb the buffer.
2022-07-14 11:59:01 -07:00
wborgeaud
33a5934255 Passing tests 2022-07-14 14:26:01 +02:00
wborgeaud
cb7215436b Merge branch 'main' into ecrecover_kernel
# Conflicts:
#	evm/src/cpu/kernel/aggregator.rs
2022-07-14 13:17:16 +02:00
wborgeaud
905b0243e7 Minor fixes 2022-07-14 13:07:58 +02:00
Daniel Lubarov
a8852946b3 Have make_kernel log the size of each (assembled) file
For now it doesn't log filenames, but we can compare against the list of filenames in `combined_kernel`.

Current output:
```
[DEBUG plonky2_evm::cpu::kernel::assembler] Assembled file size: 0 bytes
[DEBUG plonky2_evm::cpu::kernel::assembler] Assembled file size: 49 bytes
[DEBUG plonky2_evm::cpu::kernel::assembler] Assembled file size: 387 bytes
[DEBUG plonky2_evm::cpu::kernel::assembler] Assembled file size: 27365 bytes
[DEBUG plonky2_evm::cpu::kernel::assembler] Assembled file size: 0 bytes
[DEBUG plonky2_evm::cpu::kernel::assembler] Assembled file size: 11 bytes
[DEBUG plonky2_evm::cpu::kernel::assembler] Assembled file size: 7 bytes
[DEBUG plonky2_evm::cpu::kernel::aggregator::tests] Total kernel size: 27819 bytes
```

This shows that most of our kernel code is from `curve_add.asm`, which makes sense since it invovles a couple uses of the large `inverse` macro.  Thankfully that will be replaced at some point.
2022-07-13 10:53:26 -07:00
wborgeaud
a831fab8f8 Working secp add 2022-07-13 19:22:32 +02:00
wborgeaud
c8c3cc9a8f Files shuffling 2022-07-13 18:48:25 +02:00
Daniel Lubarov
58889e7649
Allow constants to be passed from Rust into our assembly (#598)
Roughly like environment variables. So we don't have to declare things like segment IDs twice.
2022-07-08 08:56:46 -07:00
wborgeaud
122188c817 Merge branch 'ec_use_macro_params' into evm_interpreter 2022-07-07 19:17:31 +02:00
wborgeaud
7bf5118f69 Test exp kernel function 2022-07-07 18:46:20 +02:00
wborgeaud
9c4947e0f0 EC ops test 2022-07-07 18:06:24 +02:00
Daniel Lubarov
beb8a90773
Macros with arguments (#595)
* Macros with arguments

See `basic_macros.rs` for an example.

* rename
2022-07-07 08:59:53 -07:00
wborgeaud
5bae732ea0 Minor 2022-07-05 21:24:51 +02:00
wborgeaud
fb8a67b0d9 Working ecmul 2022-07-05 21:12:11 +02:00
wborgeaud
eed7cde388 Add moddiv for testing 2022-07-05 15:01:40 +02:00
wborgeaud
797bece7bd First attempt 2022-07-01 18:28:22 +02:00
Daniel Lubarov
7b75eaa98d
ASM macro support (#580)
* ASM macro support

Also recognize global labels as a PUSH target; previously it only considered local labels.

* macro test
2022-06-25 23:10:08 -07:00
Jacqueline Nabaglo
191ddf7bc1
Exponentiation kernel function (#574)
* Exponentiation kernel function

* Exponentiation: Hamish comments
2022-06-23 15:33:55 -07:00
Daniel Lubarov
2e818172f0
Parse and assemble kernel functions (#567)
* Parse and assemble kernel functions

Written in "EVM++" assembly. Later on we will add some priviledged opcodes (in unused opcode ordinals), making it an extension of EVM bytecode.

I don't think there's much of a standard for EVM assembly, but I loosely based the syntax on this [proposal](https://gist.github.com/axic/17ddbbce4738ccf4040d30cbb5de484e).

* PR feedback

* tweaks for consistency

* terminology tweaks

* Update evm/src/cpu/kernel/opcodes.rs

Co-authored-by: Jacqueline Nabaglo <jakub@mirprotocol.org>

* Update evm/src/cpu/kernel/opcodes.rs

Co-authored-by: Jacqueline Nabaglo <jakub@mirprotocol.org>

* Update evm/src/cpu/kernel/opcodes.rs

Co-authored-by: Jacqueline Nabaglo <jakub@mirprotocol.org>

Co-authored-by: Jacqueline Nabaglo <jakub@mirprotocol.org>
2022-06-20 20:32:29 -07:00