Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
refactor: fixed solidity code duplication in rust, and improved justf…
Browse files Browse the repository at this point in the history
…ile (#28)

* imp: reduced code complexity a lot

* deps: simplify

* refactored

* reduced solidity duplication

* imp: simplification

* imp: regenerated fixtures

* regen fixtures

* imp: improved scripts

* ci: added operator command to just

* imp: regenerated proofs

* docs: imp
  • Loading branch information
srdtrk authored Jun 26, 2024
1 parent 5e9b832 commit 4cfb0ea
Show file tree
Hide file tree
Showing 21 changed files with 163 additions and 216 deletions.
12 changes: 12 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# URL of the Tendermint RPC node
TENDERMINT_RPC_URL=https://rpc.celestia-mocha.com/
# URL of the Ethereum RPC node
RPC_URL=https://ethereum-sepolia.publicnode.com/
# Address of the light client contract
CONTRACT_ADDRESS="CONTRACT-ADDRESS"
# SP1_PROVER={network|local|mock}
SP1_PROVER=network
# Private key with the permission to use the network prover
SP1_PRIVATE_KEY="PRIVATE-KEY"
# Private key which the operator uses to sign the transactions in Eth Sepolia testnet
PRIVATE_KEY="PRIVATE-KEY"
3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ tendermint = { version = "0.36.0", default-features = false }
ibc-core-client-types = { version = "0.53.0", default-features = false }
ibc-core-commitment-types = { version = "0.53.0", default-features = false }
time = { version = "0.3", default-features = false, features = ["macros", "parsing"] }
# tendermint-light-client-verifier = { version = "0.35.0", default-features = false, features = [
# "rust-crypto",
# ] }
alloy-primitives = "0.7.2"
alloy-contract = "0.1.2"
alloy-node-bindings = "0.1.2"
Expand Down
40 changes: 13 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,22 @@ just build-program

## Run ICS-07 Tendermint Light Client End to End

1. Generate the initialization parameters for the contract.
1. Set the environment variables by filling in the `.env` file with the following:

```sh
TENDERMINT_RPC_URL=https://rpc.celestia-mocha.com/ cargo run --bin genesis --release
cp .env.example .env
```

This will generate the `contracts/script/genesis.json` file which contains the initialization parameters for the contract.
You need to fill in the `PRIVATE_KEY`, `SP1_PROVER`, `TENDERMINT_RPC_URL`, and `RPC_URL`. You also need the `SP1_PRIVATE_KEY` field if you are using the SP1 prover network.

2. Deploy the `SP1ICS07Tendermint` contract with the initialization parameters:
2. Deploy the `SP1ICS07Tendermint` contract:

```sh
cd ../contracts
forge install
forge script script/SP1ICS07Tendermint.s.sol --rpc-url https://ethereum-sepolia.publicnode.com/ --private-key <PRIVATE_KEY> --broadcast
just deploy-contracts
```

If you see the following error, add `--legacy` to the command.
This will generate the `contracts/script/genesis.json` file which contains the initialization parameters for the contract. And then deploy the contract using `contracts/script/SP1ICS07Tendermint.s.sol`.
If you see the following error, add `--legacy` to the command in the `justfile`:
```text
Error: Failed to get EIP-1559 fees
```
Expand All @@ -60,26 +57,15 @@ just build-program

```text
== Return ==
0: address <SP1_TENDERMINT_ADDRESS>
0: address <CONTRACT_ADDRESS>
```

This will be used when you run the operator in step 5.
This will be used when you run the operator in step 5. So add this to your `.env` file.

4. Export your SP1 Prover Network configuration
```sh
# Export the PRIVATE_KEY you will use to deploy the contract & relay proofs.
export PRIVATE_KEY=<PRIVATE_KEY>
# Optional
# If you're using the Succinct network, set SP1_PROVER to "network". Otherwise, set it to "local" or "mock".
export SP1_PROVER={network|local|mock}
# Only required if SP1_PROVER is set to "network".
export SP1_PRIVATE_KEY=<SP1_PRIVATE_KEY>
```
4. Run the Tendermint operator.

5. Run the Tendermint operator.
```sh
TENDERMINT_RPC_URL=https://rpc.celestia-mocha.com/ RPC_URL=https://ethereum-sepolia.publicnode.com/ CONTRACT_ADDRESS=<CONTRACT-ADDRESS> RUST_LOG=info cargo run --bin operator --release
just operator
```

## EVM-Compatible Proof Generation & Verification
Expand All @@ -93,10 +79,10 @@ Here, I will show you how to generate a proof to be used in the fixtures for the
RUST_BACKTRACE=full RUST_LOG=info SP1_PROVER="local" TENDERMINT_RPC_URL="https://rpc.celestia-mocha.com/" cargo run --bin fixture --release -- --trusted-block 2110658 --target-block 2110668
```

To use the SP1 prover network, you will need to set the `SP1_PROVER` environment variable to `network` and provide your private key. You can do this by running the following command:
To use the SP1 prover network, you will need to set the `SP1_PROVER` environment variable to `network` and provide your private key to `.env`. After this, you can run the following command:

```sh
RUST_BACKTRACE=full RUST_LOG=info SP1_PROVER="network" SP1_PRIVATE_KEY="YOUR_PRIVATE_KEY" TENDERMINT_RPC_URL="https://rpc.celestia-mocha.com/" cargo run --bin fixture --release -- --trusted-block 2110658 --target-block 2110668
just network-fixtures
```

### Solidity Proof Verification
Expand Down
1 change: 1 addition & 0 deletions contracts/abi/SP1ICS07Tendermint.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions contracts/fixtures/fixture.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"trustedConsensusState": "000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000017db9605c70f5a75000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000020994a2058af458e1a97f19bfa85c99ba5db6534473e8040e671a45431f78651bf0000000000000000000000000000000000000000000000000000000000000020b73058223e788b1b021cd25d9d8b80f1e21f742014d270fc850bacda1e63c419",
"targetConsensusState": "000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000017db962167923e1a000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000002092a23d699a0d59f2e1b034c129b0051fb711a3d0d1f2e895fce82e933b8e36fd0000000000000000000000000000000000000000000000000000000000000020b73058223e788b1b021cd25d9d8b80f1e21f742014d270fc850bacda1e63c419",
"targetHeight": 2110668,
"vkey": "0x004ac9cd92d0a05a01903f9f62b3c271ba861e2cd6b615c4c081394cbaf123f3",
"publicValues": "0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000002034c2000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000002034cc00000000000000000000000000000000000000000000000017db9605c70f5a75000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000020994a2058af458e1a97f19bfa85c99ba5db6534473e8040e671a45431f78651bf0000000000000000000000000000000000000000000000000000000000000020b73058223e788b1b021cd25d9d8b80f1e21f742014d270fc850bacda1e63c41900000000000000000000000000000000000000000000000017db962167923e1a000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000002092a23d699a0d59f2e1b034c129b0051fb711a3d0d1f2e895fce82e933b8e36fd0000000000000000000000000000000000000000000000000000000000000020b73058223e788b1b021cd25d9d8b80f1e21f742014d270fc850bacda1e63c41900000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000044c1ff252000000000000000000000000000000000000000000000000000017dbb9d861d9c38000000000000000000000000000000000000000000000000000000000000000076d6f6368612d3400000000000000000000000000000000000000000000000000",
"proof": "0x28192d1ec8d20562142ae5ed4b621a04cf6871187db21b0991e4732d470d7b5a17e6b1c037a5e75fc275e8bae644060d82c70050b6c695bbc4efe534db3f99c62c37e3e49930156a62b2743c054c463a789181b3ade6be54b8108e2afaebc1900f30a937736a0566bda5e72e11ede01e5a9f4cc54e45deb12b5a913415df51c30d5b991991f73942bb25c07444eabf989fe86dcf09874ff7c168a6a52a5d7cf52e46af4a99e227fec9990646781353e3c35a2b6303db59f2dd6c89c6e8b7f61a1e1a5bb75660dd8a914abb6ab7fa24f6ece69b87738b39066a720617707515892dbe014e002a1b859eef8de16ec36b2adfe95d44598853412f9f8c15e6574c732902911a34c720778d381fde493150f3582e412832bc5dfd7c9769a47c6f7c310ecaccac1d8701e743aecff4f8954bda594dc60cd124491bad0b5422abe5f8c60d19b48760f8d8a4243af71ea83c67b56a0c77aa559ff686c493d55a21c83ebb25aba42a65fa9eebde9c6b23b65870cdb0f0b6ed5162042f2f76ff7c63b617861c32723bff3020c91a5a0215d7cc43c59b151909075ddc78ec46895df1c9068f1bb77a4feae837abbbf959af7348b003cd2acbb825cbaf0c1e58db57bb454ddf186666c0a1459c4a578558d46e9b02cb541b173e96e7225e1e91b80c203203001831d51c0423869cefb63f2b346df6b138bd747b1335f48d6e0fe46d6683eda110aa73735e712cc3a921134713d07f839dbd582c2b3174bcc6d2b5b6926447ca190ed214ed8fa55fffb6b850bc6b3eeaa60790c84cfaaf6d31300ed796302e6c2d42eb241dac89b1723e736da9f8c4d897c2da6c2f3b76eda7faf94d4e930d8f1e3ebb0d58ca7c0164e82a7e86724f4a12b6051a5c51d9974d3f1756d1674bd91a1a9c8d5eea30c21cfef32aba24fb9ceb9b2f543871a5855c1c7b7deeed1aac013a6be382d092b3ba9645659e1f9c8d4953e50628a55d6552183a703fca9b330f41c0ce092b8305eea6516531dd98749945178fa5fb0dabe5e6f26a4e7d0a112238b8154ad17fca7edab2c51275d5a0d06496266811912cf9b0fdc2cc14d37924dfc2a17ea46cee7f66cce4883490c7c0abcd51ae339264faf39600bfb256c926620ea8e3d6b8f3babe6ebaee3cc0d48dbbffaf9798ddffdc78cfaa7f07969f141fb667d4790be0b9ef1f503a90c41610f0cc3a6913c69049aa5ab69466dec4"
"vkey": "0x0027abf663673bd7da77aa0839ef4afb57aca485b0da85b02f53a39b8bc1991f",
"publicValues": "0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000002034c2000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000002034cc00000000000000000000000000000000000000000000000017db9605c70f5a75000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000020994a2058af458e1a97f19bfa85c99ba5db6534473e8040e671a45431f78651bf0000000000000000000000000000000000000000000000000000000000000020b73058223e788b1b021cd25d9d8b80f1e21f742014d270fc850bacda1e63c41900000000000000000000000000000000000000000000000017db962167923e1a000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000002092a23d699a0d59f2e1b034c129b0051fb711a3d0d1f2e895fce82e933b8e36fd0000000000000000000000000000000000000000000000000000000000000020b73058223e788b1b021cd25d9d8b80f1e21f742014d270fc850bacda1e63c41900000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000044c1ff252000000000000000000000000000000000000000000000000000017dc7a857543e24800000000000000000000000000000000000000000000000000000000000000076d6f6368612d3400000000000000000000000000000000000000000000000000",
"proof": "0x2b425f9ae65f69e332c01056aa13bdb0d7d0808250ceb1f1a6f38e8bf3e7222d22c64db06f748d50bf8e9604f0db8fbf9ba3a84c00e54d0268d4704462b436fe0781c1a6e15b7940c259bd37e5e0e2a85935addc2bc7a297dc878ece0639f08e12782f85c76cdddadf9511712a88a79c475190e7c35b9170e98e1e2945f522691e313e360ee82434b1e10436eaa6a90d806906d8d991d856d66e620b83609bdf00e9da5062e86da85df360875e9b7319e8b7978a099be02d2c253b284833c470049675ec44837a9642996afe235fd13053f97f82858a0f1ecf1f79f6a39636dc2a593c2f478099757e00c2c9c58545c00c9ad80e7603fed15ff8baf9395f768f195d62e5b9628c5df2c3c917bafc5bdd9a7ccb15a893d6067546a465397d425517a7f320ae3b17d033e0b89f3e981109b8aa4f72678ab2db52ba7a444b51d6361228222c659b59d328a72458777f2665c41eb5b4c2cfdc3a5b2bb665ce38303c0e2d7f0717d060d041a2d7474be52ac0b033ba1c92c031efcb69c753da048ed12d0997b4294fb87d66022cb6845ad27931166b5e8ec9af0bbf46c61a087c4dcf02790eff080b6ffe540bfd442b9d74d4b3bdf2278fa85b2052fadf655720129a2c2ecf0c56e8aa5f565082f01b794f67d12aa3cb49a0e140a2ef42a64a4636a12439471d43b855456e73546565e045fa209bf3701c24cfbd75d5050968a473ac286b725dbb63faa9a79c02d408f60e6d0a01631af5c814b06075679806f3019e0f3e81fdad4025a02122fda64253bd01a4863c6b29d5a008858b1f39ded2e5050ec8b88f634fd03f3e96909c5d10e90cbfdc7178162f8abf83672cd32db911731f26dad46ffbf7d24cbc2699825f05a365e7f95e26c799dc9b7f626a99e545681844d13f330008104c9c33646d37cd30d4e165c64dc195448d2c549ac596a9221368e7e02e8ba4169c868099f272f31c1021a8ce3409297431427356f90e53461e27e7de438e87326f84082403098c140709055ce05304abd556ab5c39f08a330e4048ed10395889d1fc7b12ed2ecce5c76b7a545a27203c0b51884b58b91bb82aab20dc88728956da6ac4c7aebbd801744f5d278b4b40daba7195a2686ccff012d215d3f892675230ebce15e7d8ccf76b2128532361d793e8ac57a3fe02a30a1695394a0a7cfdee422dcc0d346c7ecb403c610c13b9b28c758142c61f39dfbe"
}
4 changes: 2 additions & 2 deletions contracts/fixtures/mock_fixture.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"trustedConsensusState": "000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000017db9605c70f5a75000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000020994a2058af458e1a97f19bfa85c99ba5db6534473e8040e671a45431f78651bf0000000000000000000000000000000000000000000000000000000000000020b73058223e788b1b021cd25d9d8b80f1e21f742014d270fc850bacda1e63c419",
"targetConsensusState": "000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000017db962167923e1a000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000002092a23d699a0d59f2e1b034c129b0051fb711a3d0d1f2e895fce82e933b8e36fd0000000000000000000000000000000000000000000000000000000000000020b73058223e788b1b021cd25d9d8b80f1e21f742014d270fc850bacda1e63c419",
"targetHeight": 2110668,
"vkey": "0x00084515d81830c3fd44b21efbbe0ba9251ebcf47bf084734054f9d0c267449f",
"publicValues": "0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000002034c2000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000002034cc00000000000000000000000000000000000000000000000017db9605c70f5a75000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000020994a2058af458e1a97f19bfa85c99ba5db6534473e8040e671a45431f78651bf0000000000000000000000000000000000000000000000000000000000000020b73058223e788b1b021cd25d9d8b80f1e21f742014d270fc850bacda1e63c41900000000000000000000000000000000000000000000000017db962167923e1a000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000002092a23d699a0d59f2e1b034c129b0051fb711a3d0d1f2e895fce82e933b8e36fd0000000000000000000000000000000000000000000000000000000000000020b73058223e788b1b021cd25d9d8b80f1e21f742014d270fc850bacda1e63c41900000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000044c1ff252000000000000000000000000000000000000000000000000000017dbec604d35b0a000000000000000000000000000000000000000000000000000000000000000076d6f6368612d3400000000000000000000000000000000000000000000000000",
"vkey": "0x0027abf663673bd7da77aa0839ef4afb57aca485b0da85b02f53a39b8bc1991f",
"publicValues": "0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000002034c2000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000002034cc00000000000000000000000000000000000000000000000017db9605c70f5a75000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000020994a2058af458e1a97f19bfa85c99ba5db6534473e8040e671a45431f78651bf0000000000000000000000000000000000000000000000000000000000000020b73058223e788b1b021cd25d9d8b80f1e21f742014d270fc850bacda1e63c41900000000000000000000000000000000000000000000000017db962167923e1a000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000002092a23d699a0d59f2e1b034c129b0051fb711a3d0d1f2e895fce82e933b8e36fd0000000000000000000000000000000000000000000000000000000000000020b73058223e788b1b021cd25d9d8b80f1e21f742014d270fc850bacda1e63c41900000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000044c1ff252000000000000000000000000000000000000000000000000000017dc78a886422ed000000000000000000000000000000000000000000000000000000000000000076d6f6368612d3400000000000000000000000000000000000000000000000000",
"proof": "0x"
}
Loading

0 comments on commit 4cfb0ea

Please sign in to comment.