Skip to content

Commit

Permalink
bump deps
Browse files Browse the repository at this point in the history
  • Loading branch information
mangas committed Oct 14, 2024
1 parent d49c40d commit bd31868
Show file tree
Hide file tree
Showing 13 changed files with 1,078 additions and 745 deletions.
1,615 changes: 961 additions & 654 deletions Cargo.lock

Large diffs are not rendered by default.

16 changes: 11 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@ resolver = "2"
opt-level = 3

[workspace.dependencies]
alloy = { version = "0.2.1", features = [
alloy = { version = "0.4.2", features = [
"kzg",
"signer-mnemonic",
"dyn-abi",
"sol-types",
"signer-local",
"eip712",
"rlp",
"signers",
], default-features = false }
clap = "4.4.3"
lazy_static = "1.4.0"
axum = { version = "0.7.5", default-features = false }
tokio = "1.39.2"
axum = { version = "0.7.7", default-features = false }
tokio = "1.40"
prometheus = "0.13.3"
anyhow = { version = "1.0.72" }
thiserror = "1.0.49"
Expand All @@ -39,12 +45,12 @@ sqlx = { version = "0.8.2", features = [
tracing = { version = "0.1.40", default-features = false }
bigdecimal = "0.4.3"
build-info = "0.0.38"
tap_core = { git = "https://github.com/semiotic-ai/timeline-aggregation-protocol", rev = "ff856d9", default-features = false }
tap_core = { git = "https://github.com/semiotic-ai/timeline-aggregation-protocol", rev = "c26e552", default-features = false }
tracing-subscriber = { version = "0.3", features = [
"json",
"env-filter",
], default-features = false }
thegraph-core = { git = "https://github.com/edgeandnode/toolshed", rev = "85ee00b", features = [
thegraph-core = { git = "https://github.com/edgeandnode/toolshed", tag = "thegraph-core-v0.7.0", features = [
"subgraph-client",
] }
thegraph-graphql-http = "0.2.0"
Expand Down
3 changes: 1 addition & 2 deletions common/src/indexer_service/http/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ pub struct IndexerServiceConfig {

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct IndexerDipsConfig {
pub expected_payee: String,
pub allowed_payers: Vec<String>,
pub allowed_payers: Vec<Address>,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
Expand Down
3 changes: 3 additions & 0 deletions config/maximal-config-example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,6 @@ max_receipts_per_request = 10000
# Key-Value of all senders and their aggregator endpoints
0xdeadbeefcafebabedeadbeefcafebabedeadbeef = "https://example.com/aggregate-receipts"
0x0123456789abcdef0123456789abcdef01234567 = "https://other.example.com/aggregate-receipts"

[dips]
expected_payers = ["0xdeadbeef"]
3 changes: 3 additions & 0 deletions config/minimal-config-example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,6 @@ receipts_verifier_address = "0x2222222222222222222222222222222222222222"
# Key-Value of all senders and their aggregator endpoints
0xdeadbeefcafebabedeadbeefcafebabedeadbeef = "https://example.com/aggregate-receipts"
0x0123456789abcdef0123456789abcdef01234567 = "https://other.example.com/aggregate-receipts"

[dips]
allowed_payers = ["0x3333333333333333333333333333333333333333"]
3 changes: 1 addition & 2 deletions config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,7 @@ pub struct TapConfig {
#[derive(Debug, Deserialize)]
#[cfg_attr(test, derive(PartialEq))]
pub struct DipsConfig {
pub expected_payee: String,
pub allowed_payers: Vec<String>,
pub allowed_payers: Vec<Address>,
}

impl TapConfig {
Expand Down
19 changes: 12 additions & 7 deletions dips/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ version = "0.1.0"
edition = "2021"

[dependencies]
alloy-core = "0.8.5"
alloy-primitives = { version = "0.8.5", default-features = true, features = ["rlp"]}
alloy-sol-types = "0.8.5"
alloy-signer = "0.4.2"
alloy-rlp = "0.3.8"
alloy.workspace = true
thiserror.workspace = true
anyhow.workspace = true
alloy-sol-types = "=0.8.7"
# alloy-signer = { version = "0.4", features = ["eip712"] }
alloy-rlp = "0.3.8"
thegraph-core.workspace = true

[dev-dependencies]
alloy-signer-local = "0.4.2"
# alloy-signer = "0.4.2"
# alloy-rlp = "0.3.8"

# [dev-dependencies]
# alloy-signer-local = "=0.4.0"
111 changes: 67 additions & 44 deletions dips/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@

use std::str::FromStr;

pub use alloy_core;
pub use alloy;
pub use alloy_rlp;
pub use alloy_signer;
pub use alloy_sol_types;

use alloy_core::primitives::Address;
use alloy_rlp::{RlpDecodable, RlpEncodable};
use alloy_signer::Signature;
use alloy_sol_types::{sol, SolStruct};
use alloy::core::primitives::Address;
use alloy::rlp::{RlpDecodable, RlpEncodable};
use alloy::signers::{Signature, SignerSync};
use alloy_sol_types::{sol, Eip712Domain, SolStruct};
use thiserror::Error;

sol! {
// EIP712 encoded bytes, ABI - ethers
Expand Down Expand Up @@ -52,45 +51,72 @@ sol! {
}
}

#[derive(Error, Debug, PartialEq)]
pub enum AgreementVoucherValidationError {
#[error("signature is not valid, error: {0}")]
InvalidSignature(String),
#[error("payer {0} not authorised")]
PayerNotAuthorised(Address),
#[error("voucher payee {actual} does not match the expected address {expected}")]
UnexpectedPayee { expected: Address, actual: Address },
}

impl IndexingAgreementVoucher {
pub fn sign<S: SignerSync>(
&self,
domain: &Eip712Domain,
signer: S,
) -> anyhow::Result<SignedIndexingAgreementVoucher> {
let voucher = SignedIndexingAgreementVoucher {
voucher: self.clone(),
signature: signer.sign_typed_data_sync(self, domain)?.as_bytes().into(),
};

Ok(voucher)
}
}

impl SignedIndexingAgreementVoucher {
// TODO: Validate all values, maybe return a useful error on failure.
pub fn is_valid(
// TODO: Validate all values
pub fn validate(
&self,
domain: &Eip712Domain,
expected_payee: &Address,
allowed_payers: impl AsRef<[Address]>,
) -> bool {
let sig = match Signature::from_str(&self.signature.to_string()) {
Ok(s) => s,
Err(_) => return false,
};
) -> Result<(), AgreementVoucherValidationError> {
let sig = Signature::from_str(&self.signature.to_string())
.map_err(|err| AgreementVoucherValidationError::InvalidSignature(err.to_string()))?;

let payer = sig
.recover_address_from_msg(self.voucher.eip712_hash_struct())
.unwrap();
.recover_address_from_prehash(&self.voucher.eip712_signing_hash(&domain))
.map_err(|err| AgreementVoucherValidationError::InvalidSignature(err.to_string()))?;

if allowed_payers.as_ref().is_empty()
|| !allowed_payers.as_ref().iter().any(|addr| addr.eq(&payer))
{
return false;
return Err(AgreementVoucherValidationError::PayerNotAuthorised(payer));
}

if !self.voucher.payee.eq(expected_payee) {
return false;
return Err(AgreementVoucherValidationError::UnexpectedPayee {
expected: *expected_payee,
actual: self.voucher.payee,
});
}

true
Ok(())
}
}

#[cfg(test)]
mod test {
use alloy_core::primitives::{Address, FixedBytes, U256};
use alloy_signer::SignerSync;
use alloy_signer_local::PrivateKeySigner;
use alloy_sol_types::SolStruct;
use alloy::primitives::{Address, FixedBytes, U256};
use alloy::signers::local::PrivateKeySigner;
use alloy::sol_types::SolStruct;
use thegraph_core::attestation::eip712_domain;

use crate::{
IndexingAgreementVoucher, SignedIndexingAgreementVoucher, SubgraphIndexingVoucherMetadata,
AgreementVoucherValidationError, IndexingAgreementVoucher, SubgraphIndexingVoucherMetadata,
};

#[test]
Expand Down Expand Up @@ -119,17 +145,15 @@ mod test {
metadata: metadata.eip712_hash_struct().to_owned().into(),
};

let signed = SignedIndexingAgreementVoucher {
voucher: voucher.clone(),
signature: payer
.sign_message_sync(voucher.eip712_hash_struct().as_slice())
.unwrap()
.as_bytes()
.into(),
};

assert!(signed.is_valid(&payee_addr, vec![]));
assert!(signed.is_valid(&payee_addr, vec![payer_addr]));
let domain = eip712_domain(0, Address::ZERO);
let signed = voucher.sign(&domain, payer).unwrap();
assert_eq!(
signed.validate(&domain, &payee_addr, vec![]).unwrap_err(),
AgreementVoucherValidationError::PayerNotAuthorised(voucher.payer)
);
assert!(signed
.validate(&domain, &payee_addr, vec![payer_addr])
.is_ok());
}

#[test]
Expand Down Expand Up @@ -157,17 +181,16 @@ mod test {
durationEpochs: 1000,
metadata: metadata.eip712_hash_struct().to_owned().into(),
};
let domain = eip712_domain(0, Address::ZERO);

let mut signed = SignedIndexingAgreementVoucher {
voucher: voucher.clone(),
signature: payer
.sign_message_sync(voucher.eip712_hash_struct().as_slice())
.unwrap()
.as_bytes()
.into(),
};
let mut signed = voucher.sign(&domain, payer).unwrap();
signed.voucher.service = Address::repeat_byte(9);

assert!(signed.is_valid(&payee_addr, vec![payer_addr]));
assert!(matches!(
signed
.validate(&domain, &payee_addr, vec![payer_addr])
.unwrap_err(),
AgreementVoucherValidationError::PayerNotAuthorised(_)
));
}
}
4 changes: 2 additions & 2 deletions service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ async-graphql = { version = "7.0.11", default-features = false }
async-graphql-axum = "7.0.11"
base64.workspace = true
graphql = { git = "https://github.com/edgeandnode/toolshed", tag = "graphql-v0.3.0" }

[dev-dependencies]
hex-literal = "0.4.1"
alloy-signer-local = "0.4.2"
alloy.workspace = true

[build-dependencies]
build-info-build = { version = "0.0.38", default-features = false }
1 change: 0 additions & 1 deletion service/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ impl From<MainConfig> for Config {
receipt_max_value: value.service.tap.max_receipt_value_grt.get_value(),
},
dips: IndexerDipsConfig {
expected_payee: value.dips.expected_payee,
allowed_payers: value.dips.allowed_payers,
},
})
Expand Down
31 changes: 14 additions & 17 deletions service/src/routes/dips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ use anyhow::bail;
use async_graphql::{Context, FieldResult, Object, SimpleObject};
use base64::{engine::general_purpose::STANDARD, Engine};
use indexer_dips::{
alloy_core::primitives::Address, alloy_rlp::Decodable, SignedIndexingAgreementVoucher,
alloy::core::primitives::Address, alloy_rlp::Decodable, SignedIndexingAgreementVoucher,
SubgraphIndexingVoucherMetadata,
};
use thegraph_core::attestation::eip712_domain;

const CHAIN_ID: u64 = 0;
const DISPUTE_MANAGER: Address = Address::ZERO;

use crate::database::dips::AgreementStore;

Expand Down Expand Up @@ -145,9 +149,9 @@ async fn validate_and_create_agreement(
let voucher = SignedIndexingAgreementVoucher::decode(&mut rlp_bs.as_ref())?;
let metadata = SubgraphIndexingVoucherMetadata::decode(&mut voucher.voucher.metadata.as_ref())?;

if !voucher.is_valid(expected_payee, allowed_payers) {
bail!("voucher is not valid")
}
let domain = eip712_domain(CHAIN_ID, DISPUTE_MANAGER);

voucher.validate(&domain, expected_payee, allowed_payers)?;

let agreement = Agreement {
signature: voucher.signature.to_string(),
Expand All @@ -164,15 +168,14 @@ async fn validate_and_create_agreement(
mod test {
use std::sync::Arc;

use alloy_signer_local::PrivateKeySigner;
use alloy::signers::local::PrivateKeySigner;
use base64::{engine::general_purpose::STANDARD, Engine};
use indexer_dips::{
alloy_core::primitives::{Address, FixedBytes, U256},
alloy::core::primitives::{Address, FixedBytes, U256},
alloy_rlp::{self},
alloy_signer::SignerSync,
alloy_sol_types::SolStruct,
IndexingAgreementVoucher, SignedIndexingAgreementVoucher, SubgraphIndexingVoucherMetadata,
IndexingAgreementVoucher, SubgraphIndexingVoucherMetadata,
};
use thegraph_core::attestation::eip712_domain;

use crate::database::dips::InMemoryAgreementStore;

Expand Down Expand Up @@ -201,15 +204,9 @@ mod test {
durationEpochs: 1000,
metadata: alloy_rlp::encode(metadata).into(),
};
let domain = eip712_domain(0, Address::ZERO);

let voucher = SignedIndexingAgreementVoucher {
voucher: voucher.clone(),
signature: payer
.sign_message_sync(voucher.eip712_hash_struct().as_slice())
.unwrap()
.as_bytes()
.into(),
};
let voucher = voucher.sign(&domain, payer)?;
let rlp_voucher = alloy_rlp::encode(voucher.clone());
let b64 = STANDARD.encode(rlp_voucher);

Expand Down
12 changes: 2 additions & 10 deletions service/src/service.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs.
// SPDX-License-Identifier: Apache-2.0

use std::str::FromStr;
use std::time::Duration;
use std::{collections::HashMap, sync::Arc};

Expand All @@ -18,7 +17,6 @@ use indexer_common::indexer_service::http::{
AttestationOutput, IndexerServiceImpl, IndexerServiceResponse,
};
use indexer_config::Config as MainConfig;
use indexer_dips::alloy_core::primitives::Address;
use reqwest::Url;
use serde_json::{json, Value};
use sqlx::PgPool;
Expand Down Expand Up @@ -198,14 +196,8 @@ pub async fn run() -> anyhow::Result<()> {
let schema = Schema::build(
routes::dips::AgreementQuery {},
routes::dips::AgreementMutation {
expected_payee: Address::from_str(&config.0.dips.expected_payee).unwrap(),
allowed_payers: config
.0
.dips
.allowed_payers
.iter()
.map(|a| Address::from_str(a).unwrap())
.collect(),
expected_payee: config.0.indexer.indexer_address,
allowed_payers: config.0.dips.allowed_payers.clone(),
},
EmptySubscription,
)
Expand Down
2 changes: 1 addition & 1 deletion tap-agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ ruint = { version = "1.12.3", features = [
], default-features = false }
futures-util = { version = "0.3.28", default-features = false }
jsonrpsee = { version = "0.24.0", features = ["http-client", "tracing"] }
tap_aggregator = { git = "https://github.com/semiotic-ai/timeline-aggregation-protocol", rev = "eb8447e" }
tap_aggregator = { git = "https://github.com/semiotic-ai/timeline-aggregation-protocol", rev = "c26e552" }
ractor = { version = "0.9", features = [
"async-trait",
], default-features = false }
Expand Down

0 comments on commit bd31868

Please sign in to comment.