@@ -12,9 +12,12 @@ use mysten_metrics::monitored_scope;
12
12
use parking_lot:: { Mutex , MutexGuard , RwLock } ;
13
13
use prometheus:: { register_int_counter_with_registry, IntCounter , Registry } ;
14
14
use shared_crypto:: intent:: Intent ;
15
+ use std:: collections:: { BTreeMap , BTreeSet } ;
15
16
use std:: sync:: Arc ;
16
- use sui_types:: digests:: SenderSignedDataDigest ;
17
+ use sui_protocol_config:: AliasedAddress ;
18
+ use sui_types:: base_types:: SuiAddress ;
17
19
use sui_types:: digests:: ZKLoginInputsDigest ;
20
+ use sui_types:: digests:: { SenderSignedDataDigest , TransactionDigest } ;
18
21
use sui_types:: signature_verification:: {
19
22
verify_sender_signed_data_message_signatures, VerifiedDigestCache ,
20
23
} ;
@@ -87,6 +90,7 @@ impl CertBuffer {
87
90
}
88
91
}
89
92
93
+ pub type AliasedAddressMap = BTreeMap < SuiAddress , ( SuiAddress , BTreeSet < TransactionDigest > ) > ;
90
94
/// Verifies signatures in ways that faster than verifying each signature individually.
91
95
/// - BLS signatures - caching and batch verification.
92
96
/// - User signed data - caching.
@@ -96,6 +100,10 @@ pub struct SignatureVerifier {
96
100
signed_data_cache : VerifiedDigestCache < SenderSignedDataDigest > ,
97
101
zklogin_inputs_cache : Arc < VerifiedDigestCache < ZKLoginInputsDigest > > ,
98
102
103
+ /// Map from original address to aliased address and the list of transaction digests for
104
+ /// which the aliasing is allowed to be in effect.
105
+ aliased_addresses : Option < Arc < AliasedAddressMap > > ,
106
+
99
107
/// Map from JwkId (iss, kid) to the fetched JWK for that key.
100
108
/// We use an immutable data structure because verification of ZKLogins may be slow, so we
101
109
/// don't want to pass a reference to the map to the verify method, since that would lead to a
@@ -138,7 +146,36 @@ impl SignatureVerifier {
138
146
accept_zklogin_in_multisig : bool ,
139
147
accept_passkey_in_multisig : bool ,
140
148
zklogin_max_epoch_upper_bound_delta : Option < u64 > ,
149
+ aliased_addresses : Vec < AliasedAddress > ,
141
150
) -> Self {
151
+ let aliased_addresses: Option < Arc < BTreeMap < _ , _ > > > = if aliased_addresses. is_empty ( ) {
152
+ None
153
+ } else {
154
+ Some ( Arc :: new (
155
+ aliased_addresses
156
+ . into_iter ( )
157
+ . map (
158
+ |AliasedAddress {
159
+ original,
160
+ aliased,
161
+ allowed_tx_digests,
162
+ } | {
163
+ (
164
+ SuiAddress :: from_bytes ( original) . unwrap ( ) ,
165
+ (
166
+ SuiAddress :: from_bytes ( aliased) . unwrap ( ) ,
167
+ allowed_tx_digests
168
+ . into_iter ( )
169
+ . map ( TransactionDigest :: new)
170
+ . collect ( ) ,
171
+ ) ,
172
+ )
173
+ } ,
174
+ )
175
+ . collect ( ) ,
176
+ ) )
177
+ } ;
178
+
142
179
Self {
143
180
committee,
144
181
certificate_cache : VerifiedDigestCache :: new (
@@ -167,6 +204,7 @@ impl SignatureVerifier {
167
204
accept_passkey_in_multisig,
168
205
zklogin_max_epoch_upper_bound_delta,
169
206
} ,
207
+ aliased_addresses,
170
208
}
171
209
}
172
210
@@ -179,6 +217,7 @@ impl SignatureVerifier {
179
217
accept_zklogin_in_multisig : bool ,
180
218
accept_passkey_in_multisig : bool ,
181
219
zklogin_max_epoch_upper_bound_delta : Option < u64 > ,
220
+ aliased_addresses : Vec < AliasedAddress > ,
182
221
) -> Self {
183
222
Self :: new_with_batch_size (
184
223
committee,
@@ -190,6 +229,7 @@ impl SignatureVerifier {
190
229
accept_zklogin_in_multisig,
191
230
accept_passkey_in_multisig,
192
231
zklogin_max_epoch_upper_bound_delta,
232
+ aliased_addresses,
193
233
)
194
234
}
195
235
@@ -319,9 +359,16 @@ impl SignatureVerifier {
319
359
let committee = self . committee . clone ( ) ;
320
360
let metrics = self . metrics . clone ( ) ;
321
361
let zklogin_inputs_cache = self . zklogin_inputs_cache . clone ( ) ;
362
+ let aliased_addresses = self . aliased_addresses . clone ( ) ;
322
363
Handle :: current ( )
323
364
. spawn_blocking ( move || {
324
- Self :: process_queue_sync ( committee, metrics, buffer, zklogin_inputs_cache)
365
+ Self :: process_queue_sync (
366
+ committee,
367
+ metrics,
368
+ buffer,
369
+ zklogin_inputs_cache,
370
+ aliased_addresses. as_ref ( ) . map ( |arc| arc. as_ref ( ) ) ,
371
+ )
325
372
} )
326
373
. await
327
374
. expect ( "Spawn blocking should not fail" ) ;
@@ -332,13 +379,15 @@ impl SignatureVerifier {
332
379
metrics : Arc < SignatureVerifierMetrics > ,
333
380
buffer : CertBuffer ,
334
381
zklogin_inputs_cache : Arc < VerifiedDigestCache < ZKLoginInputsDigest > > ,
382
+ aliased_addresses : Option < & BTreeMap < SuiAddress , ( SuiAddress , BTreeSet < TransactionDigest > ) > > ,
335
383
) {
336
384
let _scope = monitored_scope ( "BatchCertificateVerifier::process_queue" ) ;
337
385
338
386
let results = batch_verify_certificates (
339
387
& committee,
340
388
& buffer. certs . iter ( ) . collect_vec ( ) ,
341
389
zklogin_inputs_cache,
390
+ aliased_addresses,
342
391
) ;
343
392
izip ! (
344
393
results. into_iter( ) ,
@@ -403,6 +452,7 @@ impl SignatureVerifier {
403
452
self . committee . epoch ( ) ,
404
453
& verify_params,
405
454
self . zklogin_inputs_cache . clone ( ) ,
455
+ self . aliased_addresses . as_ref ( ) . map ( |arc| arc. as_ref ( ) ) ,
406
456
)
407
457
} ,
408
458
|| Ok ( ( ) ) ,
@@ -544,6 +594,7 @@ pub fn batch_verify_certificates(
544
594
committee : & Committee ,
545
595
certs : & [ & CertifiedTransaction ] ,
546
596
zk_login_cache : Arc < VerifiedDigestCache < ZKLoginInputsDigest > > ,
597
+ aliased_addresses : Option < & BTreeMap < SuiAddress , ( SuiAddress , BTreeSet < TransactionDigest > ) > > ,
547
598
) -> Vec < SuiResult > {
548
599
// certs.data() is assumed to be verified already by the caller.
549
600
let verify_params = VerifyParams :: default ( ) ;
@@ -556,7 +607,12 @@ pub fn batch_verify_certificates(
556
607
// TODO: verify_signature currently checks the tx sig as well, which might be cached
557
608
// already.
558
609
. map ( |c| {
559
- c. verify_signatures_authenticated ( committee, & verify_params, zk_login_cache. clone ( ) )
610
+ c. verify_signatures_authenticated (
611
+ committee,
612
+ & verify_params,
613
+ zk_login_cache. clone ( ) ,
614
+ aliased_addresses,
615
+ )
560
616
} )
561
617
. collect ( ) ,
562
618
0 commit comments