Skip to content

Commit ebe950b

Browse files
authored
fix: use the correct eip712 domain for each part of dips (#667)
* fix: use the correct eip712 domain for each part of dips * fix: some details
1 parent 1dc2a79 commit ebe950b

File tree

3 files changed

+30
-24
lines changed

3 files changed

+30
-24
lines changed

crates/dips/src/lib.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ use store::AgreementStore;
2727
use thiserror::Error;
2828
use uuid::Uuid;
2929

30-
/// The Arbitrum One (mainnet) chain ID (eip155).
31-
const CHAIN_ID_ARBITRUM_ONE: ChainId = 0xa4b1; // 42161
32-
3330
/// DIPs EIP-712 domain salt
3431
const EIP712_DOMAIN_SALT: B256 =
3532
b256!("b4632c657c26dce5d4d7da1d65bda185b14ff8f905ddbb03ea0382ed06c5ef28");
@@ -38,29 +35,29 @@ const EIP712_DOMAIN_SALT: B256 =
3835
pub const PROTOCOL_VERSION: u64 = 1; // MVP
3936

4037
/// Create an EIP-712 domain given a chain ID and dispute manager address.
41-
pub fn dips_agreement_eip712_domain() -> Eip712Domain {
38+
pub fn dips_agreement_eip712_domain(chain_id: ChainId) -> Eip712Domain {
4239
eip712_domain! {
4340
name: "Graph Protocol Indexing Agreement",
4441
version: "0",
45-
chain_id: CHAIN_ID_ARBITRUM_ONE,
42+
chain_id: chain_id,
4643
salt: EIP712_DOMAIN_SALT,
4744
}
4845
}
4946

50-
pub fn dips_cancellation_eip712_domain() -> Eip712Domain {
47+
pub fn dips_cancellation_eip712_domain(chain_id: ChainId) -> Eip712Domain {
5148
eip712_domain! {
5249
name: "Graph Protocol Indexing Agreement Cancellation",
5350
version: "0",
54-
chain_id: CHAIN_ID_ARBITRUM_ONE,
51+
chain_id: chain_id,
5552
salt: EIP712_DOMAIN_SALT,
5653
}
5754
}
5855

59-
pub fn dips_collection_eip712_domain() -> Eip712Domain {
56+
pub fn dips_collection_eip712_domain(chain_id: ChainId) -> Eip712Domain {
6057
eip712_domain! {
6158
name: "Graph Protocol Indexing Agreement Collection",
6259
version: "0",
63-
chain_id: CHAIN_ID_ARBITRUM_ONE,
60+
chain_id: chain_id,
6461
salt: EIP712_DOMAIN_SALT,
6562
}
6663
}
@@ -393,7 +390,7 @@ mod test {
393390
use indexer_monitor::EscrowAccounts;
394391
use rand::{distr::Alphanumeric, Rng};
395392
use thegraph_core::alloy::{
396-
primitives::{Address, FixedBytes, U256},
393+
primitives::{Address, ChainId, FixedBytes, U256},
397394
signers::local::PrivateKeySigner,
398395
sol_types::{Eip712Domain, SolValue},
399396
};
@@ -406,6 +403,9 @@ mod test {
406403
SubgraphIndexingVoucherMetadata,
407404
};
408405

406+
/// The Arbitrum One (mainnet) chain ID (eip155).
407+
const CHAIN_ID_ARBITRUM_ONE: ChainId = 0xa4b1; // 42161
408+
409409
#[tokio::test]
410410
async fn test_validate_and_create_agreement() -> anyhow::Result<()> {
411411
let deployment_id = "Qmbg1qF4YgHjiVfsVt6a13ddrVcRtWyJQfD4LA3CwHM29f".to_string();
@@ -435,7 +435,7 @@ mod test {
435435
deadline: 10000000,
436436
metadata: metadata.abi_encode().into(),
437437
};
438-
let domain = dips_agreement_eip712_domain();
438+
let domain = dips_agreement_eip712_domain(CHAIN_ID_ARBITRUM_ONE);
439439

440440
let voucher = voucher.sign(&domain, payer)?;
441441
let abi_voucher = voucher.abi_encode();
@@ -491,7 +491,7 @@ mod test {
491491
metadata: metadata.abi_encode().into(),
492492
};
493493

494-
let domain = dips_agreement_eip712_domain();
494+
let domain = dips_agreement_eip712_domain(CHAIN_ID_ARBITRUM_ONE);
495495
let signed = voucher.sign(&domain, payer).unwrap();
496496
assert_eq!(
497497
signed
@@ -545,7 +545,7 @@ mod test {
545545
deadline: 10000000,
546546
metadata: metadata.abi_encode().into(),
547547
};
548-
let domain = dips_agreement_eip712_domain();
548+
let domain = dips_agreement_eip712_domain(CHAIN_ID_ARBITRUM_ONE);
549549

550550
let mut signed = voucher.sign(&domain, payer).unwrap();
551551
signed.voucher.service = Address::repeat_byte(9);
@@ -597,7 +597,7 @@ mod test {
597597
let voucher = CancellationRequest {
598598
agreement_id: Uuid::now_v7().as_bytes().into(),
599599
};
600-
let domain = dips_cancellation_eip712_domain();
600+
let domain = dips_cancellation_eip712_domain(CHAIN_ID_ARBITRUM_ONE);
601601

602602
let signed = voucher.sign(&domain, signer).unwrap();
603603

@@ -627,7 +627,7 @@ mod test {
627627
}
628628
}
629629
pub fn domain(&self) -> Eip712Domain {
630-
dips_agreement_eip712_domain()
630+
dips_agreement_eip712_domain(CHAIN_ID_ARBITRUM_ONE)
631631
}
632632

633633
pub fn test_voucher_with_signer(
@@ -637,7 +637,7 @@ mod test {
637637
) -> SignedIndexingAgreementVoucher {
638638
let agreement_id = Uuid::now_v7();
639639

640-
let domain = dips_agreement_eip712_domain();
640+
let domain = dips_agreement_eip712_domain(CHAIN_ID_ARBITRUM_ONE);
641641

642642
let voucher = IndexingAgreementVoucher {
643643
agreement_id: agreement_id.as_bytes().into(),
@@ -693,7 +693,7 @@ mod test {
693693
.await?;
694694

695695
// Create and sign cancellation request
696-
let cancel_domain = dips_cancellation_eip712_domain();
696+
let cancel_domain = dips_cancellation_eip712_domain(CHAIN_ID_ARBITRUM_ONE);
697697
let cancel_request = CancellationRequest {
698698
agreement_id: agreement_id.as_bytes().into(),
699699
};

crates/dips/src/server.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ use std::sync::Arc;
66
use async_trait::async_trait;
77
#[cfg(test)]
88
use indexer_monitor::EscrowAccounts;
9-
use thegraph_core::alloy::{primitives::Address, sol_types::Eip712Domain};
9+
use thegraph_core::alloy::primitives::{Address, ChainId};
1010
use tonic::{Request, Response, Status};
1111

1212
use crate::{
13+
dips_agreement_eip712_domain, dips_cancellation_eip712_domain,
1314
ipfs::IpfsFetcher,
1415
price::PriceCalculator,
1516
proto::indexer::graphprotocol::indexer::dips::{
@@ -63,7 +64,7 @@ pub struct DipsServer {
6364
pub ctx: Arc<DipsServerContext>,
6465
pub expected_payee: Address,
6566
pub allowed_payers: Vec<Address>,
66-
pub domain: Eip712Domain,
67+
pub chain_id: ChainId,
6768
}
6869

6970
#[async_trait]
@@ -88,7 +89,7 @@ impl IndexerDipsService for DipsServer {
8889
// - The subgraph deployment is available on IPFS
8990
validate_and_create_agreement(
9091
self.ctx.clone(),
91-
&self.domain,
92+
&dips_agreement_eip712_domain(self.chain_id),
9293
&self.expected_payee,
9394
&self.allowed_payers,
9495
signed_voucher,
@@ -114,9 +115,13 @@ impl IndexerDipsService for DipsServer {
114115
return Err(Status::invalid_argument("invalid version"));
115116
}
116117

117-
validate_and_cancel_agreement(self.ctx.store.clone(), &self.domain, signed_cancellation)
118-
.await
119-
.map_err(Into::<tonic::Status>::into)?;
118+
validate_and_cancel_agreement(
119+
self.ctx.store.clone(),
120+
&dips_cancellation_eip712_domain(self.chain_id),
121+
signed_cancellation,
122+
)
123+
.await
124+
.map_err(Into::<tonic::Status>::into)?;
120125

121126
Ok(tonic::Response::new(CancelAgreementResponse {}))
122127
}

crates/service/src/service.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ pub async fn run() -> anyhow::Result<()> {
9898
config.blockchain.chain_id as u64,
9999
config.blockchain.receipts_verifier_address,
100100
);
101+
let chain_id = config.blockchain.chain_id as u64;
101102

102103
let host_and_port = config.service.host_and_port;
103104
let indexer_address = config.indexer.indexer_address;
@@ -159,7 +160,7 @@ pub async fn run() -> anyhow::Result<()> {
159160
ctx: Arc::new(ctx),
160161
expected_payee: indexer_address,
161162
allowed_payers: allowed_payers.clone(),
162-
domain: domain_separator,
163+
chain_id,
163164
};
164165

165166
info!("starting dips grpc server on {}", addr);

0 commit comments

Comments
 (0)