Skip to content

Commit 3eef974

Browse files
committed
feat: support both legacy and horizon dispute managers for attestation verification
Signed-off-by: Tomás Migone <[email protected]>
1 parent 07c4dbc commit 3eef974

File tree

5 files changed

+28
-8
lines changed

5 files changed

+28
-8
lines changed

src/client_query.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ async fn run_indexer_queries(
303303
let start_time = Instant::now();
304304
// URL checked: ref df8e647b-1e6e-422a-8846-dc9ee7e0dcc2
305305
let deployment_url = url.join(&format!("subgraphs/id/{deployment}")).unwrap();
306-
let auth = IndexerAuth::Paid(&receipt, ctx.attestation_domain);
306+
let auth = IndexerAuth::Paid(&receipt, ctx.attestation_domain, ctx.legacy_attestation_domain);
307307
let result = indexer_client
308308
.query_indexer(deployment_url, auth, &indexer_query)
309309
.in_current_span()
@@ -695,7 +695,7 @@ pub async fn handle_indexer_query(
695695
.url
696696
.join(&format!("subgraphs/id/{deployment}"))
697697
.unwrap();
698-
let indexer_auth = IndexerAuth::Paid(&receipt, ctx.attestation_domain);
698+
let indexer_auth = IndexerAuth::Paid(&receipt, ctx.attestation_domain, ctx.legacy_attestation_domain);
699699

700700
let indexer_start_time = Instant::now();
701701
let result = ctx

src/client_query/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ pub struct Context {
1818
pub network: NetworkService,
1919
pub indexing_perf: IndexingPerformance,
2020
pub attestation_domain: &'static Eip712Domain,
21+
pub legacy_attestation_domain: &'static Eip712Domain,
2122
pub reporter: mpsc::UnboundedSender<reports::ClientRequest>,
2223
}

src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ pub enum BlocklistEntry {
128128
pub struct AttestationConfig {
129129
pub chain_id: String,
130130
pub dispute_manager: Address,
131+
pub legacy_dispute_manager: Address,
131132
}
132133

133134
/// The exchange rate provider.

src/indexer_client.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub struct IndexerClient {
3535
}
3636

3737
pub enum IndexerAuth<'a> {
38-
Paid(&'a Receipt, &'a Eip712Domain),
38+
Paid(&'a Receipt, &'a Eip712Domain, &'a Eip712Domain),
3939
Free(&'a str),
4040
}
4141

@@ -47,7 +47,7 @@ impl IndexerClient {
4747
query: &str,
4848
) -> Result<IndexerResponse, IndexerError> {
4949
let (auth_key, auth_value) = match auth {
50-
IndexerAuth::Paid(receipt, _) => ("Tap-Receipt", receipt.serialize()),
50+
IndexerAuth::Paid(receipt, _, _) => ("Tap-Receipt", receipt.serialize()),
5151
IndexerAuth::Free(token) => (AUTHORIZATION.as_str(), format!("Bearer {token}")),
5252
};
5353

@@ -113,18 +113,26 @@ impl IndexerClient {
113113
return Err(BadResponse(format!("unattestable response: {error}")));
114114
}
115115

116-
if let IndexerAuth::Paid(receipt, attestation_domain) = auth {
116+
if let IndexerAuth::Paid(receipt, attestation_domain, legacy_attestation_domain) = auth {
117117
match &payload.attestation {
118118
Some(attestation) => {
119119
let allocation = receipt.allocation();
120-
if let Err(err) = attestation::verify(
121-
attestation_domain,
120+
if let Err(legacy_err) = attestation::verify(
121+
legacy_attestation_domain,
122122
attestation,
123123
&allocation,
124124
query,
125125
&original_response,
126126
) {
127-
return Err(BadResponse(format!("bad attestation: {err}")));
127+
if let Err(err) = attestation::verify(
128+
attestation_domain,
129+
attestation,
130+
&allocation,
131+
query,
132+
&original_response,
133+
) {
134+
return Err(BadResponse(format!("bad attestation: {legacy_err} - {err}")));
135+
}
128136
}
129137
}
130138
None => {

src/main.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ async fn main() {
104104
conf.attestations.dispute_manager,
105105
)));
106106

107+
let legacy_attestation_domain: &'static Eip712Domain =
108+
Box::leak(Box::new(attestation::eip712_domain(
109+
conf.attestations
110+
.chain_id
111+
.parse::<ChainId>()
112+
.expect("failed to parse attestation domain chain_id"),
113+
conf.attestations.legacy_dispute_manager,
114+
)));
115+
107116
let indexer_client = IndexerClient {
108117
client: http_client.clone(),
109118
};
@@ -171,6 +180,7 @@ async fn main() {
171180
indexing_perf,
172181
network,
173182
attestation_domain,
183+
legacy_attestation_domain,
174184
reporter,
175185
};
176186

0 commit comments

Comments
 (0)