-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: sync committee proof server (#100)
* feat: sync committee proof server docs: rust doc + recompile program feat: compile program feat: proper count for signers feat: remove setup logger feat: committee change proof server * docs: fix necessary RUSTFLAGS * Update ethereum/docs/src/run/setup_proof_server.md Co-authored-by: wwared <[email protected]> * refactor: integrate review Co-authored-by: wwared <[email protected]> --------- Co-authored-by: wwared <[email protected]>
- Loading branch information
1 parent
9803a39
commit 1782d8b
Showing
22 changed files
with
680 additions
and
52 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,5 @@ With our deployment machine properly configured, we can run the client. | |
```bash | ||
git clone [email protected]:lurk-lab/zk-light-clients.git && \ | ||
cd zk-light-clients/ethereum && \ | ||
RUST_LOG="debug" cargo +nightly-2024-05-31 run -p light-client --release --bin client -- -c <CHECKPOINT_PROVIDER_ADDRESS> -b <BEACON_NODE_ADDRESS> | ||
RUST_LOG="debug" cargo +nightly-2024-05-31 run -p light-client --release --bin client -- -c <CHECKPOINT_PROVIDER_ADDRESS> -b <BEACON_NODE_ADDRESS> -p <PROOF_SERVER_ADDRESS> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Deploy the Proof Server | ||
|
||
We have two components to deploy for the Proof Server to work as intended. The primary and the secondary server. | ||
There is no particular order in which they should be deployed, but here we will deploy the secondary and then | ||
the primary. | ||
|
||
For best results, the primary and secondary servers should be deployed to **different server instances**, so that | ||
proof generation can happen in parallel if necessary. | ||
|
||
## Requirements | ||
|
||
Make sure to finish the [initial configuration](./configuration.md) first. | ||
|
||
## Environment variables | ||
|
||
- `RUSTFLAGS="-C target-cpu=native -C opt-level=3"`: | ||
- `-C target-cpu=native`: This will ensure that the binary is optimized | ||
for the CPU it is running on. This is very important | ||
for [plonky3](https://github.com/plonky3/plonky3?tab=readme-ov-file#cpu-features) performance. | ||
- `-C opt-level=3`: This turns on the maximum level of compiler optimizations. | ||
- This can also be configured in `~/.cargo/config.toml` instead by adding: | ||
```toml | ||
[target.'cfg(all())'] | ||
rustflags = ["-C", "target-cpu=native", "-C", "opt-level=3"] | ||
``` | ||
|
||
Make sure to launch the proof servers with `cargo +nightly-2024-05-31`. | ||
|
||
> **Note** | ||
> | ||
> One can also set the `RUST_LOG` environment variable to `debug` to get more information | ||
> about the execution of the server. | ||
|
||
## Deploy the primary server | ||
|
||
Finally, once the primary server is configured in the same fashion, run it: | ||
|
||
```bash | ||
git clone [email protected]:lurk-lab/zk-light-clients.git && \ | ||
cd zk-light-clients/ethereum/light-client && \ | ||
SHARD_BATCH_SIZE=0 RUSTFLAGS="-C target-cpu=native -C opt-level=3" cargo +nightly-2024-05-31 run --release --bin server_primary -- -a <NETWORK_ADDESS> --snd-addr <SECONDARY_SERVER_ADDRESS> | ||
``` |
Binary file modified
BIN
-1.34 KB
(100%)
ethereum/ethereum-programs/artifacts/committee-change-program
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,77 @@ | ||
// Copyright (c) Yatima, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#[allow(clippy::missing_const_for_fn)] | ||
fn main() {} | ||
use anyhow::{Error, Result}; | ||
use clap::Parser; | ||
use ethereum_lc::proofs::committee_change::CommitteeChangeProver; | ||
use ethereum_lc::proofs::Prover; | ||
use ethereum_lc::types::network::Request; | ||
use ethereum_lc::utils::{read_bytes, write_bytes}; | ||
use log::{error, info}; | ||
use std::sync::Arc; | ||
use tokio::net::TcpListener; | ||
use tokio::task::spawn_blocking; | ||
|
||
#[derive(Parser)] | ||
struct Cli { | ||
/// Address of this server. E.g. 127.0.0.1:1234 | ||
#[arg(short, long)] | ||
addr: String, | ||
|
||
/// Address of the secondary server. E.g. 127.0.0.1:4321 | ||
#[arg(long)] | ||
snd_addr: String, | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
let Cli { addr, .. } = Cli::parse(); | ||
|
||
env_logger::init(); | ||
|
||
let listener = TcpListener::bind(addr).await?; | ||
info!("Server is running on {}", listener.local_addr()?); | ||
|
||
let committee_prover = Arc::new(CommitteeChangeProver::new()); | ||
|
||
loop { | ||
let (mut client_stream, _) = listener.accept().await?; | ||
info!("Received a connection"); | ||
|
||
let committee_prover = committee_prover.clone(); | ||
|
||
tokio::spawn(async move { | ||
info!("Awaiting request"); | ||
let request_bytes = read_bytes(&mut client_stream).await?; | ||
info!("Request received"); | ||
|
||
info!("Deserializing request"); | ||
match Request::from_bytes(&request_bytes) { | ||
Ok(request) => match request { | ||
Request::ProveCommitteeChange(boxed) => { | ||
info!("Start proving"); | ||
let proof_handle = spawn_blocking(move || { | ||
let (proving_mode, inputs) = boxed.as_ref(); | ||
committee_prover.prove(inputs.clone(), proving_mode.clone()) | ||
}); | ||
let proof = proof_handle.await??; | ||
info!("Proof generated. Serializing"); | ||
let proof_bytes = proof.to_bytes()?; | ||
info!("Sending proof"); | ||
write_bytes(&mut client_stream, &proof_bytes).await?; | ||
info!("Proof sent"); | ||
} | ||
Request::VerifyCommitteeChange(proof) => { | ||
write_bytes( | ||
&mut client_stream, | ||
&[u8::from(committee_prover.verify(&proof).is_ok())], | ||
) | ||
.await?; | ||
} | ||
}, | ||
Err(err) => error!("Failed to deserialize request object: {err}"), | ||
} | ||
Ok::<(), Error>(()) | ||
}); | ||
} | ||
} |
Oops, something went wrong.