|
1 |
| -## Foundry |
| 1 | +# MRC |
| 2 | +- **RFC**: [RFC MCR](https://github.com/movementlabsxyz/rfcs/pulls) |
2 | 3 |
|
3 |
| -**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.** |
| 4 | +This directory contains the implementation of the MRC settlement smart contract. To test the contract, run: |
4 | 5 |
|
5 |
| -Foundry consists of: |
6 |
| - |
7 |
| -- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools). |
8 |
| -- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data. |
9 |
| -- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network. |
10 |
| -- **Chisel**: Fast, utilitarian, and verbose solidity REPL. |
11 |
| - |
12 |
| -## Documentation |
13 |
| - |
14 |
| -https://book.getfoundry.sh/ |
15 |
| - |
16 |
| -## Usage |
17 |
| - |
18 |
| -### Build |
19 |
| - |
20 |
| -```shell |
21 |
| -$ forge build |
22 |
| -``` |
23 |
| - |
24 |
| -### Test |
25 |
| - |
26 |
| -```shell |
27 |
| -$ forge test |
28 |
| -``` |
29 |
| - |
30 |
| -### Format |
31 |
| - |
32 |
| -```shell |
33 |
| -$ forge fmt |
34 |
| -``` |
35 |
| - |
36 |
| -### Gas Snapshots |
37 |
| - |
38 |
| -```shell |
39 |
| -$ forge snapshot |
| 6 | +```bash |
| 7 | +forge test |
40 | 8 | ```
|
41 | 9 |
|
42 |
| -### Anvil |
| 10 | +There is a long-running test cover over 50 epochs. It will take about a minute and a half to complete on most machines. |
43 | 11 |
|
44 |
| -```shell |
45 |
| -$ anvil |
46 |
| -``` |
| 12 | +# Implementation |
| 13 | +## Description |
| 14 | +For a given block height, MCR selects the earliest block commitment that matches the supermajority of stake for a given epoch by: |
| 15 | +1. Fixing the stake parameters for the epoch; all stake changes apply to the next epoch. |
| 16 | +2. Tracking commitments for each block height until one exceeds the supermajority of stake. |
47 | 17 |
|
48 |
| -### Deploy |
| 18 | +## Proof of Correctness |
| 19 | +The stake is fixed for an epoch, so only commitments for a specific block height are considered, allowing for a straightforward proof. |
49 | 20 |
|
50 |
| -```shell |
51 |
| -$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key> |
52 |
| -``` |
| 21 | +Let $C$ represent all possible commitments, and $C'$ be an ordered subset of $C$. MCR returns $c_i \in C'$, the earliest commitment matching the supermajority of stake, defined as: |
53 | 22 |
|
54 |
| -### Cast |
| 23 | +$$ |
| 24 | +\delta(C') = \frac{2}{3} \times \sum_{c \in C'} s(v(c)), |
| 25 | +$$ |
55 | 26 |
|
56 |
| -```shell |
57 |
| -$ cast <subcommand> |
58 |
| -``` |
| 27 | +where $v: C \to V$ maps a commitment to its validator and $s: V \to \mathbb{N}$ maps a validator to their stake. Define $\sigma'(C', i) = \sum_{j = 0}^{i} s(v(c_j))$, the cumulative stake up to the $i$-th commitment. $\sigma'$ is non-decreasing as $\sigma(C', i) = \sigma(C', i - 1) + s(v(c_i))$. |
59 | 28 |
|
60 |
| -### Help |
61 |
| - |
62 |
| -```shell |
63 |
| -$ forge --help |
64 |
| -$ anvil --help |
65 |
| -$ cast --help |
66 |
| -``` |
| 29 | +If $\sigma(C', i) \geq \delta(C')$, then $c_i$ is the earliest commitment where the supermajority is met, since any earlier commitment $c_j$ for $j < i$ would violate the non-decreasing nature of $\sigma'$. |
0 commit comments