Skip to content

Commit ed808ef

Browse files
authored
Merge pull request #296 from matter-labs/verify-era-proof-attestation-tdx
refactor(verify-era-proof-attestation): modularize and restructure proof verification logic
2 parents 2ba5c45 + 95b6a2d commit ed808ef

File tree

46 files changed

+2985
-2374
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2985
-2374
lines changed

Cargo.lock

Lines changed: 323 additions & 1620 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ gpt = "4.0.0"
3232
hex = { version = "0.4.3", features = ["std"], default-features = false }
3333
intel-tee-quote-verification-rs = { package = "teepot-tee-quote-verification-rs", path = "crates/teepot-tee-quote-verification-rs", version = "0.3.0" }
3434
intel-tee-quote-verification-sys = { version = "0.2.1" }
35-
jsonrpsee-types = { version = "0.24", default-features = false }
3635
num-integer = "0.1.46"
3736
num-traits = "0.2.18"
3837
opentelemetry = { version = "0.28.0", features = ["default", "logs"] }

bin/verify-attestation/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ use anyhow::{bail, Context, Result};
77
use clap::Parser;
88

99
use std::{fs, io::Read, path::PathBuf, str::FromStr, time::UNIX_EPOCH};
10-
use teepot::{
11-
quote::{error, tee_qv_get_collateral, verify_quote_with_collateral, QuoteVerificationResult},
12-
sgx::TcbLevel,
10+
use teepot::quote::{
11+
error, tcblevel::TcbLevel, tee_qv_get_collateral, verify_quote_with_collateral,
12+
QuoteVerificationResult,
1313
};
1414

1515
#[derive(Parser, Debug)]

bin/verify-era-proof-attestation/Cargo.toml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,24 @@ repository.workspace = true
88
version.workspace = true
99

1010
[dependencies]
11-
anyhow.workspace = true
11+
bytes.workspace = true
1212
clap.workspace = true
13+
enumset.workspace = true
1314
hex.workspace = true
14-
jsonrpsee-types.workspace = true
15+
jsonrpsee-types = "0.24"
1516
reqwest.workspace = true
1617
secp256k1.workspace = true
1718
serde.workspace = true
19+
serde_json.workspace = true
1820
serde_with = { workspace = true, features = ["hex"] }
21+
serde_yaml = "0.9.33"
1922
teepot.workspace = true
23+
thiserror.workspace = true
2024
tokio.workspace = true
25+
tokio-util = "0.7.14"
2126
tracing.workspace = true
2227
tracing-subscriber.workspace = true
2328
url.workspace = true
24-
zksync_basic_types = "=0.1.0"
25-
zksync_types = "=0.1.0"
26-
zksync_web3_decl = "=0.1.0"
29+
zksync_basic_types = "27.0.0-non-semver-compat"
30+
zksync_types = "27.0.0-non-semver-compat"
31+
zksync_web3_decl = "27.0.0-non-semver-compat"
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Era Proof Attestation Verifier
2+
3+
This tool verifies the SGX/TDX attestations and signatures for zkSync Era L1 batches.
4+
5+
## Usage
6+
7+
Basic usage with attestation policy provided from a YAML file:
8+
9+
```bash
10+
verify-era-proof-attestation --rpc https://mainnet.era.zksync.io \
11+
--continuous 493220 \
12+
--attestation-policy-file examples/attestation_policy.yaml \
13+
--log-level info
14+
```
15+
16+
## Attestation Policy Configuration
17+
18+
You can specify the attestation policy either through command-line arguments or by providing a YAML configuration file.
19+
20+
### Command-line Arguments
21+
22+
The following command-line arguments are available:
23+
24+
- `--batch`, `-n <BATCH>`: The batch number or range of batch numbers to verify the attestation and signature (e.g., "
25+
42" or "42-45"). Mutually exclusive with `--continuous`.
26+
- `--continuous <FIRST_BATCH>`: Continuous mode: keep verifying new batches starting from the specified batch number
27+
until interrupted. Mutually exclusive with `--batch`.
28+
- `--rpc <URL>`: URL of the RPC server to query for the batch attestation and signature.
29+
- `--chain <CHAIN_ID>`: Chain ID of the network to query (default: L2ChainId::default()).
30+
- `--rate-limit <MILLISECONDS>`: Rate limit between requests in milliseconds (default: 0).
31+
- `--log-level <LEVEL>`: Log level for the log output. Valid values are: `off`, `error`, `warn`, `info`, `debug`,
32+
`trace` (default: `warn`).
33+
- `--attestation-policy-file <PATH>`: Path to a YAML file containing attestation policy configuration. This overrides
34+
any attestation policy settings provided via command line options.
35+
36+
Either `--batch` or `--continuous` mode must be specified.
37+
38+
### YAML Configuration File
39+
40+
The attestation policy is loaded from a YAML file using the `--attestation-policy-file` option.
41+
42+
Example YAML configuration file:
43+
44+
```yaml
45+
sgx:
46+
mrenclaves:
47+
- a2caa7055e333f69c3e46ca7ba65b135a86c90adfde2afb356e05075b7818b3c
48+
- 36eeb64cc816f80a1cf5818b26710f360714b987d3799e757cbefba7697b9589
49+
- 4a8b79e5123f4dbf23453d583cb8e5dcf4d19a6191a0be6dd85b7b3052c32faf
50+
- 1498845b3f23667356cc49c38cae7b4ac234621a5b85fdd5c52b5f5d12703ec9
51+
- 1b2374631bb2572a0e05b3be8b5cdd23c42e9d7551e1ef200351cae67c515a65
52+
- 6fb19e47d72a381a9f3235c450f8c40f01428ce19a941f689389be3eac24f42a
53+
- b610fd1d749775cc3de88beb84afe8bb79f55a19100db12d76f6a62ac576e35d
54+
- a0b1b069b01bdcf3c1517ef8d4543794a27ed4103e464be7c4afdc6136b42d66
55+
- 71e2a11a74b705082a7286b2008f812f340c0e4de19f8b151baa347eda32d057
56+
- d5a0bf8932d9a3d7af6d9405d4c6de7dcb7b720bb5510666b4396fc58ee58bb2
57+
allowed_tcb_levels:
58+
- Ok
59+
- SwHardeningNeeded
60+
allowed_advisory_ids:
61+
- INTEL-SA-00615
62+
tdx:
63+
mrs:
64+
- - 2a90c8fa38672cafd791d994beb6836b99383b2563736858632284f0f760a6446efd1e7ec457cf08b629ea630f7b4525
65+
- 3300980705adf09d28b707b79699d9874892164280832be2c386a715b6e204e0897fb564a064f810659207ba862b304f
66+
- c08ab64725566bcc8a6fb1c79e2e64744fcff1594b8f1f02d716fb66592ecd5de94933b2bc54ffbbc43a52aab7eb1146
67+
- 092a4866a9e6a1672d7439a5d106fbc6eb57b738d5bfea5276d41afa2551824365fdd66700c1ce9c0b20542b9f9d5945
68+
- 971fb52f90ec98a234301ca9b8fc30b613c33e3dd9c0cc42dcb8003d4a95d8fb218b75baf028b70a3cabcb947e1ca453
69+
- - 2a90c8fa38672cafd791d994beb6836b99383b2563736858632284f0f760a6446efd1e7ec457cf08b629ea630f7b4525
70+
- 3300980705adf09d28b707b79699d9874892164280832be2c386a715b6e204e0897fb564a064f810659207ba862b304f
71+
- c08ab64725566bcc8a6fb1c79e2e64744fcff1594b8f1f02d716fb66592ecd5de94933b2bc54ffbbc43a52aab7eb1146
72+
- 092a4866a9e6a1672d7439a5d106fbc6eb57b738d5bfea5276d41afa2551824365fdd66700c1ce9c0b20542b9f9d5945
73+
- f57bb7ed82c6ae4a29e6c9879338c592c7d42a39135583e8ccbe3940f2344b0eb6eb8503db0ffd6a39ddd00cd07d8317
74+
allowed_tcb_levels:
75+
- Ok
76+
```
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
sgx:
2+
mrenclaves:
3+
- a2caa7055e333f69c3e46ca7ba65b135a86c90adfde2afb356e05075b7818b3c
4+
- 36eeb64cc816f80a1cf5818b26710f360714b987d3799e757cbefba7697b9589
5+
- 4a8b79e5123f4dbf23453d583cb8e5dcf4d19a6191a0be6dd85b7b3052c32faf
6+
- 1498845b3f23667356cc49c38cae7b4ac234621a5b85fdd5c52b5f5d12703ec9
7+
- 1b2374631bb2572a0e05b3be8b5cdd23c42e9d7551e1ef200351cae67c515a65
8+
- 6fb19e47d72a381a9f3235c450f8c40f01428ce19a941f689389be3eac24f42a
9+
- b610fd1d749775cc3de88beb84afe8bb79f55a19100db12d76f6a62ac576e35d
10+
- a0b1b069b01bdcf3c1517ef8d4543794a27ed4103e464be7c4afdc6136b42d66
11+
- 71e2a11a74b705082a7286b2008f812f340c0e4de19f8b151baa347eda32d057
12+
- d5a0bf8932d9a3d7af6d9405d4c6de7dcb7b720bb5510666b4396fc58ee58bb2
13+
allowed_tcb_levels:
14+
- Ok
15+
- SwHardeningNeeded
16+
allowed_advisory_ids:
17+
- INTEL-SA-00615
18+
tdx:
19+
mrs:
20+
- - 2a90c8fa38672cafd791d994beb6836b99383b2563736858632284f0f760a6446efd1e7ec457cf08b629ea630f7b4525
21+
- 3300980705adf09d28b707b79699d9874892164280832be2c386a715b6e204e0897fb564a064f810659207ba862b304f
22+
- c08ab64725566bcc8a6fb1c79e2e64744fcff1594b8f1f02d716fb66592ecd5de94933b2bc54ffbbc43a52aab7eb1146
23+
- 092a4866a9e6a1672d7439a5d106fbc6eb57b738d5bfea5276d41afa2551824365fdd66700c1ce9c0b20542b9f9d5945
24+
- 971fb52f90ec98a234301ca9b8fc30b613c33e3dd9c0cc42dcb8003d4a95d8fb218b75baf028b70a3cabcb947e1ca453
25+
- - 2a90c8fa38672cafd791d994beb6836b99383b2563736858632284f0f760a6446efd1e7ec457cf08b629ea630f7b4525
26+
- 3300980705adf09d28b707b79699d9874892164280832be2c386a715b6e204e0897fb564a064f810659207ba862b304f
27+
- c08ab64725566bcc8a6fb1c79e2e64744fcff1594b8f1f02d716fb66592ecd5de94933b2bc54ffbbc43a52aab7eb1146
28+
- 092a4866a9e6a1672d7439a5d106fbc6eb57b738d5bfea5276d41afa2551824365fdd66700c1ce9c0b20542b9f9d5945
29+
- f57bb7ed82c6ae4a29e6c9879338c592c7d42a39135583e8ccbe3940f2344b0eb6eb8503db0ffd6a39ddd00cd07d8317
30+
allowed_tcb_levels:
31+
- Ok

bin/verify-era-proof-attestation/src/args.rs

Lines changed: 0 additions & 95 deletions
This file was deleted.

bin/verify-era-proof-attestation/src/client.rs

Lines changed: 0 additions & 45 deletions
This file was deleted.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright (c) 2023-2025 Matter Labs
3+
4+
//! HTTP client for making requests to external services
5+
6+
use reqwest::Client;
7+
use serde::{de::DeserializeOwned, Serialize};
8+
use std::time::Duration;
9+
use url::Url;
10+
11+
use crate::{
12+
core::DEFAULT_HTTP_REQUEST_TIMEOUT,
13+
error::{Error, Result},
14+
};
15+
16+
/// Client for making HTTP requests
17+
#[derive(Clone)]
18+
pub struct HttpClient {
19+
client: Client,
20+
}
21+
22+
impl HttpClient {
23+
/// Create a new HTTP client with default configuration
24+
pub fn new() -> Self {
25+
let client = Client::builder()
26+
.timeout(Duration::from_secs(DEFAULT_HTTP_REQUEST_TIMEOUT))
27+
.build()
28+
.expect("Failed to create HTTP client");
29+
30+
Self { client }
31+
}
32+
33+
/// Make a POST request to the specified URL with the provided body
34+
pub async fn post<T: Serialize>(&self, url: &Url, body: T) -> Result<String> {
35+
let response = self.client.post(url.clone()).json(&body).send().await?;
36+
self.handle_response(response).await
37+
}
38+
39+
/// Send a JSON request and parse the response
40+
pub async fn send_json<T: Serialize, R: DeserializeOwned>(
41+
&self,
42+
url: &Url,
43+
body: T,
44+
) -> Result<R> {
45+
let response_text = self.post(url, body).await?;
46+
let response: R = serde_json::from_str(&response_text)
47+
.map_err(|e| Error::JsonRpcInvalidResponse(e.to_string()))?;
48+
49+
Ok(response)
50+
}
51+
52+
/// Handle the HTTP response
53+
async fn handle_response(&self, response: reqwest::Response) -> Result<String> {
54+
let status = response.status();
55+
let body = response.text().await?;
56+
57+
if status.is_success() {
58+
Ok(body)
59+
} else {
60+
Err(Error::Http {
61+
status_code: status.as_u16(),
62+
message: body,
63+
})
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)