Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
fborello-lambda committed Nov 1, 2024
1 parent a1569d3 commit 82de9c4
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 28 deletions.
3 changes: 0 additions & 3 deletions crates/l2/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ ENGINE_API_JWT_PATH=./jwt.hex
PROVER_SERVER_LISTEN_IP=127.0.0.1
PROVER_SERVER_LISTEN_PORT=3000
PROVER_CLIENT_PROVER_SERVER_ENDPOINT=localhost:3000
# If not set it will use directories::ProjectDirs::data_local_dir()/ethereum_rust_l2/prover_state.json
# directories is a Crate from Rust
PROVER_CLIENT_PROVER_STATE_FILE_PATH=
PROPOSER_ON_CHAIN_PROPOSER_ADDRESS=0xe9927d77c931f8648da4cc6751ef4e5e2ce74608
PROPOSER_L1_ADDRESS=0x3d1e15a1a55578f7c920884a9943b3b35d0d885b
PROPOSER_L1_PRIVATE_KEY=0x385c546456b6a603a1cfcaa9ec9494ba4832da08dd6bcf4de9a71e4a01b74924
Expand Down
23 changes: 7 additions & 16 deletions crates/l2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,9 @@ down-l2: ## 🛑 Shuts down the L2 Lambda Ethereum Rust Client

restart-l2: down-l2 init-l2 ## 🔄 Restarts the L2 Lambda Ethereum Rust Client

init-l2-prover: FORCE_PURGE := 1
init-l2-prover: purge_prover_state ## 🚀 Initializes the Prover
cargo run --release --features build_zkvm --manifest-path ../../Cargo.toml --bin ethereum_rust_prover

init-l2-prover-gpu: FORCE_PURGE := 1
init-l2-prover-gpu: purge_prover_state ## 🚀 Initializes the Prover with GPU support
cargo run --release --features "build_zkvm,gpu" --manifest-path ../../Cargo.toml --bin ethereum_rust_prover

Expand All @@ -82,17 +80,10 @@ endif

.PHONY: purge_prover_state
purge_prover_state:
@if [ "$(FORCE_PURGE)" -eq "1" ]; then \
echo "Force purging the directory: $(PROJECT_PATH)"; \
rm -rf "$(PROJECT_PATH)"; \
echo "Directory deleted."; \
else \
echo "Are you sure you want to delete the directory: $(PROJECT_PATH)? [y/n]"; \
read answer; \
if [ "$$answer" != "y" ]; then \
echo "Operation canceled."; \
exit 1; \
fi; \
rm -rf "$(PROJECT_PATH)"; \
echo "Directory deleted."; \
fi
@echo "Are you sure you want to delete the directory: $(PROJECT_PATH)? [y/n]"
@read answer; \
if [ "$$answer" != "y" ]; then \
echo "Operation canceled."; \
fi; \
rm -rf "$(PROJECT_PATH)"; \
echo "Directory deleted."
11 changes: 11 additions & 0 deletions crates/l2/docs/prover.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- [ToC](#toc)
- [What](#what)
- [Prover State](#prover-state)
- [Workflow](#workflow)
- [How](#how)
- [Dev Mode](#dev-mode)
Expand All @@ -22,6 +23,16 @@ Before the `zkVM` code (or guest), there is a directory called `interface`, whic

In summary, the `prover_client` manages the inputs from the `prover_server` and then "calls" the `zkVM` to perform the proving process and generate the `groth16` ZK proof.

## Prover State

The `prover_client` saves its state in the file located at `directories::ProjectDirs::data_local_dir()/ethereum_rust_l2/prover_state.json`.

It is assumed that the `prover_server` is initiated beforehand and that the `prover_client` starts afterward. After receiving a `SubmitAck`, the client saves the last prover block header in the file. If the client goes down, it will read the file, extract the block number, and add 1, so the next request to the server will be for `last_proven_block_number + 1`.

If the `prover_server` goes down, it will start its count from 0. Consequently, when the prover client requests a higher block, this may result in a panic.

Currently, the state of the `prover_server` is not being saved.

## Workflow

The `Prover Server` monitors requests for new jobs from the `Prover Client`, which are sent when the prover is available. Upon receiving a new job, the Prover generates the proof, after which the `Prover Client` sends the proof back to the `Prover Server`.
Expand Down
5 changes: 1 addition & 4 deletions crates/l2/prover/src/prover_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ struct ProverClient {

impl ProverClient {
pub fn new(config: ProverClientConfig) -> Result<Self, Box<dyn std::error::Error>> {
let prover_state_file_path = match config.prover_state_file_path {
Some(path) => path,
None => save_prover_state::get_default_prover_state_file_path()?,
};
let prover_state_file_path = save_prover_state::get_default_prover_state_file_path()?;

let block_number_to_request = match read_block_in_prover_state(&prover_state_file_path) {
Ok(ps) => ps.block_header.number + 1,
Expand Down
7 changes: 3 additions & 4 deletions crates/l2/prover/src/utils/save_prover_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ pub fn get_default_prover_state_file_path() -> Result<String, Box<dyn std::error
create_prover_state_file_path("prover_client_state.json")
}

pub fn create_prover_state_file() -> Result<File, Box<dyn std::error::Error>> {
let file_path = get_default_prover_state_file_path()?;
if let Some(parent) = Path::new(&file_path).parent() {
pub fn create_prover_state_file(file_path: &str) -> Result<File, Box<dyn std::error::Error>> {
if let Some(parent) = Path::new(file_path).parent() {
create_dir_all(parent)?;
}
File::create(file_path).map_err(Into::into)
Expand All @@ -41,7 +40,7 @@ pub fn persist_block_in_prover_state(
file_path: &str,
block_header: BlockHeader,
) -> Result<(), Box<dyn std::error::Error>> {
let inner = File::create(file_path)?;
let inner = create_prover_state_file(file_path)?;
let mut writer = BufWriter::new(inner);

let prover_state = ProverState { block_header };
Expand Down
1 change: 0 additions & 1 deletion crates/l2/utils/config/prover_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use super::errors::ConfigError;
#[derive(Deserialize, Debug)]
pub struct ProverClientConfig {
pub prover_server_endpoint: String,
pub prover_state_file_path: Option<String>,
}

impl ProverClientConfig {
Expand Down

0 comments on commit 82de9c4

Please sign in to comment.