Skip to content

Commit 2f11aaf

Browse files
committed
chore: bump deps
1 parent d49c40d commit 2f11aaf

File tree

13 files changed

+1078
-745
lines changed

13 files changed

+1078
-745
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@ resolver = "2"
66
opt-level = 3
77

88
[workspace.dependencies]
9-
alloy = { version = "0.2.1", features = [
9+
alloy = { version = "0.4.2", features = [
1010
"kzg",
1111
"signer-mnemonic",
12+
"dyn-abi",
13+
"sol-types",
14+
"signer-local",
15+
"eip712",
16+
"rlp",
17+
"signers",
1218
], default-features = false }
1319
clap = "4.4.3"
1420
lazy_static = "1.4.0"
15-
axum = { version = "0.7.5", default-features = false }
16-
tokio = "1.39.2"
21+
axum = { version = "0.7.7", default-features = false }
22+
tokio = "1.40"
1723
prometheus = "0.13.3"
1824
anyhow = { version = "1.0.72" }
1925
thiserror = "1.0.49"
@@ -39,12 +45,12 @@ sqlx = { version = "0.8.2", features = [
3945
tracing = { version = "0.1.40", default-features = false }
4046
bigdecimal = "0.4.3"
4147
build-info = "0.0.38"
42-
tap_core = { git = "https://github.com/semiotic-ai/timeline-aggregation-protocol", rev = "ff856d9", default-features = false }
48+
tap_core = { git = "https://github.com/semiotic-ai/timeline-aggregation-protocol", rev = "c26e552", default-features = false }
4349
tracing-subscriber = { version = "0.3", features = [
4450
"json",
4551
"env-filter",
4652
], default-features = false }
47-
thegraph-core = { git = "https://github.com/edgeandnode/toolshed", rev = "85ee00b", features = [
53+
thegraph-core = { git = "https://github.com/edgeandnode/toolshed", tag = "thegraph-core-v0.7.0", features = [
4854
"subgraph-client",
4955
] }
5056
thegraph-graphql-http = "0.2.0"

common/src/indexer_service/http/config.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ pub struct IndexerServiceConfig {
4747

4848
#[derive(Debug, Deserialize, Serialize, Clone)]
4949
pub struct IndexerDipsConfig {
50-
pub expected_payee: String,
51-
pub allowed_payers: Vec<String>,
50+
pub allowed_payers: Vec<Address>,
5251
}
5352

5453
#[derive(Clone, Debug, Deserialize, Serialize)]

config/maximal-config-example.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,6 @@ max_receipts_per_request = 10000
145145
# Key-Value of all senders and their aggregator endpoints
146146
0xdeadbeefcafebabedeadbeefcafebabedeadbeef = "https://example.com/aggregate-receipts"
147147
0x0123456789abcdef0123456789abcdef01234567 = "https://other.example.com/aggregate-receipts"
148+
149+
[dips]
150+
expected_payers = ["0xdeadbeef"]

config/minimal-config-example.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,6 @@ receipts_verifier_address = "0x2222222222222222222222222222222222222222"
6363
# Key-Value of all senders and their aggregator endpoints
6464
0xdeadbeefcafebabedeadbeefcafebabedeadbeef = "https://example.com/aggregate-receipts"
6565
0x0123456789abcdef0123456789abcdef01234567 = "https://other.example.com/aggregate-receipts"
66+
67+
[dips]
68+
allowed_payers = ["0x3333333333333333333333333333333333333333"]

config/src/config.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,7 @@ pub struct TapConfig {
354354
#[derive(Debug, Deserialize)]
355355
#[cfg_attr(test, derive(PartialEq))]
356356
pub struct DipsConfig {
357-
pub expected_payee: String,
358-
pub allowed_payers: Vec<String>,
357+
pub allowed_payers: Vec<Address>,
359358
}
360359

361360
impl TapConfig {

dips/Cargo.toml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
alloy-core = "0.8.5"
8-
alloy-primitives = { version = "0.8.5", default-features = true, features = ["rlp"]}
9-
alloy-sol-types = "0.8.5"
10-
alloy-signer = "0.4.2"
11-
alloy-rlp = "0.3.8"
7+
alloy.workspace = true
8+
thiserror.workspace = true
9+
anyhow.workspace = true
10+
alloy-sol-types = "=0.8.7"
11+
# alloy-signer = { version = "0.4", features = ["eip712"] }
12+
alloy-rlp = "0.3.8"
13+
thegraph-core.workspace = true
1214

13-
[dev-dependencies]
14-
alloy-signer-local = "0.4.2"
15+
# alloy-signer = "0.4.2"
16+
# alloy-rlp = "0.3.8"
17+
18+
# [dev-dependencies]
19+
# alloy-signer-local = "=0.4.0"

dips/src/lib.rs

Lines changed: 67 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33

44
use std::str::FromStr;
55

6-
pub use alloy_core;
6+
pub use alloy;
77
pub use alloy_rlp;
8-
pub use alloy_signer;
9-
pub use alloy_sol_types;
108

11-
use alloy_core::primitives::Address;
12-
use alloy_rlp::{RlpDecodable, RlpEncodable};
13-
use alloy_signer::Signature;
14-
use alloy_sol_types::{sol, SolStruct};
9+
use alloy::core::primitives::Address;
10+
use alloy::rlp::{RlpDecodable, RlpEncodable};
11+
use alloy::signers::{Signature, SignerSync};
12+
use alloy_sol_types::{sol, Eip712Domain, SolStruct};
13+
use thiserror::Error;
1514

1615
sol! {
1716
// EIP712 encoded bytes, ABI - ethers
@@ -52,45 +51,72 @@ sol! {
5251
}
5352
}
5453

54+
#[derive(Error, Debug, PartialEq)]
55+
pub enum AgreementVoucherValidationError {
56+
#[error("signature is not valid, error: {0}")]
57+
InvalidSignature(String),
58+
#[error("payer {0} not authorised")]
59+
PayerNotAuthorised(Address),
60+
#[error("voucher payee {actual} does not match the expected address {expected}")]
61+
UnexpectedPayee { expected: Address, actual: Address },
62+
}
63+
64+
impl IndexingAgreementVoucher {
65+
pub fn sign<S: SignerSync>(
66+
&self,
67+
domain: &Eip712Domain,
68+
signer: S,
69+
) -> anyhow::Result<SignedIndexingAgreementVoucher> {
70+
let voucher = SignedIndexingAgreementVoucher {
71+
voucher: self.clone(),
72+
signature: signer.sign_typed_data_sync(self, domain)?.as_bytes().into(),
73+
};
74+
75+
Ok(voucher)
76+
}
77+
}
78+
5579
impl SignedIndexingAgreementVoucher {
56-
// TODO: Validate all values, maybe return a useful error on failure.
57-
pub fn is_valid(
80+
// TODO: Validate all values
81+
pub fn validate(
5882
&self,
83+
domain: &Eip712Domain,
5984
expected_payee: &Address,
6085
allowed_payers: impl AsRef<[Address]>,
61-
) -> bool {
62-
let sig = match Signature::from_str(&self.signature.to_string()) {
63-
Ok(s) => s,
64-
Err(_) => return false,
65-
};
86+
) -> Result<(), AgreementVoucherValidationError> {
87+
let sig = Signature::from_str(&self.signature.to_string())
88+
.map_err(|err| AgreementVoucherValidationError::InvalidSignature(err.to_string()))?;
6689

6790
let payer = sig
68-
.recover_address_from_msg(self.voucher.eip712_hash_struct())
69-
.unwrap();
91+
.recover_address_from_prehash(&self.voucher.eip712_signing_hash(domain))
92+
.map_err(|err| AgreementVoucherValidationError::InvalidSignature(err.to_string()))?;
7093

7194
if allowed_payers.as_ref().is_empty()
7295
|| !allowed_payers.as_ref().iter().any(|addr| addr.eq(&payer))
7396
{
74-
return false;
97+
return Err(AgreementVoucherValidationError::PayerNotAuthorised(payer));
7598
}
7699

77100
if !self.voucher.payee.eq(expected_payee) {
78-
return false;
101+
return Err(AgreementVoucherValidationError::UnexpectedPayee {
102+
expected: *expected_payee,
103+
actual: self.voucher.payee,
104+
});
79105
}
80106

81-
true
107+
Ok(())
82108
}
83109
}
84110

85111
#[cfg(test)]
86112
mod test {
87-
use alloy_core::primitives::{Address, FixedBytes, U256};
88-
use alloy_signer::SignerSync;
89-
use alloy_signer_local::PrivateKeySigner;
90-
use alloy_sol_types::SolStruct;
113+
use alloy::primitives::{Address, FixedBytes, U256};
114+
use alloy::signers::local::PrivateKeySigner;
115+
use alloy::sol_types::SolStruct;
116+
use thegraph_core::attestation::eip712_domain;
91117

92118
use crate::{
93-
IndexingAgreementVoucher, SignedIndexingAgreementVoucher, SubgraphIndexingVoucherMetadata,
119+
AgreementVoucherValidationError, IndexingAgreementVoucher, SubgraphIndexingVoucherMetadata,
94120
};
95121

96122
#[test]
@@ -119,17 +145,15 @@ mod test {
119145
metadata: metadata.eip712_hash_struct().to_owned().into(),
120146
};
121147

122-
let signed = SignedIndexingAgreementVoucher {
123-
voucher: voucher.clone(),
124-
signature: payer
125-
.sign_message_sync(voucher.eip712_hash_struct().as_slice())
126-
.unwrap()
127-
.as_bytes()
128-
.into(),
129-
};
130-
131-
assert!(signed.is_valid(&payee_addr, vec![]));
132-
assert!(signed.is_valid(&payee_addr, vec![payer_addr]));
148+
let domain = eip712_domain(0, Address::ZERO);
149+
let signed = voucher.sign(&domain, payer).unwrap();
150+
assert_eq!(
151+
signed.validate(&domain, &payee_addr, vec![]).unwrap_err(),
152+
AgreementVoucherValidationError::PayerNotAuthorised(voucher.payer)
153+
);
154+
assert!(signed
155+
.validate(&domain, &payee_addr, vec![payer_addr])
156+
.is_ok());
133157
}
134158

135159
#[test]
@@ -157,17 +181,16 @@ mod test {
157181
durationEpochs: 1000,
158182
metadata: metadata.eip712_hash_struct().to_owned().into(),
159183
};
184+
let domain = eip712_domain(0, Address::ZERO);
160185

161-
let mut signed = SignedIndexingAgreementVoucher {
162-
voucher: voucher.clone(),
163-
signature: payer
164-
.sign_message_sync(voucher.eip712_hash_struct().as_slice())
165-
.unwrap()
166-
.as_bytes()
167-
.into(),
168-
};
186+
let mut signed = voucher.sign(&domain, payer).unwrap();
169187
signed.voucher.service = Address::repeat_byte(9);
170188

171-
assert!(signed.is_valid(&payee_addr, vec![payer_addr]));
189+
assert!(matches!(
190+
signed
191+
.validate(&domain, &payee_addr, vec![payer_addr])
192+
.unwrap_err(),
193+
AgreementVoucherValidationError::PayerNotAuthorised(_)
194+
));
172195
}
173196
}

service/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ async-graphql = { version = "7.0.11", default-features = false }
3030
async-graphql-axum = "7.0.11"
3131
base64.workspace = true
3232
graphql = { git = "https://github.com/edgeandnode/toolshed", tag = "graphql-v0.3.0" }
33-
33+
3434
[dev-dependencies]
3535
hex-literal = "0.4.1"
36-
alloy-signer-local = "0.4.2"
36+
alloy.workspace = true
3737

3838
[build-dependencies]
3939
build-info-build = { version = "0.0.38", default-features = false }

service/src/config.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ impl From<MainConfig> for Config {
7878
receipt_max_value: value.service.tap.max_receipt_value_grt.get_value(),
7979
},
8080
dips: IndexerDipsConfig {
81-
expected_payee: value.dips.expected_payee,
8281
allowed_payers: value.dips.allowed_payers,
8382
},
8483
})

0 commit comments

Comments
 (0)