Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add zeth support in rpc type #803

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .github/workflows/zeth-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
# Zeth Integration

name: Zeth Integration

on:
push:
branches: [develop, main]
pull_request:
branches:
- "**"
workflow_dispatch:
branches:
- "**"

env:
CARGO_TERM_COLOR: always

jobs:
zeth_integration:
name: Zeth Integration
runs-on: zero-ci
timeout-minutes: 30
steps:
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Clone Repositories
uses: actions/checkout@v4
with:
repository: 0xPolygonZero/zeth
ref: "arpit/1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When do we plan to merge your work to the main branch?

Copy link
Contributor Author

@temaniarpit27 temaniarpit27 Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR - 0xPolygonZero/zeth#5
Whenever this is merged

path: zeth

- name: Run zeth network
run: |
cd zeth
touch polygon-zero.db
cargo run -- node --dev --http.api all &
# TODO - @temaniarpit27 - This is a hack to wait for the network to start
echo "Zeth network started, Sleeping for sometime to let the network start"
sleep 120

- name: Generate txn
run: |
cast send --async --legacy \
--from "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" \
--private-key "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" \
--rpc-url http://localhost:8545 --gas-limit 100000 --value 1 "0x852DA15b70a3e197d1D668a9a481B1F4c2168a5D"
Comment on lines +44 to +49
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could probably use polycli loadtest to generate multiple blocks. As this integration test is about witness extraction, probably few different kind of transactions and blocks would be great.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a demo integration to kick things off. Issue for improvement:
#806


- name: Checkout
uses: actions/checkout@v4
with:
path: zk_evm

- name: Run prove blocks with zero tracer in test_only mode
run: |
cd zk_evm
OUTPUT_TO_TERMINAL=true ./scripts/prove_rpc.sh 1 1 http://localhost:8545 zeth 0 3000 100 test_only
echo "Proving blocks in test_only mode finished"
5 changes: 5 additions & 0 deletions zero/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::prover::BlockProverInput;
pub mod jerigon;
pub mod native;
pub mod retry;
pub mod zeth;

use crate::provider::CachedProvider;

Expand All @@ -37,6 +38,7 @@ const PREVIOUS_HASHES_COUNT: usize = 256;
pub enum RpcType {
Jerigon,
Native,
Zeth,
}

/// Obtain the prover input for one block
Expand All @@ -56,6 +58,9 @@ where
RpcType::Native => {
native::block_prover_input(cached_provider, block_id, checkpoint_block_number).await
}
RpcType::Zeth => {
zeth::block_prover_input(cached_provider, block_id, checkpoint_block_number).await
}
}
}

Expand Down
35 changes: 35 additions & 0 deletions zero/src/rpc/zeth.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use alloy::{providers::Provider, rpc::types::eth::BlockId, transports::Transport};
use trace_decoder::BlockTrace;

use super::fetch_other_block_data;
use crate::prover::BlockProverInput;
use crate::provider::CachedProvider;

pub async fn block_prover_input<ProviderT, TransportT>(
cached_provider: std::sync::Arc<CachedProvider<ProviderT, TransportT>>,
target_block_id: BlockId,
checkpoint_block_number: u64,
) -> anyhow::Result<BlockProverInput>
where
ProviderT: Provider<TransportT>,
TransportT: Transport + Clone,
{
let block_number = match target_block_id {
BlockId::Number(block_number) => block_number,
_ => return Err(anyhow::anyhow!("block number expected")),
Copy link
Member

@atanmarko atanmarko Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We handle case where block hash is provided in the CLI for other blockchain clients, could we do the same for zeth? In the worst case that zeth api does not support hashes, we could get the block header by hash and learn the block number.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

};

let block_trace = cached_provider
.get_provider()
.await?
.raw_request::<_, BlockTrace>("zero_getBlockTraceByNumber".into(), vec![block_number])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there a same standard API in zeth, debug_traceBlockByNumber?

https://github.com/paradigmxyz/reth/blob/main/crates/rpc/rpc-api/src/debug.rs#L73

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zeth is a wrapper over reth. This was done by Francesco earlier. We can name this API whatever we want
0xPolygonZero/zeth#9

Copy link
Member

@atanmarko atanmarko Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should stick with the standard API. It is not about renaming, reth already implements debug_traceBlockByNumber. Just the zero tracer option should be added to that one when you specify type of the tracer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya cool. Created task above to handle this in future

.await?;

let other_data =
fetch_other_block_data(cached_provider, target_block_id, checkpoint_block_number).await?;

Ok(BlockProverInput {
block_trace,
other_data,
})
}
Loading