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
48 changes: 24 additions & 24 deletions tap_aggregator/src/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ use alloy::{
};
use anyhow::{bail, Ok, Result};
use rayon::prelude::*;
use tap_core::signed_message::{EIP712SignedMessage, SignatureBytes, SignatureBytesExt};
use tap_core::signed_message::{Eip712SignedMessage, SignatureBytes, SignatureBytesExt};
use tap_graph::{Receipt, ReceiptAggregateVoucher};

pub fn check_and_aggregate_receipts(
domain_separator: &Eip712Domain,
receipts: &[EIP712SignedMessage<Receipt>],
previous_rav: Option<EIP712SignedMessage<ReceiptAggregateVoucher>>,
receipts: &[Eip712SignedMessage<Receipt>],
previous_rav: Option<Eip712SignedMessage<ReceiptAggregateVoucher>>,
wallet: &PrivateKeySigner,
accepted_addresses: &HashSet<Address>,
) -> Result<EIP712SignedMessage<ReceiptAggregateVoucher>> {
) -> Result<Eip712SignedMessage<ReceiptAggregateVoucher>> {
check_signatures_unique(receipts)?;

// Check that the receipts are signed by an accepted signer address
Expand Down Expand Up @@ -63,11 +63,11 @@ pub fn check_and_aggregate_receipts(
let rav = ReceiptAggregateVoucher::aggregate_receipts(allocation_id, receipts, previous_rav)?;

// Sign the rav and return
Ok(EIP712SignedMessage::new(domain_separator, rav, wallet)?)
Ok(Eip712SignedMessage::new(domain_separator, rav, wallet)?)
}

fn check_signature_is_from_one_of_addresses<M: SolStruct>(
message: &EIP712SignedMessage<M>,
message: &Eip712SignedMessage<M>,
domain_separator: &Eip712Domain,
accepted_addresses: &HashSet<Address>,
) -> Result<()> {
Expand All @@ -81,7 +81,7 @@ fn check_signature_is_from_one_of_addresses<M: SolStruct>(
}

fn check_allocation_id(
receipts: &[EIP712SignedMessage<Receipt>],
receipts: &[Eip712SignedMessage<Receipt>],
allocation_id: Address,
) -> Result<()> {
for receipt in receipts.iter() {
Expand All @@ -93,7 +93,7 @@ fn check_allocation_id(
Ok(())
}

fn check_signatures_unique(receipts: &[EIP712SignedMessage<Receipt>]) -> Result<()> {
fn check_signatures_unique(receipts: &[Eip712SignedMessage<Receipt>]) -> Result<()> {
let mut receipt_signatures: hash_set::HashSet<SignatureBytes> = hash_set::HashSet::new();
for receipt in receipts.iter() {
let signature = receipt.signature.get_signature_bytes();
Expand All @@ -109,8 +109,8 @@ fn check_signatures_unique(receipts: &[EIP712SignedMessage<Receipt>]) -> Result<
}

fn check_receipt_timestamps(
receipts: &[EIP712SignedMessage<Receipt>],
previous_rav: Option<&EIP712SignedMessage<ReceiptAggregateVoucher>>,
receipts: &[Eip712SignedMessage<Receipt>],
previous_rav: Option<&Eip712SignedMessage<ReceiptAggregateVoucher>>,
) -> Result<()> {
if let Some(previous_rav) = &previous_rav {
for receipt in receipts.iter() {
Expand All @@ -134,7 +134,7 @@ mod tests {

use alloy::{dyn_abi::Eip712Domain, primitives::Address, signers::local::PrivateKeySigner};
use rstest::*;
use tap_core::{signed_message::EIP712SignedMessage, tap_eip712_domain};
use tap_core::{signed_message::Eip712SignedMessage, tap_eip712_domain};
use tap_graph::{Receipt, ReceiptAggregateVoucher};

use crate::aggregator;
Expand Down Expand Up @@ -170,7 +170,7 @@ mod tests {
) {
// Create the same receipt twice (replay attack)
let mut receipts = Vec::new();
let receipt = EIP712SignedMessage::new(
let receipt = Eip712SignedMessage::new(
&domain_separator,
Receipt::new(allocation_ids[0], 42).unwrap(),
&keys.0,
Expand All @@ -192,13 +192,13 @@ mod tests {
) {
// Create 2 different receipts
let receipts = vec![
EIP712SignedMessage::new(
Eip712SignedMessage::new(
&domain_separator,
Receipt::new(allocation_ids[0], 42).unwrap(),
&keys.0,
)
.unwrap(),
EIP712SignedMessage::new(
Eip712SignedMessage::new(
&domain_separator,
Receipt::new(allocation_ids[0], 43).unwrap(),
&keys.0,
Expand All @@ -223,7 +223,7 @@ mod tests {
let mut receipts = Vec::new();
for i in receipt_timestamp_range.clone() {
receipts.push(
EIP712SignedMessage::new(
Eip712SignedMessage::new(
&domain_separator,
Receipt {
allocation_id: allocation_ids[0],
Expand All @@ -238,7 +238,7 @@ mod tests {
}

// Create rav with max_timestamp below the receipts timestamps
let rav = EIP712SignedMessage::new(
let rav = Eip712SignedMessage::new(
&domain_separator,
ReceiptAggregateVoucher {
allocationId: allocation_ids[0],
Expand All @@ -252,7 +252,7 @@ mod tests {

// Create rav with max_timestamp equal to the lowest receipt timestamp
// Aggregation should fail
let rav = EIP712SignedMessage::new(
let rav = Eip712SignedMessage::new(
&domain_separator,
ReceiptAggregateVoucher {
allocationId: allocation_ids[0],
Expand All @@ -266,7 +266,7 @@ mod tests {

// Create rav with max_timestamp above highest receipt timestamp
// Aggregation should fail
let rav = EIP712SignedMessage::new(
let rav = Eip712SignedMessage::new(
&domain_separator,
ReceiptAggregateVoucher {
allocationId: allocation_ids[0],
Expand All @@ -289,19 +289,19 @@ mod tests {
domain_separator: Eip712Domain,
) {
let receipts = vec![
EIP712SignedMessage::new(
Eip712SignedMessage::new(
&domain_separator,
Receipt::new(allocation_ids[0], 42).unwrap(),
&keys.0,
)
.unwrap(),
EIP712SignedMessage::new(
Eip712SignedMessage::new(
&domain_separator,
Receipt::new(allocation_ids[0], 43).unwrap(),
&keys.0,
)
.unwrap(),
EIP712SignedMessage::new(
Eip712SignedMessage::new(
&domain_separator,
Receipt::new(allocation_ids[1], 44).unwrap(),
&keys.0,
Expand All @@ -323,19 +323,19 @@ mod tests {
domain_separator: Eip712Domain,
) {
let receipts = vec![
EIP712SignedMessage::new(
Eip712SignedMessage::new(
&domain_separator,
Receipt::new(allocation_ids[0], 42).unwrap(),
&keys.0,
)
.unwrap(),
EIP712SignedMessage::new(
Eip712SignedMessage::new(
&domain_separator,
Receipt::new(allocation_ids[0], 43).unwrap(),
&keys.0,
)
.unwrap(),
EIP712SignedMessage::new(
Eip712SignedMessage::new(
&domain_separator,
Receipt::new(allocation_ids[0], 44).unwrap(),
&keys.0,
Expand Down
8 changes: 4 additions & 4 deletions tap_aggregator/src/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

use anyhow::anyhow;
use tap_core::signed_message::EIP712SignedMessage;
use tap_core::signed_message::Eip712SignedMessage;

tonic::include_proto!("tap_aggregator.v1");

Expand Down Expand Up @@ -51,7 +51,7 @@ impl From<tap_graph::SignedReceipt> for SignedReceipt {
}
}

impl TryFrom<SignedRav> for EIP712SignedMessage<tap_graph::ReceiptAggregateVoucher> {
impl TryFrom<SignedRav> for Eip712SignedMessage<tap_graph::ReceiptAggregateVoucher> {
type Error = anyhow::Error;
fn try_from(voucher: SignedRav) -> Result<Self, Self::Error> {
Ok(Self {
Expand All @@ -64,8 +64,8 @@ impl TryFrom<SignedRav> for EIP712SignedMessage<tap_graph::ReceiptAggregateVouch
}
}

impl From<EIP712SignedMessage<tap_graph::ReceiptAggregateVoucher>> for SignedRav {
fn from(voucher: EIP712SignedMessage<tap_graph::ReceiptAggregateVoucher>) -> Self {
impl From<Eip712SignedMessage<tap_graph::ReceiptAggregateVoucher>> for SignedRav {
fn from(voucher: Eip712SignedMessage<tap_graph::ReceiptAggregateVoucher>) -> Self {
Self {
signature: voucher.signature.as_bytes().to_vec(),
message: Some(voucher.message.into()),
Expand Down
42 changes: 21 additions & 21 deletions tap_aggregator/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use jsonrpsee::{
use lazy_static::lazy_static;
use log::info;
use prometheus::{register_counter, register_int_counter, Counter, IntCounter};
use tap_core::signed_message::EIP712SignedMessage;
use tap_core::signed_message::Eip712SignedMessage;
use tap_graph::{Receipt, ReceiptAggregateVoucher, SignedReceipt};
use tokio::{net::TcpListener, signal, task::JoinHandle};
use tonic::{codec::CompressionEncoding, service::Routes, Request, Response, Status};
Expand Down Expand Up @@ -87,9 +87,9 @@ pub trait Rpc {
fn aggregate_receipts(
&self,
api_version: String,
receipts: Vec<EIP712SignedMessage<Receipt>>,
previous_rav: Option<EIP712SignedMessage<ReceiptAggregateVoucher>>,
) -> JsonRpcResult<EIP712SignedMessage<ReceiptAggregateVoucher>>;
receipts: Vec<Eip712SignedMessage<Receipt>>,
previous_rav: Option<Eip712SignedMessage<ReceiptAggregateVoucher>>,
) -> JsonRpcResult<Eip712SignedMessage<ReceiptAggregateVoucher>>;
}

#[derive(Clone)]
Expand Down Expand Up @@ -134,9 +134,9 @@ fn aggregate_receipts_(
wallet: &PrivateKeySigner,
accepted_addresses: &HashSet<Address>,
domain_separator: &Eip712Domain,
receipts: Vec<EIP712SignedMessage<Receipt>>,
previous_rav: Option<EIP712SignedMessage<ReceiptAggregateVoucher>>,
) -> JsonRpcResult<EIP712SignedMessage<ReceiptAggregateVoucher>> {
receipts: Vec<Eip712SignedMessage<Receipt>>,
previous_rav: Option<Eip712SignedMessage<ReceiptAggregateVoucher>>,
) -> JsonRpcResult<Eip712SignedMessage<ReceiptAggregateVoucher>> {
// Return an error if the API version is not supported.
let api_version = match parse_api_version(api_version.as_str()) {
Ok(v) => v,
Expand Down Expand Up @@ -230,9 +230,9 @@ impl RpcServer for RpcImpl {
fn aggregate_receipts(
&self,
api_version: String,
receipts: Vec<EIP712SignedMessage<Receipt>>,
previous_rav: Option<EIP712SignedMessage<ReceiptAggregateVoucher>>,
) -> JsonRpcResult<EIP712SignedMessage<ReceiptAggregateVoucher>> {
receipts: Vec<Eip712SignedMessage<Receipt>>,
previous_rav: Option<Eip712SignedMessage<ReceiptAggregateVoucher>>,
) -> JsonRpcResult<Eip712SignedMessage<ReceiptAggregateVoucher>> {
// Values for Prometheus metrics
let receipts_grt: u128 = receipts.iter().map(|r| r.message.value).sum();
let receipts_count: u64 = receipts.len() as u64;
Expand Down Expand Up @@ -391,7 +391,7 @@ mod tests {
use jsonrpsee::{core::client::ClientT, http_client::HttpClientBuilder, rpc_params};
use rand::{prelude::*, seq::SliceRandom};
use rstest::*;
use tap_core::{signed_message::EIP712SignedMessage, tap_eip712_domain};
use tap_core::{signed_message::Eip712SignedMessage, tap_eip712_domain};
use tap_graph::{Receipt, ReceiptAggregateVoucher};

use crate::server;
Expand Down Expand Up @@ -520,7 +520,7 @@ mod tests {
let mut receipts = Vec::new();
for value in values {
receipts.push(
EIP712SignedMessage::new(
Eip712SignedMessage::new(
&domain_separator,
Receipt::new(allocation_ids[0], value).unwrap(),
&all_wallets.choose(&mut rng).unwrap().wallet,
Expand All @@ -531,7 +531,7 @@ mod tests {

// Skipping receipts validation in this test, aggregate_receipts assumes receipts are valid.
// Create RAV through the JSON-RPC server.
let res: server::JsonRpcResponse<EIP712SignedMessage<ReceiptAggregateVoucher>> = client
let res: server::JsonRpcResponse<Eip712SignedMessage<ReceiptAggregateVoucher>> = client
.request(
"aggregate_receipts",
rpc_params!(api_version, &receipts, None::<()>),
Expand Down Expand Up @@ -600,7 +600,7 @@ mod tests {
let mut receipts = Vec::new();
for value in values {
receipts.push(
EIP712SignedMessage::new(
Eip712SignedMessage::new(
&domain_separator,
Receipt::new(allocation_ids[0], value).unwrap(),
&all_wallets.choose(&mut rng).unwrap().wallet,
Expand All @@ -616,15 +616,15 @@ mod tests {
None,
)
.unwrap();
let signed_prev_rav = EIP712SignedMessage::new(
let signed_prev_rav = Eip712SignedMessage::new(
&domain_separator,
prev_rav,
&all_wallets.choose(&mut rng).unwrap().wallet,
)
.unwrap();

// Create new RAV from last half of receipts and prev_rav through the JSON-RPC server
let res: server::JsonRpcResponse<EIP712SignedMessage<ReceiptAggregateVoucher>> = client
let res: server::JsonRpcResponse<Eip712SignedMessage<ReceiptAggregateVoucher>> = client
.request(
"aggregate_receipts",
rpc_params!(
Expand Down Expand Up @@ -674,7 +674,7 @@ mod tests {
.unwrap();

// Create receipts
let receipts = vec![EIP712SignedMessage::new(
let receipts = vec![Eip712SignedMessage::new(
&domain_separator,
Receipt::new(allocation_ids[0], 42).unwrap(),
&keys_main.wallet,
Expand All @@ -684,7 +684,7 @@ mod tests {
// Skipping receipts validation in this test, aggregate_receipts assumes receipts are valid.
// Create RAV through the JSON-RPC server.
let res: Result<
server::JsonRpcResponse<EIP712SignedMessage<ReceiptAggregateVoucher>>,
server::JsonRpcResponse<Eip712SignedMessage<ReceiptAggregateVoucher>>,
jsonrpsee::core::ClientError,
> = client
.request(
Expand Down Expand Up @@ -768,7 +768,7 @@ mod tests {
let mut receipts = Vec::new();
for _ in 1..number_of_receipts_to_exceed_limit {
receipts.push(
EIP712SignedMessage::new(
Eip712SignedMessage::new(
&domain_separator,
Receipt::new(allocation_ids[0], u128::MAX / 1000).unwrap(),
&keys_main.wallet,
Expand All @@ -781,7 +781,7 @@ mod tests {
// Create RAV through the JSON-RPC server.
// Test with a number of receipts that stays within request size limit
let res: Result<
server::JsonRpcResponse<EIP712SignedMessage<ReceiptAggregateVoucher>>,
server::JsonRpcResponse<Eip712SignedMessage<ReceiptAggregateVoucher>>,
jsonrpsee::core::ClientError,
> = client
.request(
Expand All @@ -798,7 +798,7 @@ mod tests {
// Create RAV through the JSON-RPC server.
// Test with all receipts to exceed request size limit
let res: Result<
server::JsonRpcResponse<EIP712SignedMessage<ReceiptAggregateVoucher>>,
server::JsonRpcResponse<Eip712SignedMessage<ReceiptAggregateVoucher>>,
jsonrpsee::core::ClientError,
> = client
.request(
Expand Down
6 changes: 3 additions & 3 deletions tap_aggregator/tests/aggregate_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use tap_aggregator::{
jsonrpsee_helpers::JsonRpcResponse,
server,
};
use tap_core::{signed_message::EIP712SignedMessage, tap_eip712_domain};
use tap_core::{signed_message::Eip712SignedMessage, tap_eip712_domain};
use tap_graph::{Receipt, ReceiptAggregateVoucher};
use tonic::codec::CompressionEncoding;

Expand Down Expand Up @@ -51,7 +51,7 @@ async fn aggregation_test() {
let mut receipts = Vec::new();
for value in 50..60 {
receipts.push(
EIP712SignedMessage::new(
Eip712SignedMessage::new(
&domain_separator,
Receipt::new(allocation_id, value).unwrap(),
&wallet,
Expand All @@ -68,7 +68,7 @@ async fn aggregation_test() {

let previous_rav: Option<tap_graph::SignedRav> = None;

let response: JsonRpcResponse<EIP712SignedMessage<ReceiptAggregateVoucher>> = sender_aggregator
let response: JsonRpcResponse<Eip712SignedMessage<ReceiptAggregateVoucher>> = sender_aggregator
.request(
"aggregate_receipts",
rpc_params!(
Expand Down
Loading