From b5f85fcdb0e3c292b654e0d7c2192fb4d709e1a7 Mon Sep 17 00:00:00 2001 From: Alexis Asseman Date: Fri, 2 Feb 2024 14:13:39 -0800 Subject: [PATCH] feat(core): Supply EIP712 domain sep with prefilled version and name Signed-off-by: Alexis Asseman --- tap_aggregator/src/aggregator.rs | 13 ++++------ tap_aggregator/src/server.rs | 12 +++------ .../timeline_aggretion_protocol_benchmark.rs | 10 +++----- .../adapters/test/rav_storage_adapter_test.rs | 10 +++----- .../test/receipt_checks_adapter_test.rs | 10 +++----- .../test/receipt_storage_adapter_test.rs | 10 +++----- tap_core/src/lib.rs | 25 +++++++++++++------ tap_core/src/tap_manager/test/manager_test.rs | 11 +++----- .../tests/received_receipt_tests.rs | 11 +++----- tap_integration_tests/tests/showcase.rs | 10 +++----- 10 files changed, 47 insertions(+), 75 deletions(-) diff --git a/tap_aggregator/src/aggregator.rs b/tap_aggregator/src/aggregator.rs index 4f855c80..efd07684 100644 --- a/tap_aggregator/src/aggregator.rs +++ b/tap_aggregator/src/aggregator.rs @@ -117,12 +117,14 @@ mod tests { use std::str::FromStr; use alloy_primitives::Address; - use alloy_sol_types::{eip712_domain, Eip712Domain}; + use alloy_sol_types::Eip712Domain; use ethers_signers::{LocalWallet, Signer}; use rstest::*; use crate::aggregator; - use tap_core::{eip_712_signed_message::EIP712SignedMessage, tap_receipt::Receipt}; + use tap_core::{ + eip_712_signed_message::EIP712SignedMessage, tap_eip712_domain, tap_receipt::Receipt, + }; #[fixture] fn keys() -> (LocalWallet, Address) { @@ -146,12 +148,7 @@ mod tests { #[fixture] fn domain_separator() -> Eip712Domain { - eip712_domain! { - name: "TAP", - version: "1", - chain_id: 1, - verifying_contract: Address::from([0x11u8; 20]), - } + tap_eip712_domain(1, Address::from([0x11u8; 20])) } #[rstest] diff --git a/tap_aggregator/src/server.rs b/tap_aggregator/src/server.rs index e2ed6ac6..762aef8e 100644 --- a/tap_aggregator/src/server.rs +++ b/tap_aggregator/src/server.rs @@ -241,7 +241,7 @@ mod tests { use std::str::FromStr; use alloy_primitives::Address; - use alloy_sol_types::{eip712_domain, Eip712Domain}; + use alloy_sol_types::Eip712Domain; use ethers_signers::{coins_bip39::English, LocalWallet, MnemonicBuilder, Signer}; use jsonrpsee::{core::client::ClientT, http_client::HttpClientBuilder, rpc_params}; use rstest::*; @@ -249,7 +249,8 @@ mod tests { use crate::server; use tap_core::{ eip_712_signed_message::EIP712SignedMessage, - receipt_aggregate_voucher::ReceiptAggregateVoucher, tap_receipt::Receipt, + receipt_aggregate_voucher::ReceiptAggregateVoucher, tap_eip712_domain, + tap_receipt::Receipt, }; #[fixture] @@ -277,12 +278,7 @@ mod tests { #[fixture] fn domain_separator() -> Eip712Domain { - eip712_domain! { - name: "TAP", - version: "1", - chain_id: 1, - verifying_contract: Address::from([0x11u8; 20]), - } + tap_eip712_domain(1, Address::from([0x11u8; 20])) } #[fixture] diff --git a/tap_core/benches/timeline_aggretion_protocol_benchmark.rs b/tap_core/benches/timeline_aggretion_protocol_benchmark.rs index c47c0138..7bcc36e8 100644 --- a/tap_core/benches/timeline_aggretion_protocol_benchmark.rs +++ b/tap_core/benches/timeline_aggretion_protocol_benchmark.rs @@ -11,12 +11,13 @@ use std::str::FromStr; use alloy_primitives::Address; -use alloy_sol_types::{eip712_domain, Eip712Domain}; +use alloy_sol_types::Eip712Domain; use criterion::async_executor::AsyncStdExecutor; use criterion::{black_box, criterion_group, criterion_main, Criterion}; use ethers::signers::{LocalWallet, Signer, Wallet}; use ethers_core::k256::ecdsa::SigningKey; use rand_core::OsRng; +use tap_core::tap_eip712_domain; use tap_core::{ eip_712_signed_message::EIP712SignedMessage, receipt_aggregate_voucher::ReceiptAggregateVoucher, tap_receipt::Receipt, @@ -39,12 +40,7 @@ pub async fn create_and_sign_receipt( } pub fn criterion_benchmark(c: &mut Criterion) { - let domain_seperator = eip712_domain! { - name: "TAP", - version: "1", - chain_id: 1, - verifying_contract: Address::from([0x11u8; 20]), - }; + let domain_seperator = tap_eip712_domain(1, Address::from([0x11u8; 20])); let async_runtime = Runtime::new().unwrap(); diff --git a/tap_core/src/adapters/test/rav_storage_adapter_test.rs b/tap_core/src/adapters/test/rav_storage_adapter_test.rs index a7234119..ce5c324f 100644 --- a/tap_core/src/adapters/test/rav_storage_adapter_test.rs +++ b/tap_core/src/adapters/test/rav_storage_adapter_test.rs @@ -6,7 +6,7 @@ mod rav_storage_adapter_unit_test { use std::{str::FromStr, sync::Arc}; use alloy_primitives::Address; - use alloy_sol_types::{eip712_domain, Eip712Domain}; + use alloy_sol_types::Eip712Domain; use ethers::signers::coins_bip39::English; use ethers::signers::{LocalWallet, MnemonicBuilder}; use rstest::*; @@ -16,6 +16,7 @@ mod rav_storage_adapter_unit_test { use crate::adapters::{ rav_storage_adapter::RAVStore, rav_storage_adapter_mock::RAVStorageAdapterMock, }; + use crate::tap_eip712_domain; use crate::{ eip_712_signed_message::EIP712SignedMessage, receipt_aggregate_voucher::ReceiptAggregateVoucher, tap_receipt::Receipt, @@ -23,12 +24,7 @@ mod rav_storage_adapter_unit_test { #[fixture] fn domain_separator() -> Eip712Domain { - eip712_domain! { - name: "TAP", - version: "1", - chain_id: 1, - verifying_contract: Address::from([0x11u8; 20]), - } + tap_eip712_domain(1, Address::from([0x11u8; 20])) } #[rstest] diff --git a/tap_core/src/adapters/test/receipt_checks_adapter_test.rs b/tap_core/src/adapters/test/receipt_checks_adapter_test.rs index 13693722..0d25f771 100644 --- a/tap_core/src/adapters/test/receipt_checks_adapter_test.rs +++ b/tap_core/src/adapters/test/receipt_checks_adapter_test.rs @@ -10,7 +10,7 @@ mod receipt_checks_adapter_unit_test { }; use alloy_primitives::Address; - use alloy_sol_types::{eip712_domain, Eip712Domain}; + use alloy_sol_types::Eip712Domain; use ethers::signers::{coins_bip39::English, LocalWallet, MnemonicBuilder}; use futures::{stream, StreamExt}; use rstest::*; @@ -22,17 +22,13 @@ mod receipt_checks_adapter_unit_test { receipt_checks_adapter_mock::ReceiptChecksAdapterMock, }, eip_712_signed_message::EIP712SignedMessage, + tap_eip712_domain, tap_receipt::{get_full_list_of_checks, Receipt, ReceivedReceipt}, }; #[fixture] fn domain_separator() -> Eip712Domain { - eip712_domain! { - name: "TAP", - version: "1", - chain_id: 1, - verifying_contract: Address::from([0x11u8; 20]), - } + tap_eip712_domain(1, Address::from([0x11u8; 20])) } #[rstest] diff --git a/tap_core/src/adapters/test/receipt_storage_adapter_test.rs b/tap_core/src/adapters/test/receipt_storage_adapter_test.rs index 6bd14395..26beeaf4 100644 --- a/tap_core/src/adapters/test/receipt_storage_adapter_test.rs +++ b/tap_core/src/adapters/test/receipt_storage_adapter_test.rs @@ -10,7 +10,7 @@ mod receipt_storage_adapter_unit_test { use std::sync::Arc; use alloy_primitives::Address; - use alloy_sol_types::{eip712_domain, Eip712Domain}; + use alloy_sol_types::Eip712Domain; use ethers::signers::coins_bip39::English; use ethers::signers::{LocalWallet, MnemonicBuilder}; use rstest::*; @@ -20,6 +20,7 @@ mod receipt_storage_adapter_unit_test { receipt_storage_adapter::ReceiptStore, receipt_storage_adapter_mock::ReceiptStorageAdapterMock, }; + use crate::tap_eip712_domain; use crate::tap_receipt::ReceivedReceipt; use crate::{ eip_712_signed_message::EIP712SignedMessage, tap_receipt::get_full_list_of_checks, @@ -28,12 +29,7 @@ mod receipt_storage_adapter_unit_test { #[fixture] fn domain_separator() -> Eip712Domain { - eip712_domain! { - name: "TAP", - version: "1", - chain_id: 1, - verifying_contract: Address::from([0x11u8; 20]), - } + tap_eip712_domain(1, Address::from([0x11u8; 20])) } #[rstest] diff --git a/tap_core/src/lib.rs b/tap_core/src/lib.rs index 8a577d63..42fcc0bb 100644 --- a/tap_core/src/lib.rs +++ b/tap_core/src/lib.rs @@ -8,6 +8,7 @@ use std::time::{SystemTime, UNIX_EPOCH}; +use alloy_sol_types::eip712_domain; use thiserror::Error; pub mod adapters; @@ -28,18 +29,31 @@ pub(crate) fn get_current_timestamp_u64_ns() -> Result { .as_nanos() as u64) } +pub fn tap_eip712_domain( + chain_id: u64, + verifying_contract_address: alloy_primitives::Address, +) -> alloy_sol_types::Eip712Domain { + eip712_domain! { + name: "TAP", + version: "1", + chain_id: chain_id, + verifying_contract: verifying_contract_address, + } +} + #[cfg(test)] mod tap_tests { use std::str::FromStr; use alloy_primitives::Address; - use alloy_sol_types::{eip712_domain, Eip712Domain}; + use alloy_sol_types::Eip712Domain; use ethers::signers::{coins_bip39::English, LocalWallet, MnemonicBuilder, Signer}; use rstest::*; use crate::{ eip_712_signed_message::EIP712SignedMessage, - receipt_aggregate_voucher::ReceiptAggregateVoucher, tap_receipt::Receipt, + receipt_aggregate_voucher::ReceiptAggregateVoucher, tap_eip712_domain, + tap_receipt::Receipt, }; #[fixture] @@ -67,12 +81,7 @@ mod tap_tests { #[fixture] fn domain_separator() -> Eip712Domain { - eip712_domain! { - name: "TAP", - version: "1", - chain_id: 1, - verifying_contract: Address::from([0x11u8; 20]), - } + tap_eip712_domain(1, Address::from([0x11u8; 20])) } #[rstest] diff --git a/tap_core/src/tap_manager/test/manager_test.rs b/tap_core/src/tap_manager/test/manager_test.rs index c81e38a0..09d04d99 100644 --- a/tap_core/src/tap_manager/test/manager_test.rs +++ b/tap_core/src/tap_manager/test/manager_test.rs @@ -10,7 +10,7 @@ mod manager_unit_test { }; use alloy_primitives::Address; - use alloy_sol_types::{eip712_domain, Eip712Domain}; + use alloy_sol_types::Eip712Domain; use ethers::signers::{coins_bip39::English, LocalWallet, MnemonicBuilder, Signer}; use rstest::*; use tokio::sync::RwLock; @@ -24,7 +24,7 @@ mod manager_unit_test { receipt_storage_adapter::ReceiptRead, }, eip_712_signed_message::EIP712SignedMessage, - get_current_timestamp_u64_ns, + get_current_timestamp_u64_ns, tap_eip712_domain, tap_receipt::{get_full_list_of_checks, Receipt, ReceiptCheck}, }; @@ -63,12 +63,7 @@ mod manager_unit_test { #[fixture] fn domain_separator() -> Eip712Domain { - eip712_domain! { - name: "TAP", - version: "1", - chain_id: 1, - verifying_contract: Address::from([0x11u8; 20]), - } + tap_eip712_domain(1, Address::from([0x11u8; 20])) } #[fixture] diff --git a/tap_core/src/tap_receipt/tests/received_receipt_tests.rs b/tap_core/src/tap_receipt/tests/received_receipt_tests.rs index c1df5712..64a52029 100644 --- a/tap_core/src/tap_receipt/tests/received_receipt_tests.rs +++ b/tap_core/src/tap_receipt/tests/received_receipt_tests.rs @@ -10,7 +10,7 @@ mod received_receipt_unit_test { }; use alloy_primitives::Address; - use alloy_sol_types::{eip712_domain, Eip712Domain}; + use alloy_sol_types::Eip712Domain; use ethers::signers::{coins_bip39::English, LocalWallet, MnemonicBuilder, Signer}; use rstest::*; use tokio::sync::RwLock; @@ -24,7 +24,7 @@ mod received_receipt_unit_test { receipt_storage_adapter_mock::ReceiptStorageAdapterMock, }, eip_712_signed_message::EIP712SignedMessage, - get_current_timestamp_u64_ns, + get_current_timestamp_u64_ns, tap_eip712_domain, tap_receipt::{ get_full_list_of_checks, Receipt, ReceiptAuditor, ReceiptCheck, ReceivedReceipt, }, @@ -121,12 +121,7 @@ mod received_receipt_unit_test { #[fixture] fn domain_separator() -> Eip712Domain { - eip712_domain! { - name: "TAP", - version: "1", - chain_id: 1, - verifying_contract: Address::from([0x11u8; 20]), - } + tap_eip712_domain(1, Address::from([0x11u8; 20])) } #[rstest] diff --git a/tap_integration_tests/tests/showcase.rs b/tap_integration_tests/tests/showcase.rs index 2d9a092d..0735e3ff 100644 --- a/tap_integration_tests/tests/showcase.rs +++ b/tap_integration_tests/tests/showcase.rs @@ -14,7 +14,7 @@ use std::{ }; use alloy_primitives::Address; -use alloy_sol_types::{eip712_domain, Eip712Domain}; +use alloy_sol_types::Eip712Domain; use anyhow::{Error, Result}; use ethers::signers::{coins_bip39::English, LocalWallet, MnemonicBuilder, Signer}; use jsonrpsee::{ @@ -33,6 +33,7 @@ use tap_core::{ receipt_storage_adapter_mock::ReceiptStorageAdapterMock, }, eip_712_signed_message::EIP712SignedMessage, + tap_eip712_domain, tap_manager::SignedRAV, tap_receipt::{Receipt, ReceiptCheck, ReceivedReceipt}, }; @@ -125,12 +126,7 @@ fn allocation_ids() -> Vec
{ // Domain separator is used to sign receipts/RAVs according to EIP-712 #[fixture] fn domain_separator() -> Eip712Domain { - eip712_domain! { - name: "TAP", - version: "1", - chain_id: 1, - verifying_contract: Address::from([0x11u8; 20]), - } + tap_eip712_domain(1, Address::from([0x11u8; 20])) } // Query price will typically be set by the Indexer. It's assumed to be part of the Indexer service.