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

fix: sp1 patches #349

Closed
wants to merge 6 commits into from
Closed
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
421 changes: 355 additions & 66 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@ risc0-build = { version = "1.0.1" }
risc0-binfmt = { version = "1.0.1" }

# SP1
sp1-sdk = { version = "1.0.1" }
sp1-zkvm = { version = "1.0.1" }
sp1-helper = { version = "1.0.1" }
# sp1-sdk = { version = "1.0.1" }
# sp1-zkvm = { version = "1.0.1" }
# sp1-helper = { version = "1.0.1" }
sp1-sdk = { git = "https://github.com/succinctlabs/sp1", branch = "dev" }
sp1-zkvm = { git = "https://github.com/succinctlabs/sp1", branch = "dev" }
sp1-helper = { git = "https://github.com/succinctlabs/sp1", branch = "dev" }

# alloy
alloy-rlp = { version = "0.3.4", default-features = false }
Expand Down Expand Up @@ -134,7 +137,7 @@ utoipa-scalar = { version = "0.1.0", features = ["axum"] }
utoipa = { version = "4.2.0", features = ["axum_extras"] }
structopt = "0.3.24"
prometheus = { version = "0.13.3", features = ["process"] }
tokio = { version = "^1.23", features = ["full"] }
tokio = { version = "^1.39.3", features = ["full"] }
tokio-util = { version = "0.7.11" }
reqwest = { version = "0.11.22", features = ["json"] }
url = "2.5.0"
Expand Down
8 changes: 4 additions & 4 deletions core/src/provider/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl BlockDataProvider for RpcBlockDataProvider {
batch
.send()
.await
.map_err(|_| RaikoError::RPC("Error sending batch request".to_owned()))?;
.map_err(|e| RaikoError::RPC(format!("Error sending batch request: {e}")))?;

let mut blocks = Vec::with_capacity(max_batch_size);
// Collect the data from the batch
Expand Down Expand Up @@ -132,7 +132,7 @@ impl BlockDataProvider for RpcBlockDataProvider {
batch
.send()
.await
.map_err(|_| RaikoError::RPC("Error sending batch request".to_owned()))?;
.map_err(|e| RaikoError::RPC(format!("Error sending batch request: {e}")))?;

let mut accounts = vec![];
// Collect the data from the batch
Expand Down Expand Up @@ -197,7 +197,7 @@ impl BlockDataProvider for RpcBlockDataProvider {
batch
.send()
.await
.map_err(|_| RaikoError::RPC("Error sending batch request".to_owned()))?;
.map_err(|e| RaikoError::RPC(format!("Error sending batch request: {e}")))?;

let mut values = Vec::with_capacity(max_batch_size);
// Collect the data from the batch
Expand Down Expand Up @@ -299,7 +299,7 @@ impl BlockDataProvider for RpcBlockDataProvider {
batch
.send()
.await
.map_err(|_| RaikoError::RPC("Error sending batch request".to_owned()))?;
.map_err(|e| RaikoError::RPC(format!("Error sending batch request: {e}")))?;

// Collect the data from the batch
for request in requests {
Expand Down
11 changes: 7 additions & 4 deletions host/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,18 @@ impl ProofActor {
pub async fn run_task(&mut self, proof_request: ProofRequest, _permit: OwnedSemaphorePermit) {
let cancel_token = CancellationToken::new();

let Ok((chain_id, blockhash)) = get_task_data(
let res = get_task_data(
&proof_request.network,
proof_request.block_number,
&self.chain_specs,
)
.await
else {
error!("Could not get task data for {proof_request:?}");
.await;
if let Err(e) = res {
error!("Could not get task data for {proof_request:?}: {e}");
return;
}
let Ok((chain_id, blockhash)) = res else {
unreachable!();
};

let key = TaskDescriptor::from((
Expand Down
4 changes: 2 additions & 2 deletions provers/sp1/driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl Prover for Sp1Prover {
output.header.number, proof_id
);
network_prover
.wait_proof::<sp1_sdk::SP1ProofWithPublicValues>(&proof_id)
.wait_proof::<sp1_sdk::SP1ProofWithPublicValues>(&proof_id, None)
.await
.map_err(|e| ProverError::GuestError(format!("Sp1: network proof failed {:?}", e)))
.unwrap()
Expand Down Expand Up @@ -199,7 +199,7 @@ fn get_env_mock() -> ProverMode {
fn init_verifier() -> Result<PathBuf, ProverError> {
// In cargo run, Cargo sets the working directory to the root of the workspace
let output_dir: PathBuf = CONTRACT_PATH.into();
let artifacts_dir = sp1_sdk::install::try_install_plonk_bn254_artifacts();
let artifacts_dir = sp1_sdk::install::try_install_circuit_artifacts();
if !artifacts_dir.join("SP1Verifier.sol").exists() {
return Err(ProverError::GuestError(format!(
"verifier file not found at {:?}",
Expand Down
81 changes: 24 additions & 57 deletions provers/sp1/guest/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions provers/sp1/guest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ path = "src/benchmark/bn254_mul.rs"

[dependencies]
raiko-lib = { path = "../../../lib", features = ["std", "sp1", "proof_of_equivalence"] }
sp1-zkvm ={ version = "1.0.1" }
sp1-zkvm = { git = "https://github.com/succinctlabs/sp1", branch = "dev" }
sp1-core = "1.0.1"
sha2-v0-10-8 = { git = "https://github.com/sp1-patches/RustCrypto-hashes", package = "sha2", branch = "patch-v0.10.8" }
secp256k1 = { git = "https://github.com/sp1-patches/rust-secp256k1", branch = "feat/patch-ecrecover" }
secp256k1 = { git = "https://github.com/sp1-patches/rust-secp256k1", branch = "patch-secp256k1-v0.29.0" }
harness-core = { path = "../../../harness/core" }
harness = { path = "../../../harness/macro", features = ["sp1"]}
substrate-bn = "0.6.0"
Expand All @@ -56,9 +56,13 @@ revm-primitives = { git = "https://github.com/taikoxyz/revm.git", branch = "v36-
revm-precompile = { git = "https://github.com/taikoxyz/revm.git", branch = "v36-taiko" }
c-kzg = { git = "https://github.com/brechtpd/c-kzg-4844", branch = "for-alpha7" }
blst = { git = "https://github.com/CeciliaZ030/blst.git", branch = "v0.3.12-serialize" }
ecdsa = { git = "https://github.com/taikoxyz/signatures.git", branch = "0.16.9" }
secp256k1 = { git = "https://github.com/sp1-patches/rust-secp256k1", branch = "patch-secp256k1-v0.29.0" }


sha2 = { git = "https://github.com/sp1-patches/RustCrypto-hashes", branch = "patch-v0.10.8", package = "sha2" }
ecdsa-core = { git = "https://github.com/sp1-patches/signatures", package = "ecdsa", branch = "patch-ecdsa-v0.16.9" }
tiny-keccak = { git = "https://github.com/sp1-patches/tiny-keccak", branch = "patch-v2.0.2" }
secp256k1 = { git = "https://github.com/sp1-patches/rust-secp256k1", branch = "feat/patch-ecrecover" }
bn = { package = "substrate-bn", git = "https://github.com/sp1-patches/bn", branch = "master" }

[features]
default = ["sp1-cycle-tracker"]
Expand Down
Binary file modified provers/sp1/guest/elf/sp1-guest
Binary file not shown.
11 changes: 0 additions & 11 deletions provers/sp1/guest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,6 @@ pub fn main() {
let input = bincode::deserialize::<GuestInput>(&input).unwrap();
ct.end();

revm_precompile::zk_op::ZKVM_OPERATOR.get_or_init(|| Box::new(Sp1Operator {}));
revm_precompile::zk_op::ZKVM_OPERATIONS
.set(Box::new(vec![
ZkOperation::Bn128Add,
ZkOperation::Bn128Mul,
ZkOperation::Sha256,
//already patched with https://github.com/CeciliaZ030/rust-secp256k1
ZkOperation::Secp256k1,
]))
.expect("Failed to set ZkvmOperations");

ct = CycleTracker::start("calculate_block_header");
let header = calculate_block_header(&input);
ct.end();
Expand Down
6 changes: 4 additions & 2 deletions script/prove-block.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ elif [ "$proof" == "sp1" ]; then
proofParam='
"proof_type": "sp1",
"sp1": {
"recursion": "plonk",
"recursion": "compressed",
"prover": "network",
"verify": false
}
Expand Down Expand Up @@ -131,7 +131,7 @@ for block in $(eval echo {$rangeStart..$rangeEnd}); do
fi

echo "- proving block $block"
curl --location --request POST 'http://localhost:8080/proof' \
curl --location --request POST 'http://localhost:9000/proof' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer 4cbd753fbcbc2639de804f8ce425016a50e0ecd53db00cb5397912e83f5e570e' \
--data-raw "{
Expand All @@ -143,4 +143,6 @@ for block in $(eval echo {$rangeStart..$rangeEnd}); do
$proofParam
}"
echo ""

sleep 25.0
done
Loading
Loading