Skip to content

Commit ccd054e

Browse files
authored
feat: add the address check in MoveAuthenticator, allow only one(sender) MoveAuthenticator (#8963)
# Description of change 1. Improved `MoveAuthenticator:: verify_claims` implementation by checking the author address. 2. Check a transaction's authenticator amount; allow only one authenticator(sender) until we implement sponsor support. ## Links to any relevant issues fixes #8747
1 parent 4f3071a commit ccd054e

File tree

3 files changed

+62
-25
lines changed

3 files changed

+62
-25
lines changed

crates/iota-core/src/authority.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ impl AuthorityState {
912912
epoch,
913913
)?;
914914

915-
if let Some(move_authenticator) = transaction.move_authenticator() {
915+
if let Some(move_authenticator) = transaction.sender_move_authenticator() {
916916
// It is supposed that `Move authentication` availability is checked in
917917
// `SenderSignedData::validity_check`.
918918

@@ -1348,7 +1348,7 @@ impl AuthorityState {
13481348
.execution_load_input_objects_latency
13491349
.start_timer();
13501350

1351-
let objects = if let Some(move_authenticator) = certificate.move_authenticator() {
1351+
let objects = if let Some(move_authenticator) = certificate.sender_move_authenticator() {
13521352
// It is supposed that `Move authentication` availability is checked in
13531353
// `SenderSignedData::validity_check`.
13541354

@@ -1779,7 +1779,7 @@ impl AuthorityState {
17791779
let (kind, signer, gas) = tx_data.execution_parts();
17801780

17811781
let authenticator_computation_cost = if let Some(move_authenticator) =
1782-
certificate.move_authenticator()
1782+
certificate.sender_move_authenticator()
17831783
{
17841784
// It is supposed that `Move authentication` availability is checked in
17851785
// `SenderSignedData::validity_check`.

crates/iota-types/src/move_authenticator.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::{
1818
committee::EpochId,
1919
crypto::{SignatureScheme, default_hash},
2020
digests::{MoveAuthenticatorDigest, ObjectDigest, ZKLoginInputsDigest},
21-
error::{IotaResult, UserInputError},
21+
error::{IotaError, IotaResult, UserInputError},
2222
signature::{AuthenticatorTrait, VerifyParams},
2323
signature_verification::VerifiedDigestCache,
2424
transaction::{CallArg, InputObjectKind, ObjectArg, SharedInputObject},
@@ -157,13 +157,19 @@ impl AuthenticatorTrait for MoveAuthenticator {
157157
fn verify_claims<T>(
158158
&self,
159159
_value: &IntentMessage<T>,
160-
_author: IotaAddress,
160+
author: IotaAddress,
161161
_aux_verify_data: &VerifyParams,
162162
_zklogin_inputs_cache: Arc<VerifiedDigestCache<ZKLoginInputsDigest>>,
163163
) -> IotaResult
164164
where
165165
T: Serialize,
166166
{
167+
if author != self.address()? {
168+
return Err(IotaError::InvalidSignature {
169+
error: "Invalid author".to_string(),
170+
});
171+
};
172+
167173
Ok(())
168174
}
169175
}

crates/iota-types/src/transaction.rs

Lines changed: 51 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2428,13 +2428,35 @@ impl SenderSignedData {
24282428
}
24292429
);
24302430

2431-
// Check the `MoveAuthenticator` transactions limitations.
2432-
if self.move_authenticator().is_some() && !tx_data.kind().is_programmable_transaction() {
2433-
return Err(UserInputError::Unsupported(
2434-
"SenderSignedData with MoveAuthenticator must be a programmable transaction"
2435-
.to_string(),
2436-
)
2437-
.into());
2431+
// Check the `MoveAuthenticator` limitations.
2432+
let authenticators_num = self.move_authenticators().len();
2433+
if authenticators_num > 0 {
2434+
if !tx_data.kind().is_programmable_transaction() {
2435+
return Err(UserInputError::Unsupported(
2436+
"SenderSignedData with MoveAuthenticator must be a programmable transaction"
2437+
.to_string(),
2438+
)
2439+
.into());
2440+
}
2441+
2442+
// TODO(https://github.com/iotaledger/iota/issues/8966): The following
2443+
// restrictions are temporary added until we implement MoveAuthenticator support
2444+
// for sponsors.
2445+
2446+
if authenticators_num > 1 {
2447+
return Err(UserInputError::Unsupported(
2448+
"SenderSignedData with more than one MoveAuthenticator is not supported"
2449+
.to_string(),
2450+
)
2451+
.into());
2452+
}
2453+
2454+
if self.sender_move_authenticator().is_none() {
2455+
return Err(UserInputError::Unsupported(
2456+
"SenderSignedData can have MoveAuthenticator only for the sender".to_string(),
2457+
)
2458+
.into());
2459+
}
24382460
}
24392461

24402462
// Checks to see if the transaction has expired
@@ -2467,19 +2489,28 @@ impl SenderSignedData {
24672489
Ok(tx_size)
24682490
}
24692491

2470-
// TODO: A temporary created function. Needs to be replaced with a proper check.
2471-
pub fn move_authenticator(&self) -> Option<&MoveAuthenticator> {
2472-
let signatures = self.tx_signatures();
2492+
pub fn move_authenticators(&self) -> Vec<&MoveAuthenticator> {
2493+
self.tx_signatures()
2494+
.iter()
2495+
.filter_map(|sig| {
2496+
if let GenericSignature::MoveAuthenticator(move_authenticator) = sig {
2497+
Some(move_authenticator)
2498+
} else {
2499+
None
2500+
}
2501+
})
2502+
.collect()
2503+
}
2504+
2505+
pub fn sender_move_authenticator(&self) -> Option<&MoveAuthenticator> {
2506+
let sender = self.intent_message().value.sender();
24732507

2474-
if signatures.len() == 1 {
2475-
if let GenericSignature::MoveAuthenticator(move_authenticator) = &signatures[0] {
2476-
Some(move_authenticator)
2477-
} else {
2478-
None
2479-
}
2480-
} else {
2481-
None
2482-
}
2508+
self.move_authenticators()
2509+
.into_iter()
2510+
.find(|a| match a.address() {
2511+
Ok(addr) => addr == sender,
2512+
Err(_) => false,
2513+
})
24832514
}
24842515
}
24852516

@@ -2512,7 +2543,7 @@ impl<S> Envelope<SenderSignedData, S> {
25122543
pub fn shared_input_objects(&self) -> impl Iterator<Item = SharedInputObject> + '_ {
25132544
// Add the Move authenticator shared objects if any.
25142545
let authenticator_shared_objects =
2515-
if let Some(move_authenticator) = self.move_authenticator() {
2546+
if let Some(move_authenticator) = self.sender_move_authenticator() {
25162547
move_authenticator
25172548
.shared_objects()
25182549
.into_iter()

0 commit comments

Comments
 (0)