Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release_please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
# run only if release-please had released a new version
needs: release-please
container:
image: rust:1.86-bookworm
image: rust:1.87-bookworm
if: needs.release-please.outputs.releases_created == 'true' || github.event.inputs.force_publish == 'true'
steps:
- uses: actions/checkout@v3
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
name: cargo clippy
runs-on: ubuntu-latest
container:
image: rust:1.86-bookworm
image: rust:1.87-bookworm
steps:
- uses: actions/checkout@v3
- name: Install protobuf compiler
Expand All @@ -51,7 +51,7 @@ jobs:
pull-requests: write
actions: read
container:
image: rust:1.86-bookworm
image: rust:1.87-bookworm
steps:
- uses: actions/checkout@v3
- name: Install protobuf compiler
Expand All @@ -78,7 +78,7 @@ jobs:
name: cargo test docs
runs-on: ubuntu-latest
container:
image: rust:1.86-bookworm
image: rust:1.87-bookworm
steps:
- uses: actions/checkout@v3
- name: Install protobuf compiler
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ criterion = { version = "0.5.1", features = ["async_std"] }
futures-util = "0.3.31"
hyper = { version = "1.6.0", features = ["full"] }
insta = { version = "1.42.2", features = ["json"] }
jsonrpsee = { version = "0.25.1", features = ["macros", "server"] }
jsonrpsee = { version = "0.25.1", features = ["macros", "server", "client"] }
jsonrpsee-core = "0.25.1"
lazy_static = "1.5.0"
log = "0.4.27"
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.tap_aggregator
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rust:1.86-bookworm as build
FROM rust:1.87-bookworm as build

WORKDIR /root

Expand Down
33 changes: 14 additions & 19 deletions tap_aggregator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,19 @@ struct Args {
#[arg(long, default_value_t = 5000, env = "TAP_METRICS_PORT")]
metrics_port: u16,

/// Domain name to be used for the EIP-712 domain separator.
#[arg(long, env = "TAP_DOMAIN_NAME")]
domain_name: Option<String>,

/// Domain version to be used for the EIP-712 domain separator.
#[arg(long, env = "TAP_DOMAIN_VERSION")]
domain_version: Option<String>,

/// Domain chain ID to be used for the EIP-712 domain separator.
#[arg(long, env = "TAP_DOMAIN_CHAIN_ID")]
domain_chain_id: Option<String>,

/// Domain verifying contract to be used for the EIP-712 domain separator.
/// [TAP v1] Domain verifying contract to be used for the EIP-712 domain separator.
#[arg(long, env = "TAP_DOMAIN_VERIFYING_CONTRACT")]
domain_verifying_contract: Option<Address>,

/// Domain salt to be used for the EIP-712 domain separator.
/// [TAP v2] Domain verifying contract to be used for the EIP-712 domain separator.
#[arg(long, env = "TAP_DOMAIN_VERIFYING_CONTRACT_V2")]
domain_verifying_contract_v2: Option<Address>,

/// [Shared] Domain salt to be used for the EIP-712 domain separator.
#[arg(long, env = "TAP_DOMAIN_SALT")]
domain_salt: Option<String>,

Expand Down Expand Up @@ -100,7 +96,8 @@ async fn main() -> Result<()> {
info!("Wallet address: {:#40x}", wallet.address());

// Create the EIP-712 domain separator.
let domain_separator = create_eip712_domain(&args)?;
let domain_separator = create_eip712_domain(&args, TapVersion::V1)?;
let domain_separator_v2 = create_eip712_domain(&args, TapVersion::V2)?;

// Create HashSet of *all* allowed signers
let mut accepted_addresses: HashSet<Address> = std::collections::HashSet::new();
Expand All @@ -127,6 +124,7 @@ async fn main() -> Result<()> {
wallet,
accepted_addresses,
domain_separator,
domain_separator_v2,
args.max_request_body_size,
args.max_response_body_size,
args.max_connections,
Expand All @@ -142,9 +140,9 @@ async fn main() -> Result<()> {
Ok(())
}

fn create_eip712_domain(args: &Args) -> Result<Eip712Domain> {
/// Creates the TAP EIP-712 domain separator based on the provided arguments and TAP version
fn create_eip712_domain(args: &Args, version: TapVersion) -> Result<Eip712Domain> {
// Transform the args into the types expected by Eip712Domain::new().

// Transform optional strings into optional Cow<str>.
// Transform optional strings into optional U256.
if args.domain_chain_id.is_some() {
Expand All @@ -161,12 +159,9 @@ fn create_eip712_domain(args: &Args) -> Result<Eip712Domain> {
}

// Transform optional strings into optional Address.
let verifying_contract: Option<Address> = args.domain_verifying_contract;

// Determine TAP version from domain_version argument
let version = match args.domain_version.as_deref() {
Some("2") => TapVersion::V2,
_ => TapVersion::V1, // Default to V1
let verifying_contract: Option<Address> = match version {
TapVersion::V1 => args.domain_verifying_contract,
TapVersion::V2 => args.domain_verifying_contract_v2,
};

// Create the EIP-712 domain separator.
Expand Down
33 changes: 31 additions & 2 deletions tap_aggregator/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ pub trait Rpc {
#[method(name = "eip712domain_info")]
fn eip712_domain_info(&self) -> JsonRpcResult<Eip712Domain>;

/// Returns the v2 EIP-712 domain separator information used by this server.
/// The client is able to verify the signatures of the receipts and receipt aggregate vouchers.
#[cfg(feature = "v2")]
#[method(name = "eip712domain_info_v2")]
fn eip712_domain_info_v2(&self) -> JsonRpcResult<Eip712Domain>;

/// Aggregates the given receipts into a receipt aggregate voucher.
/// Returns an error if the user expected API version is not supported.
#[method(name = "aggregate_receipts")]
Expand Down Expand Up @@ -112,6 +118,8 @@ struct RpcImpl {
wallet: PrivateKeySigner,
accepted_addresses: HashSet<Address>,
domain_separator: Eip712Domain,
#[cfg(feature = "v2")]
domain_separator_v2: Eip712Domain,
kafka: Option<rdkafka::producer::ThreadedProducer<rdkafka::producer::DefaultProducerContext>>,
}

Expand Down Expand Up @@ -340,7 +348,7 @@ impl v2::tap_aggregator_server::TapAggregator for RpcImpl {
let receipts_count: u64 = receipts.len() as u64;

match aggregator::v2::check_and_aggregate_receipts(
&self.domain_separator,
&self.domain_separator_v2,
receipts.as_slice(),
previous_rav,
&self.wallet,
Expand Down Expand Up @@ -381,6 +389,11 @@ impl RpcServer for RpcImpl {
Ok(JsonRpcResponse::ok(self.domain_separator.clone()))
}

#[cfg(feature = "v2")]
fn eip712_domain_info_v2(&self) -> JsonRpcResult<Eip712Domain> {
Ok(JsonRpcResponse::ok(self.domain_separator_v2.clone()))
}

fn aggregate_receipts(
&self,
api_version: String,
Expand Down Expand Up @@ -435,7 +448,7 @@ impl RpcServer for RpcImpl {
api_version,
&self.wallet,
&self.accepted_addresses,
&self.domain_separator,
&self.domain_separator_v2,
receipts,
previous_rav,
) {
Expand Down Expand Up @@ -468,6 +481,7 @@ pub async fn run_server(
wallet: PrivateKeySigner,
accepted_addresses: HashSet<Address>,
domain_separator: Eip712Domain,
domain_separator_v2: Eip712Domain,
max_request_body_size: u32,
max_response_body_size: u32,
max_concurrent_connections: u32,
Expand All @@ -478,6 +492,7 @@ pub async fn run_server(
wallet,
accepted_addresses,
domain_separator,
domain_separator_v2,
kafka,
};
let (json_rpc_service, _) = create_json_rpc_service(
Expand Down Expand Up @@ -661,6 +676,10 @@ mod tests {
fn domain_separator() -> Eip712Domain {
tap_eip712_domain(1, Address::from([0x11u8; 20]), TapVersion::V1)
}
#[fixture]
fn domain_separator_v2() -> Eip712Domain {
tap_eip712_domain(1, Address::from([0x22u8; 20]), TapVersion::V2)
}

#[fixture]
fn http_request_size_limit() -> u32 {
Expand All @@ -681,6 +700,7 @@ mod tests {
#[tokio::test]
async fn protocol_version(
domain_separator: Eip712Domain,
domain_separator_v2: Eip712Domain,
http_request_size_limit: u32,
http_response_size_limit: u32,
http_max_concurrent_connections: u32,
Expand All @@ -694,6 +714,7 @@ mod tests {
keys_main.wallet,
HashSet::from([keys_main.address]),
domain_separator,
domain_separator_v2,
http_request_size_limit,
http_response_size_limit,
http_max_concurrent_connections,
Expand All @@ -720,6 +741,7 @@ mod tests {
#[tokio::test]
async fn signed_rav_is_valid_with_no_previous_rav(
domain_separator: Eip712Domain,
domain_separator_v2: Eip712Domain,
http_request_size_limit: u32,
http_response_size_limit: u32,
http_max_concurrent_connections: u32,
Expand All @@ -746,6 +768,7 @@ mod tests {
keys_main.wallet.clone(),
HashSet::from([keys_main.address, keys_0.address, keys_1.address]),
domain_separator.clone(),
domain_separator_v2.clone(),
http_request_size_limit,
http_response_size_limit,
http_max_concurrent_connections,
Expand Down Expand Up @@ -803,6 +826,7 @@ mod tests {
#[tokio::test]
async fn signed_rav_is_valid_with_previous_rav(
domain_separator: Eip712Domain,
domain_separator_v2: Eip712Domain,
http_request_size_limit: u32,
http_response_size_limit: u32,
http_max_concurrent_connections: u32,
Expand All @@ -829,6 +853,7 @@ mod tests {
keys_main.wallet.clone(),
HashSet::from([keys_main.address, keys_0.address, keys_1.address]),
domain_separator.clone(),
domain_separator_v2.clone(),
http_request_size_limit,
http_response_size_limit,
http_max_concurrent_connections,
Expand Down Expand Up @@ -893,6 +918,7 @@ mod tests {
#[tokio::test]
async fn invalid_api_version(
domain_separator: Eip712Domain,
domain_separator_v2: Eip712Domain,
http_request_size_limit: u32,
http_response_size_limit: u32,
http_max_concurrent_connections: u32,
Expand All @@ -907,6 +933,7 @@ mod tests {
keys_main.wallet.clone(),
HashSet::from([keys_main.address]),
domain_separator.clone(),
domain_separator_v2.clone(),
http_request_size_limit,
http_response_size_limit,
http_max_concurrent_connections,
Expand Down Expand Up @@ -976,6 +1003,7 @@ mod tests {
#[tokio::test]
async fn request_size_limit(
domain_separator: Eip712Domain,
domain_separator_v2: Eip712Domain,
http_response_size_limit: u32,
http_max_concurrent_connections: u32,
allocation_ids: Vec<Address>,
Expand All @@ -999,6 +1027,7 @@ mod tests {
keys_main.wallet.clone(),
HashSet::from([keys_main.address]),
domain_separator.clone(),
domain_separator_v2.clone(),
http_request_size_limit,
http_response_size_limit,
http_max_concurrent_connections,
Expand Down
2 changes: 2 additions & 0 deletions tap_aggregator/tests/aggregate_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use tonic::codec::CompressionEncoding;
#[tokio::test]
async fn aggregation_test() {
let domain_separator = tap_eip712_domain(1, Address::ZERO, TapVersion::V1);
let domain_separator_v2 = tap_eip712_domain(1, Address::ZERO, TapVersion::V2);

let wallet = PrivateKeySigner::random();

Expand All @@ -31,6 +32,7 @@ async fn aggregation_test() {
wallet.clone(),
accepted_addresses,
domain_separator.clone(),
domain_separator_v2.clone(),
max_request_body_size,
max_response_body_size,
max_concurrent_connections,
Expand Down
2 changes: 2 additions & 0 deletions tap_aggregator/tests/aggregate_v1_and_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use tonic::codec::CompressionEncoding;
#[tokio::test]
async fn aggregation_test() {
let domain_separator = tap_eip712_domain(1, Address::ZERO, TapVersion::V2);
let domain_separator_v2 = tap_eip712_domain(1, Address::ZERO, TapVersion::V2);

let wallet = PrivateKeySigner::random();

Expand All @@ -35,6 +36,7 @@ async fn aggregation_test() {
wallet.clone(),
accepted_addresses,
domain_separator.clone(),
domain_separator_v2.clone(),
max_request_body_size,
max_response_body_size,
max_concurrent_connections,
Expand Down
Loading