41 Commits

Author SHA1 Message Date
Daniel Lubarov
c7b03cfe9a More MPT logic 2022-09-24 20:49:19 -07:00
Nicholas Ward
26fcd9eed4 fmt 2022-09-23 11:49:30 -07:00
Nicholas Ward
2b298e39eb stack manipulation: allow empty LHS 2022-09-23 11:49:13 -07:00
Daniel Lubarov
dbb0503d3e Support macro overloading 2022-09-22 20:22:57 -07:00
Daniel Lubarov
c27e40e7bb
Merge pull request #731 from mir-protocol/mpt
Basic MPT logic
2022-09-22 12:06:16 -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
Daniel Lubarov
218f689422 Fix prohibited macro names 2022-09-21 13:10:16 -07:00
Daniel Lubarov
f876a8ab02 Fix macro vars in %stack directive 2022-09-21 08:42:56 -07:00
Nicholas Ward
a5f34d9a2e fix 2022-09-13 22:03:25 -07:00
Nicholas Ward
b25986ce57 parentheses change 2022-09-13 22:03:25 -07:00
Nicholas Ward
0b9881c5e3 blocks in stack manipulation 2022-09-09 12:05:58 -07:00
Daniel Lubarov
763d63de08 For permutations, find the optimal sequence of swaps
Using a method Angus described. This is mainly his idea and code, I just ported it to Rust.
2022-08-09 16:33:02 -04:00
Daniel Lubarov
616eb618f2 Support macro-local labels
Again borrowing syntax from NASM. Example from the test:

    %macro spin
    %%start:
        PUSH %%start
        JUMP
    %endmacro

One thing this lets us do is create "wrapper" macros which call a function, then return to the code immediately following the macro call, such as

    %macro decode_rlp_scalar
        %stack (pos) -> (pos, %%after)
        %jump(decode_rlp_scalar)
    %%after:
    %endmacro

I used this to clean up `type_0.asm`.

However, since such macros need to insert `%%after` beneath any arguments in the stack, using them will be suboptimal in some cases. I wouldn't worry about it generally, but we might want to avoid them in performance-critical code, or functions with many arguments like `memcpy`.
2022-08-04 12:32:20 -07:00
Daniel Lubarov
dfd715fafb Fix case where a valid constant propagation a broke test 2022-08-03 13:52:52 -07:00
Daniel Lubarov
8aad0b0746 Feedback 2022-08-02 15:57:06 -07:00
Daniel Lubarov
497b26dee6 Some simple optimization rules
Depends on #647.
2022-07-31 13:00:27 -07:00
Daniel Lubarov
7e91720088 Store literals as U256 (or u8 for BYTES)
Instead of the original strings. Will make optimizations simpler.
2022-07-31 12:12:35 -07:00
Daniel Lubarov
bd6847e8fc Allow %stack to work with labels
There's no syntax to distinguish named stack items from labels, so this simply searches the former first. I.e. labels can be shadowed by stack items.
2022-07-31 12:12:17 -07:00
wborgeaud
9dacbe0ff6 Comments 2022-07-23 12:52:45 +02:00
wborgeaud
ec97f8497f Modify parser 2022-07-23 11:16:45 +02:00
Daniel Lubarov
47ea00d6c7 A few ASM fixes 2022-07-20 15:05:09 -07:00
Daniel Lubarov
78fb34a9b6 Minor 2022-07-20 00:10:52 -07:00
Daniel Lubarov
1a0d6f4413 Pruning 2022-07-19 23:43:29 -07:00
Daniel Lubarov
05a1fbfbae Stack manipulation macro
Uses a variant of Dijkstra's, with a few pruning mechanics, to find a path of instructions between the two stack states. We don't explicitly store the graph though.

The Dijkstra implementation is somewhat inspired by the `pathfinding` crate. That crate doesn't quite fit our needs though.

If we need to make it faster later, there are a lot of allocations and clones that we could probably eliminate.
2022-07-19 22:59:56 -07:00
Daniel Lubarov
83643aa584
Merge pull request #612 from mir-protocol/bootstrapping_continued
Continue work on bootstrapping
2022-07-15 13:03:16 -07:00
Daniel Lubarov
6d69e14a89 Add %rep syntax for repeating a block
Same syntax as NASM.
2022-07-14 14:58:18 -07: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
Daniel Lubarov
33622c1ec1
Merge pull request #608 from mir-protocol/kernel_size_logs
Have `make_kernel` log the size of each (assembled) file
2022-07-13 13:13:39 -07: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
a68d8ff586 Avoid duplicate macros 2022-07-13 18:54:43 +02:00
Daniel Lubarov
8a2a035411 Merge branch 'main' into evm_generation 2022-07-11 09:58:38 -07: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
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
ee80fa4a39 Minor 2022-07-05 16:19:23 +02:00
wborgeaud
8873eaba11 Find labels before assembly 2022-07-05 16:11:55 +02:00
Daniel Lubarov
e7b480deaf Begin work on witness generation and kernel bootstrapping 2022-07-01 10:09:57 -07:00
Jacqueline Nabaglo
e3834a5335
Util for assembling EVM code to hex (#586)
This is just for debugging the kernel. It's fully disposable.
2022-06-27 18:08:03 -07: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
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