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

Update Requirements #43

Merged
merged 5 commits into from
Sep 8, 2024
Merged
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
2 changes: 1 addition & 1 deletion prover/src/provers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub trait Prover<T> {
}

const DEGREE_BITS_RANGE: [[std::ops::Range<usize>; 6]; 1] =
[[10..21, 12..22, 12..21, 8..21, 8..21, 13..23]];
[[10..21, 12..22, 12..21, 8..21, 6..21, 13..23]];
// const DEGREE_BITS_RANGE: [[std::ops::Range<usize>; 6]; 5] = [
// [16..17, 12..13, 10..16, 9..12, 15..17, 17..19],
// [16..17, 15..17, 12..19, 9..14, 15..17, 19..20],
Expand Down
14 changes: 12 additions & 2 deletions service/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
fn main() -> Result<(), Box<dyn std::error::Error>> {
tonic_build::compile_protos("proto/src/proto/prover/v1/prover.proto")?;
tonic_build::compile_protos("proto/src/proto/stage/v1/stage.proto")?;
tonic_build::configure()
.protoc_arg("--experimental_allow_proto3_optional")
.compile(
&["proto/src/proto/prover/v1/prover.proto"],
&["proto/src/proto"],
)?;
tonic_build::configure()
.protoc_arg("--experimental_allow_proto3_optional")
.compile(
&["proto/src/proto/stage/v1/stage.proto"],
&["proto/src/proto"],
)?;
Ok(())
}
26 changes: 8 additions & 18 deletions service/examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,14 @@

* Compile the Go code to MIPS

Write your own hello.go, and compile with(Recommended use golang1.20)
Write your own hello.go, and compile

```
$ GOOS=linux GOARCH=mips GOMIPS=softfloat go build hello.go -o /tmp/zkm/test/hello_world
```

If you build your own server, you can use Docker Compose (The image is built based on AMD64)

Minimum Requirements
| SEG_SIZE | RAM |
| ------- | ------- |
| 1024 | 16G |
| 16384 | 28.2G |
| 32768 | 95.2G |
| 65536 | 96.3G |
| 262144 | 130.1G |

```
$ docker-compose up -d
```
Expand All @@ -42,7 +33,7 @@ $ RUST_LOG=info ELF_PATH=/tmp/zkm/test/hello_world OUTPUT_DIR=/tmp/zkm/test ENDP

## [Minigeth](https://github.com/zkMIPS/cannon-mips)

* Compile the minigeth_mips Please use Golang1.20 version
* Compile the minigeth_mips

```
$ git clone https://github.com/zkMIPS/cannon-mips
Expand Down Expand Up @@ -84,13 +75,12 @@ $ cargo build --release --target=mips-unknown-linux-musl

* Adjust parameter request stage service

Name | Description
------------ | ------------
ENDPOINT | zkm-prover service endpoint
CA_CERT_PATH | zkm-prover service CA CERT
PRIVATE_KEY | wallet private key, used for message signing
ELF_PATH | the file compiled in the previous step
PUBLIC_INPUT_PATH | Output file for the Generate Suite_json step
- `ENDPOINT`: zkm-prover service endpoint
- `CA_CERT_PATH`: zkm-prover service CA CERT
- `PRIVATE_KEY`: wallet private key, used for message signing
- `ELF_PATH`: the file compiled in the previous step
- `PUBLIC_INPUT_PATH`: Output file for the Generate Suite_json step

```
$ export RUST_LOG=info
$ ENDPOINT=... CA_CERT_PATH=... PRIVATE_KEY=... ELF_PATH=...revm SEG_SIZE=262144 PUBLIC_INPUT_PATH=... cargo run --release --example stage
Expand Down
17 changes: 12 additions & 5 deletions service/examples/stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,17 @@ pub mod stage_service {
async fn sign_ecdsa(request: &mut GenerateProofRequest, private_key: &str) {
if !private_key.is_empty() {
let wallet = private_key.parse::<LocalWallet>().unwrap();
let sign_data = format!(
"{}&{}&{}&{}",
request.proof_id, request.block_no, request.seg_size, request.args
);
let sign_data = match request.block_no {
Some(block_no) => {
format!(
"{}&{}&{}&{}",
request.proof_id, block_no, request.seg_size, request.args
)
}
None => {
format!("{}&{}&{}", request.proof_id, request.seg_size, request.args)
}
};
let signature = wallet.sign_message(sign_data).await.unwrap();
request.signature = signature.to_string();
}
Expand Down Expand Up @@ -86,7 +93,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
proof_id: proof_id.clone(),
elf_data,
block_data,
block_no,
block_no: Some(block_no),
seg_size,
args,
public_input_stream,
Expand Down
105 changes: 46 additions & 59 deletions service/proto/src/proto/prover/v1/prover.proto
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,17 @@ message GetTaskResultResponse {
}

message SplitElfRequest {
uint64 chain_id = 1;
uint64 timestamp = 2;
string proof_id = 3;
string computed_request_id = 4;

string base_dir = 5;
string elf_path = 6;
string seg_path = 7;
uint64 block_no = 8;
uint32 seg_size = 9;
string args = 10;
string public_input_path = 11;
string private_input_path = 12;
string output_path = 13;
string proof_id = 1;
string computed_request_id = 2;
string base_dir = 3;
string elf_path = 4;
string seg_path = 5;
uint64 block_no = 6;
uint32 seg_size = 7;
string args = 8;
string public_input_path = 9;
string private_input_path = 10;
string output_path = 11;
}

message SplitElfResponse {
Expand All @@ -85,17 +82,15 @@ message SplitElfResponse {
}

message ProveRequest {
uint64 chain_id = 1;
uint64 timestamp = 2;
string proof_id = 3;
string computed_request_id = 4;
string proof_id = 1;
string computed_request_id = 2;

string base_dir = 5;
string seg_path = 6;
uint64 block_no = 7;
uint32 seg_size = 8;
string proof_path = 9;
string pub_value_path = 10;
string base_dir = 3;
string seg_path = 4;
uint64 block_no = 5;
uint32 seg_size = 6;
string proof_path = 7;
string pub_value_path = 8;
}

message ProveResponse {
Expand All @@ -111,21 +106,18 @@ message AggregateInput {
};

message AggregateRequest {
uint64 chain_id = 1;
uint64 timestamp = 2;
string proof_id = 3;
string computed_request_id = 4;

string base_dir = 5;
string seg_path = 6;
uint64 block_no = 7;
uint32 seg_size = 8;
AggregateInput input1 = 9;
AggregateInput input2 = 10;
string agg_proof_path = 11;
string agg_pub_value_path = 12;
bool is_final = 13;
string output_dir = 14;
string proof_id = 1;
string computed_request_id = 2;
string base_dir = 3;
string seg_path = 4;
uint64 block_no = 5;
uint32 seg_size = 6;
AggregateInput input1 = 7;
AggregateInput input2 = 8;
string agg_proof_path = 9;
string agg_pub_value_path = 10;
bool is_final = 11;
string output_dir = 12;
}

message AggregateResponse {
Expand All @@ -135,19 +127,16 @@ message AggregateResponse {
}

message AggregateAllRequest {
uint64 chain_id = 1;
uint64 timestamp = 2;
string proof_id = 3;
string computed_request_id = 4;

string base_dir = 5;
string seg_path = 6;
uint64 block_no = 7;
uint32 seg_size = 8;
uint32 proof_num = 9;
string proof_dir = 10;
string pub_value_dir = 11;
string output_dir = 12;
string proof_id = 1;
string computed_request_id = 2;
string base_dir = 3;
string seg_path = 4;
uint64 block_no = 5;
uint32 seg_size = 6;
uint32 proof_num = 7;
string proof_dir = 8;
string pub_value_dir = 9;
string output_dir = 10;
}

message AggregateAllResponse {
Expand All @@ -157,13 +146,11 @@ message AggregateAllResponse {
}

message FinalProofRequest {
uint64 chain_id = 1;
uint64 timestamp = 2;
string proof_id = 3;
string computed_request_id = 4;
bytes common_circuit_data = 5;
bytes verifier_only_circuit_data = 6;
bytes proof_with_public_inputs = 7;
string proof_id = 1;
string computed_request_id = 2;
bytes common_circuit_data = 3;
bytes verifier_only_circuit_data = 4;
bytes proof_with_public_inputs = 5;
}

message FinalProofResponse {
Expand Down
22 changes: 10 additions & 12 deletions service/proto/src/proto/stage/v1/stage.proto
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,16 @@ message BlockFileItem {
}

message GenerateProofRequest {
uint64 chain_id = 1;
uint64 timestamp = 2;
string proof_id = 3;
bytes elf_data = 4;
repeated BlockFileItem block_data = 5;
uint64 block_no = 6;
uint32 seg_size = 7;
string args = 8;
string signature = 9;
bytes public_input_stream = 10;
bytes private_input_stream = 11;
bool execute_only = 12;
string proof_id = 1;
bytes elf_data = 2;
repeated BlockFileItem block_data = 3;
optional uint64 block_no = 4;
uint32 seg_size = 5;
string args = 6;
string signature = 7;
bytes public_input_stream = 8;
bytes private_input_stream = 9;
bool execute_only = 10;
}

message GenerateProofResponse {
Expand Down
10 changes: 0 additions & 10 deletions service/src/prover_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ pub async fn split(mut split_task: SplitTask, tls_config: Option<TlsConfig>) ->
let client = get_idle_client(tls_config).await;
if let Some((addrs, mut client)) = client {
let request = SplitElfRequest {
chain_id: 0,
timestamp: 0,
proof_id: split_task.proof_id.clone(),
computed_request_id: split_task.task_id.clone(),
base_dir: split_task.base_dir.clone(),
Expand Down Expand Up @@ -123,8 +121,6 @@ pub async fn prove(mut prove_task: ProveTask, tls_config: Option<TlsConfig>) ->
let client = get_idle_client(tls_config).await;
if let Some((addrs, mut client)) = client {
let request = ProveRequest {
chain_id: 0,
timestamp: 0,
proof_id: prove_task.proof_id.clone(),
computed_request_id: prove_task.task_id.clone(),
base_dir: prove_task.base_dir.clone(),
Expand Down Expand Up @@ -163,8 +159,6 @@ pub async fn aggregate(mut agg_task: AggTask, tls_config: Option<TlsConfig>) ->
let client = get_idle_client(tls_config).await;
if let Some((addrs, mut client)) = client {
let request = AggregateRequest {
chain_id: 0,
timestamp: 0,
proof_id: agg_task.proof_id.clone(),
computed_request_id: agg_task.task_id.clone(),
base_dir: agg_task.base_dir.clone(),
Expand Down Expand Up @@ -218,8 +212,6 @@ pub async fn aggregate_all(
let client = get_idle_client(tls_config).await;
if let Some((addrs, mut client)) = client {
let request = AggregateAllRequest {
chain_id: 0,
timestamp: 0,
proof_id: agg_all_task.proof_id.clone(),
computed_request_id: agg_all_task.task_id.clone(),
base_dir: agg_all_task.base_dir.clone(),
Expand Down Expand Up @@ -283,8 +275,6 @@ pub async fn final_proof(
file::new(&verifier_only_circuit_data_file).read().unwrap();
let proof_with_public_inputs = file::new(&proof_with_public_inputs_file).read().unwrap();
let request = FinalProofRequest {
chain_id: 0,
timestamp: 0,
proof_id: final_task.proof_id.clone(),
computed_request_id: final_task.task_id.clone(),
common_circuit_data,
Expand Down
20 changes: 14 additions & 6 deletions service/src/stage_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,17 @@ impl StageServiceSVC {
}

pub fn valid_signature(&self, request: &GenerateProofRequest) -> Result<String, Error> {
let sign_data = format!(
"{}&{}&{}&{}",
request.proof_id, request.block_no, request.seg_size, request.args
);
let sign_data = match request.block_no {
Some(block_no) => {
format!(
"{}&{}&{}&{}",
request.proof_id, block_no, request.seg_size, request.args
)
}
None => {
format!("{}&{}&{}", request.proof_id, request.seg_size, request.args)
}
};
let signature = Signature::from_str(&request.signature)?;
let recovered = signature.recover(sign_data)?;
Ok(hex::encode(recovered))
Expand Down Expand Up @@ -193,7 +200,8 @@ impl StageService for StageServiceSVC {
.write(&request.get_ref().elf_data)
.map_err(|e| Status::internal(e.to_string()))?;

let block_dir = format!("{}/0_{}", dir_path, request.get_ref().block_no);
let block_no = request.get_ref().block_no.unwrap_or(0u64);
let block_dir = format!("{}/0_{}", dir_path, block_no);
file::new(&block_dir)
.create_dir_all()
.map_err(|e| Status::internal(e.to_string()))?;
Expand Down Expand Up @@ -279,7 +287,7 @@ impl StageService for StageServiceSVC {
&private_input_stream_path,
&output_stream_path,
&request.get_ref().args,
request.get_ref().block_no,
block_no,
request.get_ref().seg_size,
request.get_ref().execute_only,
);
Expand Down
Loading