diff --git a/tap_core/Cargo.toml b/tap_core/Cargo.toml index af50aa5b..4d504e19 100644 --- a/tap_core/Cargo.toml +++ b/tap_core/Cargo.toml @@ -28,7 +28,3 @@ thegraph-core = { workspace = true, features = ["alloy-signer-mnemonic"] } [features] default = ["in_memory"] in_memory = ["dep:tap_graph"] - -[[bench]] -name = 'timeline_aggretion_protocol_benchmark' -harness = false diff --git a/tap_core/benches/timeline_aggretion_protocol_benchmark.rs b/tap_core/benches/timeline_aggretion_protocol_benchmark.rs deleted file mode 100644 index c8a9d4ad..00000000 --- a/tap_core/benches/timeline_aggretion_protocol_benchmark.rs +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright 2023-, Semiotic AI, Inc. -// SPDX-License-Identifier: Apache-2.0 - -//! Module containing Receipt type used for providing and verifying a payment -//! -//! Receipts are used as single transaction promise of payment. A payment sender -//! creates a receipt and ECDSA signs it, then sends it to a payment receiver. -//! The payment receiver would verify the received receipt and store it to be -//! accumulated with other received receipts in the future. - -use std::str::FromStr; - -use criterion::{black_box, criterion_group, criterion_main, Criterion}; -use tap_core::{signed_message::Eip712SignedMessage, tap_eip712_domain}; -use tap_graph::{Receipt, ReceiptAggregateVoucher}; -use thegraph_core::alloy::{ - dyn_abi::Eip712Domain, primitives::Address, signers::local::PrivateKeySigner, -}; - -pub fn create_and_sign_receipt( - domain_separator: &Eip712Domain, - allocation_id: Address, - value: u128, - wallet: &PrivateKeySigner, -) -> Eip712SignedMessage { - Eip712SignedMessage::new( - domain_separator, - Receipt::new(allocation_id, value).unwrap(), - wallet, - ) - .unwrap() -} - -pub fn criterion_benchmark(c: &mut Criterion) { - let domain_seperator = tap_eip712_domain(1, Address::from([0x11u8; 20])); - - let wallet = PrivateKeySigner::random(); - let address = wallet.address(); - - // Arbitrary values wrapped in black box to avoid compiler optimizing them out - let allocation_id = Address::from_str("0xabababababababababababababababababababab").unwrap(); - let value = 12345u128; - - c.bench_function("Create Receipt", |b| { - b.iter(|| { - create_and_sign_receipt( - black_box(&domain_seperator), - black_box(allocation_id), - black_box(value), - black_box(&wallet), - ) - }) - }); - - let receipt = create_and_sign_receipt(&domain_seperator, allocation_id, value, &wallet); - - c.bench_function("Validate Receipt", |b| { - b.iter(|| { - black_box(&receipt) - .verify(black_box(&domain_seperator), black_box(address)) - .unwrap() - }) - }); - - let mut rav_group = c.benchmark_group("Create RAV with varying input sizes"); - - for log_number_of_receipts in 10..30 { - let receipts = (0..2 ^ log_number_of_receipts) - .map(|_| create_and_sign_receipt(&domain_seperator, allocation_id, value, &wallet)) - .collect::>(); - - rav_group.bench_function( - format!("Create RAV w/ 2^{} receipt's", log_number_of_receipts), - |b| { - b.iter(|| { - ReceiptAggregateVoucher::aggregate_receipts( - black_box(allocation_id), - black_box(&receipts), - black_box(None), - ) - }) - }, - ); - - let signed_rav = Eip712SignedMessage::new( - &domain_seperator, - ReceiptAggregateVoucher::aggregate_receipts(allocation_id, &receipts, None).unwrap(), - &wallet, - ) - .unwrap(); - - rav_group.bench_function( - format!("Validate RAV w/ 2^{} receipt's", log_number_of_receipts), - |b| b.iter(|| black_box(&signed_rav).verify(&domain_seperator, black_box(address))), - ); - } -} - -criterion_group!(benches, criterion_benchmark); -criterion_main!(benches); diff --git a/tap_core/src/lib.rs b/tap_core/src/lib.rs index 13cfa0ee..2ec4c62f 100644 --- a/tap_core/src/lib.rs +++ b/tap_core/src/lib.rs @@ -163,27 +163,4 @@ mod tap_tests { assert!(signed_rav.recover_signer(&domain_separator).unwrap() == keys.1); } - - #[rstest] - #[test] - fn verify_signature( - keys: (PrivateKeySigner, Address), - allocation_ids: Vec
, - domain_separator: Eip712Domain, - ) { - let signed_message = Eip712SignedMessage::new( - &domain_separator, - Receipt::new(allocation_ids[0], 42).unwrap(), - &keys.0, - ) - .unwrap(); - - assert!(signed_message.verify(&domain_separator, keys.1).is_ok()); - assert!(signed_message - .verify( - &domain_separator, - Address::from_str("0x76f4eeD9fE41262669D0250b2A97db79712aD855").unwrap() - ) - .unwrap()); - } } diff --git a/tap_eip712_message/src/lib.rs b/tap_eip712_message/src/lib.rs index d34ec748..e0899081 100644 --- a/tap_eip712_message/src/lib.rs +++ b/tap_eip712_message/src/lib.rs @@ -105,22 +105,6 @@ impl Eip712SignedMessage { Ok(recovered_address) } - /// Checks that receipts signature is valid for given verifying key, returns `Ok(true)` if it is valid. - /// - /// # Errors - /// - /// Returns [`crate::Error::SignatureError`] if the recovered address from the - /// signature is not equal to `expected_address` - /// - pub fn verify( - &self, - domain_separator: &Eip712Domain, - expected_address: Address, - ) -> Result { - let recovered_address = self.recover_signer(domain_separator)?; - Ok(recovered_address != expected_address) - } - /// Use this as a simple key for testing pub fn unique_hash(&self) -> MessageId { MessageId(self.message.eip712_hash_struct().into())