diff --git a/crates/dips/src/lib.rs b/crates/dips/src/lib.rs index 5a0144221..84d8c5a32 100644 --- a/crates/dips/src/lib.rs +++ b/crates/dips/src/lib.rs @@ -27,9 +27,6 @@ use store::AgreementStore; use thiserror::Error; use uuid::Uuid; -/// The Arbitrum One (mainnet) chain ID (eip155). -const CHAIN_ID_ARBITRUM_ONE: ChainId = 0xa4b1; // 42161 - /// DIPs EIP-712 domain salt const EIP712_DOMAIN_SALT: B256 = b256!("b4632c657c26dce5d4d7da1d65bda185b14ff8f905ddbb03ea0382ed06c5ef28"); @@ -38,29 +35,29 @@ const EIP712_DOMAIN_SALT: B256 = pub const PROTOCOL_VERSION: u64 = 1; // MVP /// Create an EIP-712 domain given a chain ID and dispute manager address. -pub fn dips_agreement_eip712_domain() -> Eip712Domain { +pub fn dips_agreement_eip712_domain(chain_id: ChainId) -> Eip712Domain { eip712_domain! { name: "Graph Protocol Indexing Agreement", version: "0", - chain_id: CHAIN_ID_ARBITRUM_ONE, + chain_id: chain_id, salt: EIP712_DOMAIN_SALT, } } -pub fn dips_cancellation_eip712_domain() -> Eip712Domain { +pub fn dips_cancellation_eip712_domain(chain_id: ChainId) -> Eip712Domain { eip712_domain! { name: "Graph Protocol Indexing Agreement Cancellation", version: "0", - chain_id: CHAIN_ID_ARBITRUM_ONE, + chain_id: chain_id, salt: EIP712_DOMAIN_SALT, } } -pub fn dips_collection_eip712_domain() -> Eip712Domain { +pub fn dips_collection_eip712_domain(chain_id: ChainId) -> Eip712Domain { eip712_domain! { name: "Graph Protocol Indexing Agreement Collection", version: "0", - chain_id: CHAIN_ID_ARBITRUM_ONE, + chain_id: chain_id, salt: EIP712_DOMAIN_SALT, } } @@ -393,7 +390,7 @@ mod test { use indexer_monitor::EscrowAccounts; use rand::{distr::Alphanumeric, Rng}; use thegraph_core::alloy::{ - primitives::{Address, FixedBytes, U256}, + primitives::{Address, ChainId, FixedBytes, U256}, signers::local::PrivateKeySigner, sol_types::{Eip712Domain, SolValue}, }; @@ -406,6 +403,9 @@ mod test { SubgraphIndexingVoucherMetadata, }; + /// The Arbitrum One (mainnet) chain ID (eip155). + const CHAIN_ID_ARBITRUM_ONE: ChainId = 0xa4b1; // 42161 + #[tokio::test] async fn test_validate_and_create_agreement() -> anyhow::Result<()> { let deployment_id = "Qmbg1qF4YgHjiVfsVt6a13ddrVcRtWyJQfD4LA3CwHM29f".to_string(); @@ -435,7 +435,7 @@ mod test { deadline: 10000000, metadata: metadata.abi_encode().into(), }; - let domain = dips_agreement_eip712_domain(); + let domain = dips_agreement_eip712_domain(CHAIN_ID_ARBITRUM_ONE); let voucher = voucher.sign(&domain, payer)?; let abi_voucher = voucher.abi_encode(); @@ -491,7 +491,7 @@ mod test { metadata: metadata.abi_encode().into(), }; - let domain = dips_agreement_eip712_domain(); + let domain = dips_agreement_eip712_domain(CHAIN_ID_ARBITRUM_ONE); let signed = voucher.sign(&domain, payer).unwrap(); assert_eq!( signed @@ -545,7 +545,7 @@ mod test { deadline: 10000000, metadata: metadata.abi_encode().into(), }; - let domain = dips_agreement_eip712_domain(); + let domain = dips_agreement_eip712_domain(CHAIN_ID_ARBITRUM_ONE); let mut signed = voucher.sign(&domain, payer).unwrap(); signed.voucher.service = Address::repeat_byte(9); @@ -597,7 +597,7 @@ mod test { let voucher = CancellationRequest { agreement_id: Uuid::now_v7().as_bytes().into(), }; - let domain = dips_cancellation_eip712_domain(); + let domain = dips_cancellation_eip712_domain(CHAIN_ID_ARBITRUM_ONE); let signed = voucher.sign(&domain, signer).unwrap(); @@ -627,7 +627,7 @@ mod test { } } pub fn domain(&self) -> Eip712Domain { - dips_agreement_eip712_domain() + dips_agreement_eip712_domain(CHAIN_ID_ARBITRUM_ONE) } pub fn test_voucher_with_signer( @@ -637,7 +637,7 @@ mod test { ) -> SignedIndexingAgreementVoucher { let agreement_id = Uuid::now_v7(); - let domain = dips_agreement_eip712_domain(); + let domain = dips_agreement_eip712_domain(CHAIN_ID_ARBITRUM_ONE); let voucher = IndexingAgreementVoucher { agreement_id: agreement_id.as_bytes().into(), @@ -693,7 +693,7 @@ mod test { .await?; // Create and sign cancellation request - let cancel_domain = dips_cancellation_eip712_domain(); + let cancel_domain = dips_cancellation_eip712_domain(CHAIN_ID_ARBITRUM_ONE); let cancel_request = CancellationRequest { agreement_id: agreement_id.as_bytes().into(), }; diff --git a/crates/dips/src/server.rs b/crates/dips/src/server.rs index 4ded0d580..c613f9aaa 100644 --- a/crates/dips/src/server.rs +++ b/crates/dips/src/server.rs @@ -6,10 +6,11 @@ use std::sync::Arc; use async_trait::async_trait; #[cfg(test)] use indexer_monitor::EscrowAccounts; -use thegraph_core::alloy::{primitives::Address, sol_types::Eip712Domain}; +use thegraph_core::alloy::primitives::{Address, ChainId}; use tonic::{Request, Response, Status}; use crate::{ + dips_agreement_eip712_domain, dips_cancellation_eip712_domain, ipfs::IpfsFetcher, price::PriceCalculator, proto::indexer::graphprotocol::indexer::dips::{ @@ -63,7 +64,7 @@ pub struct DipsServer { pub ctx: Arc, pub expected_payee: Address, pub allowed_payers: Vec
, - pub domain: Eip712Domain, + pub chain_id: ChainId, } #[async_trait] @@ -88,7 +89,7 @@ impl IndexerDipsService for DipsServer { // - The subgraph deployment is available on IPFS validate_and_create_agreement( self.ctx.clone(), - &self.domain, + &dips_agreement_eip712_domain(self.chain_id), &self.expected_payee, &self.allowed_payers, signed_voucher, @@ -114,9 +115,13 @@ impl IndexerDipsService for DipsServer { return Err(Status::invalid_argument("invalid version")); } - validate_and_cancel_agreement(self.ctx.store.clone(), &self.domain, signed_cancellation) - .await - .map_err(Into::::into)?; + validate_and_cancel_agreement( + self.ctx.store.clone(), + &dips_cancellation_eip712_domain(self.chain_id), + signed_cancellation, + ) + .await + .map_err(Into::::into)?; Ok(tonic::Response::new(CancelAgreementResponse {})) } diff --git a/crates/service/src/service.rs b/crates/service/src/service.rs index 1754b410e..2af13ed57 100644 --- a/crates/service/src/service.rs +++ b/crates/service/src/service.rs @@ -98,6 +98,7 @@ pub async fn run() -> anyhow::Result<()> { config.blockchain.chain_id as u64, config.blockchain.receipts_verifier_address, ); + let chain_id = config.blockchain.chain_id as u64; let host_and_port = config.service.host_and_port; let indexer_address = config.indexer.indexer_address; @@ -159,7 +160,7 @@ pub async fn run() -> anyhow::Result<()> { ctx: Arc::new(ctx), expected_payee: indexer_address, allowed_payers: allowed_payers.clone(), - domain: domain_separator, + chain_id, }; info!("starting dips grpc server on {}", addr);