1010
1111use std:: str:: FromStr ;
1212
13+ use alloy_primitives:: Address ;
14+ use alloy_sol_types:: { eip712_domain, Eip712Domain } ;
1315use criterion:: async_executor:: AsyncStdExecutor ;
1416use criterion:: { black_box, criterion_group, criterion_main, Criterion } ;
15- use ethereum_types:: Address ;
1617use ethers:: signers:: { LocalWallet , Signer , Wallet } ;
1718use ethers_core:: k256:: ecdsa:: SigningKey ;
1819use rand_core:: OsRng ;
@@ -23,19 +24,33 @@ use tap_core::{
2324use tokio:: runtime:: Runtime ;
2425
2526pub async fn create_and_sign_receipt (
27+ domain_separator : & Eip712Domain ,
2628 allocation_id : Address ,
2729 value : u128 ,
2830 wallet : & Wallet < SigningKey > ,
2931) -> EIP712SignedMessage < Receipt > {
30- EIP712SignedMessage :: new ( Receipt :: new ( allocation_id, value) . unwrap ( ) , wallet)
31- . await
32- . unwrap ( )
32+ EIP712SignedMessage :: new (
33+ domain_separator,
34+ Receipt :: new ( allocation_id, value) . unwrap ( ) ,
35+ wallet,
36+ )
37+ . await
38+ . unwrap ( )
3339}
3440
3541pub fn criterion_benchmark ( c : & mut Criterion ) {
42+ let domain_seperator = eip712_domain ! {
43+ name: "TAP" ,
44+ version: "1" ,
45+ chain_id: 1 ,
46+ verifying_contract: Address :: from( [ 0x11u8 ; 20 ] ) ,
47+ } ;
48+
3649 let async_runtime = Runtime :: new ( ) . unwrap ( ) ;
3750
3851 let wallet = LocalWallet :: new ( & mut OsRng ) ;
52+ let address: [ u8 ; 20 ] = wallet. address ( ) . into ( ) ;
53+ let address: Address = address. into ( ) ;
3954
4055 // Arbitrary values wrapped in black box to avoid compiler optimizing them out
4156 let allocation_id = Address :: from_str ( "0xabababababababababababababababababababab" ) . unwrap ( ) ;
@@ -44,19 +59,25 @@ pub fn criterion_benchmark(c: &mut Criterion) {
4459 c. bench_function ( "Create Receipt" , |b| {
4560 b. to_async ( AsyncStdExecutor ) . iter ( || {
4661 create_and_sign_receipt (
62+ black_box ( & domain_seperator) ,
4763 black_box ( allocation_id) ,
4864 black_box ( value) ,
4965 black_box ( & wallet) ,
5066 )
5167 } )
5268 } ) ;
5369
54- let receipt = async_runtime. block_on ( create_and_sign_receipt ( allocation_id, value, & wallet) ) ;
70+ let receipt = async_runtime. block_on ( create_and_sign_receipt (
71+ & domain_seperator,
72+ allocation_id,
73+ value,
74+ & wallet,
75+ ) ) ;
5576
5677 c. bench_function ( "Validate Receipt" , |b| {
5778 b. iter ( || {
5879 black_box ( & receipt)
59- . verify ( black_box ( wallet . address ( ) ) )
80+ . verify ( black_box ( & domain_seperator ) , black_box ( address ) )
6081 . unwrap ( )
6182 } )
6283 } ) ;
@@ -65,7 +86,14 @@ pub fn criterion_benchmark(c: &mut Criterion) {
6586
6687 for log_number_of_receipts in 10 ..30 {
6788 let receipts = ( 0 ..2 ^ log_number_of_receipts)
68- . map ( |_| async_runtime. block_on ( create_and_sign_receipt ( allocation_id, value, & wallet) ) )
89+ . map ( |_| {
90+ async_runtime. block_on ( create_and_sign_receipt (
91+ & domain_seperator,
92+ allocation_id,
93+ value,
94+ & wallet,
95+ ) )
96+ } )
6997 . collect :: < Vec < _ > > ( ) ;
7098
7199 rav_group. bench_function (
@@ -83,6 +111,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
83111
84112 let signed_rav = async_runtime
85113 . block_on ( EIP712SignedMessage :: new (
114+ & domain_seperator,
86115 ReceiptAggregateVoucher :: aggregate_receipts ( allocation_id, & receipts, None )
87116 . unwrap ( ) ,
88117 & wallet,
@@ -91,7 +120,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
91120
92121 rav_group. bench_function (
93122 & format ! ( "Validate RAV w/ 2^{} receipt's" , log_number_of_receipts) ,
94- |b| b. iter ( || black_box ( & signed_rav) . verify ( black_box ( wallet . address ( ) ) ) ) ,
123+ |b| b. iter ( || black_box ( & signed_rav) . verify ( & domain_seperator , black_box ( address) ) ) ,
95124 ) ;
96125 }
97126}
0 commit comments