Skip to content

Commit 43c5e6c

Browse files
committed
feat(tap-core-bench): update to work with alloy changes
Signed-off-by: Bryan Cole <[email protected]>
1 parent a99af2f commit 43c5e6c

File tree

1 file changed

+37
-8
lines changed

1 file changed

+37
-8
lines changed

tap_core/benches/timeline_aggretion_protocol_benchmark.rs

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
1111
use std::str::FromStr;
1212

13+
use alloy_primitives::Address;
14+
use alloy_sol_types::{eip712_domain, Eip712Domain};
1315
use criterion::async_executor::AsyncStdExecutor;
1416
use criterion::{black_box, criterion_group, criterion_main, Criterion};
15-
use ethereum_types::Address;
1617
use ethers::signers::{LocalWallet, Signer, Wallet};
1718
use ethers_core::k256::ecdsa::SigningKey;
1819
use rand_core::OsRng;
@@ -23,19 +24,33 @@ use tap_core::{
2324
use tokio::runtime::Runtime;
2425

2526
pub 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

3541
pub 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

Comments
 (0)