Skip to content

Commit 73bb550

Browse files
committed
feat: make domain version injectable
Signed-off-by: Joseph Livesey <[email protected]>
1 parent 4f913ea commit 73bb550

File tree

14 files changed

+55
-27
lines changed

14 files changed

+55
-27
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ thiserror = "2.0.12"
5555
tokio = { version = "1.44.2", features = ["macros", "signal"] }
5656
tonic = { version = "0.14.1", features = ["transport", "zstd"] }
5757
tonic-build = "0.14.1"
58+
tonic-prost = "0.14.1"
5859
tonic-prost-build = "0.14.1"
5960
tower = { version = "0.5.2", features = ["util", "steer"] }
6061
tracing-subscriber = "0.3.19"

tap_aggregator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ tap_graph.workspace = true
3636
thegraph-core = { workspace = true, features = ["alloy-eip712"] }
3737
tokio.workspace = true
3838
tonic.workspace = true
39-
tonic-prost = "0.14.1"
39+
tonic-prost.workspace = true
4040
tower = { workspace = true, features = ["util", "steer", "limit"] }
4141
tracing-subscriber.workspace = true
4242

tap_aggregator/src/aggregator/v1.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ mod tests {
133133
use std::str::FromStr;
134134

135135
use rstest::*;
136-
use tap_core::{signed_message::Eip712SignedMessage, tap_eip712_domain};
136+
use tap_core::{signed_message::Eip712SignedMessage, tap_eip712_domain, TapVersion};
137137
use tap_graph::{Receipt, ReceiptAggregateVoucher};
138138
use thegraph_core::alloy::{
139139
dyn_abi::Eip712Domain,
@@ -162,7 +162,7 @@ mod tests {
162162

163163
#[fixture]
164164
fn domain_separator() -> Eip712Domain {
165-
tap_eip712_domain(1, Address::from([0x11u8; 20]))
165+
tap_eip712_domain(1, Address::from([0x11u8; 20]), TapVersion::V1)
166166
}
167167

168168
#[rstest]

tap_aggregator/src/aggregator/v2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ fn check_receipt_timestamps(
188188
#[cfg(test)]
189189
mod tests {
190190
use rstest::*;
191-
use tap_core::{signed_message::Eip712SignedMessage, tap_eip712_domain};
191+
use tap_core::{signed_message::Eip712SignedMessage, tap_eip712_domain, TapVersion};
192192
use tap_graph::v2::{Receipt, ReceiptAggregateVoucher};
193193
use thegraph_core::alloy::{
194194
dyn_abi::Eip712Domain,
@@ -229,7 +229,7 @@ mod tests {
229229
}
230230
#[fixture]
231231
fn domain_separator() -> Eip712Domain {
232-
tap_eip712_domain(1, Address::from([0x11u8; 20]))
232+
tap_eip712_domain(1, Address::from([0x11u8; 20]), TapVersion::V2)
233233
}
234234

235235
#[rstest]

tap_aggregator/src/main.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use anyhow::Result;
99
use clap::Parser;
1010
use log::{debug, info};
1111
use tap_aggregator::{metrics, server};
12-
use tap_core::tap_eip712_domain;
12+
use tap_core::{tap_eip712_domain, TapVersion};
1313
use thegraph_core::alloy::{
1414
dyn_abi::Eip712Domain, primitives::Address, signers::local::PrivateKeySigner,
1515
};
@@ -163,9 +163,16 @@ fn create_eip712_domain(args: &Args) -> Result<Eip712Domain> {
163163
// Transform optional strings into optional Address.
164164
let verifying_contract: Option<Address> = args.domain_verifying_contract;
165165

166+
// Determine TAP version from domain_version argument
167+
let version = match args.domain_version.as_deref() {
168+
Some("2") => TapVersion::V2,
169+
_ => TapVersion::V1, // Default to V1
170+
};
171+
166172
// Create the EIP-712 domain separator.
167173
Ok(tap_eip712_domain(
168174
chain_id.unwrap_or(1),
169175
verifying_contract.unwrap_or_default(),
176+
version,
170177
))
171178
}

tap_aggregator/src/server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ mod tests {
627627

628628
use jsonrpsee::{core::client::ClientT, http_client::HttpClientBuilder, rpc_params};
629629
use rstest::*;
630-
use tap_core::{signed_message::Eip712SignedMessage, tap_eip712_domain};
630+
use tap_core::{signed_message::Eip712SignedMessage, tap_eip712_domain, TapVersion};
631631
use tap_graph::{Receipt, ReceiptAggregateVoucher};
632632
use thegraph_core::alloy::{
633633
dyn_abi::Eip712Domain, primitives::Address, signers::local::PrivateKeySigner,
@@ -659,7 +659,7 @@ mod tests {
659659

660660
#[fixture]
661661
fn domain_separator() -> Eip712Domain {
662-
tap_eip712_domain(1, Address::from([0x11u8; 20]))
662+
tap_eip712_domain(1, Address::from([0x11u8; 20]), TapVersion::V1)
663663
}
664664

665665
#[fixture]

tap_aggregator/tests/aggregate_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ use tap_aggregator::{
99
jsonrpsee_helpers::JsonRpcResponse,
1010
server,
1111
};
12-
use tap_core::{signed_message::Eip712SignedMessage, tap_eip712_domain};
12+
use tap_core::{signed_message::Eip712SignedMessage, tap_eip712_domain, TapVersion};
1313
use tap_graph::{Receipt, ReceiptAggregateVoucher};
1414
use thegraph_core::alloy::{primitives::Address, signers::local::PrivateKeySigner};
1515
use tonic::codec::CompressionEncoding;
1616

1717
#[tokio::test]
1818
async fn aggregation_test() {
19-
let domain_separator = tap_eip712_domain(1, Address::ZERO);
19+
let domain_separator = tap_eip712_domain(1, Address::ZERO, TapVersion::V1);
2020

2121
let wallet = PrivateKeySigner::random();
2222

tap_aggregator/tests/aggregate_v1_and_v2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use tap_aggregator::{
1010
},
1111
server,
1212
};
13-
use tap_core::{signed_message::Eip712SignedMessage, tap_eip712_domain};
13+
use tap_core::{signed_message::Eip712SignedMessage, tap_eip712_domain, TapVersion};
1414
use tap_graph::{v2::Receipt as ReceiptV2, Receipt as ReceiptV1};
1515
use thegraph_core::alloy::{
1616
primitives::{address, Address, FixedBytes},
@@ -20,7 +20,7 @@ use tonic::codec::CompressionEncoding;
2020

2121
#[tokio::test]
2222
async fn aggregation_test() {
23-
let domain_separator = tap_eip712_domain(1, Address::ZERO);
23+
let domain_separator = tap_eip712_domain(1, Address::ZERO, TapVersion::V2);
2424

2525
let wallet = PrivateKeySigner::random();
2626

tap_core/src/lib.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,35 @@ fn get_current_timestamp_u64_ns() -> Result<u64> {
3939
/// You can take a look on deployed [TAPVerfiers](https://github.com/semiotic-ai/timeline-aggregation-protocol-contracts/blob/4dc87fc616680c924b99dbaf285bdd449c777261/src/TAPVerifier.sol)
4040
/// contracts [here](https://github.com/semiotic-ai/timeline-aggregation-protocol-contracts/blob/4dc87fc616680c924b99dbaf285bdd449c777261/addresses.json)
4141
///
42+
/// TAP protocol version for EIP-712 domain separator
43+
#[derive(Debug, Clone, Copy)]
44+
pub enum TapVersion {
45+
V1,
46+
V2,
47+
}
48+
49+
impl TapVersion {
50+
pub fn as_str(&self) -> &'static str {
51+
match self {
52+
TapVersion::V1 => "1",
53+
TapVersion::V2 => "2",
54+
}
55+
}
56+
}
57+
4258
/// The domain separator is defined as:
4359
/// - `name`: "TAP"
44-
/// - `version`: "1"
60+
/// - `version`: "1" or "2" depending on protocol version
4561
/// - `chain_id`: The chain ID of the chain where the domain separator is deployed.
4662
/// - `verifying_contract`: The address of the contract that is verifying the signature.
47-
pub fn tap_eip712_domain(chain_id: u64, verifying_contract_address: Address) -> Eip712Domain {
63+
pub fn tap_eip712_domain(
64+
chain_id: u64,
65+
verifying_contract_address: Address,
66+
version: TapVersion,
67+
) -> Eip712Domain {
4868
eip712_domain! {
4969
name: "TAP",
50-
version: "1",
70+
version: version.as_str(),
5171
chain_id: chain_id,
5272
verifying_contract: verifying_contract_address,
5373
}
@@ -63,7 +83,7 @@ mod tap_tests {
6383
dyn_abi::Eip712Domain, primitives::Address, signers::local::PrivateKeySigner,
6484
};
6585

66-
use crate::{signed_message::Eip712SignedMessage, tap_eip712_domain};
86+
use crate::{signed_message::Eip712SignedMessage, tap_eip712_domain, TapVersion};
6787

6888
#[fixture]
6989
fn keys() -> (PrivateKeySigner, Address) {
@@ -85,7 +105,7 @@ mod tap_tests {
85105

86106
#[fixture]
87107
fn domain_separator() -> Eip712Domain {
88-
tap_eip712_domain(1, Address::from([0x11u8; 20]))
108+
tap_eip712_domain(1, Address::from([0x11u8; 20]), TapVersion::V1)
89109
}
90110

91111
#[rstest]

tap_core/tests/manager_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use tap_core::{
3131
Context, ReceiptWithState,
3232
},
3333
signed_message::Eip712SignedMessage,
34-
tap_eip712_domain,
34+
tap_eip712_domain, TapVersion,
3535
};
3636
use tap_graph::{Receipt, ReceiptAggregateVoucher, SignedReceipt};
3737

@@ -66,7 +66,7 @@ fn sender_ids(signer: PrivateKeySigner) -> (PrivateKeySigner, Vec<Address>) {
6666

6767
#[fixture]
6868
fn domain_separator() -> Eip712Domain {
69-
tap_eip712_domain(1, Address::from([0x11u8; 20]))
69+
tap_eip712_domain(1, Address::from([0x11u8; 20]), TapVersion::V1)
7070
}
7171

7272
struct ContextFixture {

0 commit comments

Comments
 (0)