Skip to content

Commit 48f8351

Browse files
committed
Box all large values in state and messages.
Fix other lints. Note: not everything needs to be boxed, but doing so for simplicity. Smaller values should be used directly here.
1 parent a849db1 commit 48f8351

10 files changed

Lines changed: 65 additions & 59 deletions

File tree

crates/cac/protocol/src/deposit/evaluator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ fn stf(_config: &Config, state: State, input: Input) -> State {
9999
by_deposit: prev_by_deposit,
100100
}
101101
}
102-
State::SendingAdaptorMsg | State::DepositReady { .. } => State::Consumed { by_deposit },
102+
State::SendingAdaptorMsg | State::DepositReady => State::Consumed { by_deposit },
103103
_ => state,
104104
},
105105
}

crates/cac/protocol/src/deposit/garbler.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ pub enum State {
4444
WaitForAdaptors,
4545
DepositReady {
4646
adaptor_msg_id: MsgId,
47-
deposit_adaptors: DepositAdaptors,
48-
withdrawal_adaptors: WithdrawalAdaptors,
47+
deposit_adaptors: Box<DepositAdaptors>,
48+
withdrawal_adaptors: Box<WithdrawalAdaptors>,
4949
},
5050
Completed {
5151
counterproof_sig: (), // TODO: counterproof sig type
@@ -99,6 +99,7 @@ fn stf(_config: &Config, state: State, input: Input) -> State {
9999
},
100100
Input::GenerateCounterproofSignature(counterproof) => match state {
101101
State::DepositReady { .. } => {
102+
#[expect(clippy::let_unit_value, reason = "TODO: correct type")]
102103
let counterproof_sig = generate_counterproof_signature(counterproof);
103104
State::Completed { counterproof_sig }
104105
}

crates/cac/protocol/src/setup/evaluator.rs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -46,48 +46,48 @@ pub enum State {
4646
// challenge sent, waiting for challenge response
4747
ReceivedCommitments {
4848
commit_msg_id: MsgId,
49-
polynomial_commitments: PolynomialCommitments,
50-
garbling_table_commitments: GarblingTableCommitments,
49+
polynomial_commitments: Box<PolynomialCommitments>,
50+
garbling_table_commitments: Box<GarblingTableCommitments>,
5151
},
5252
// got challenge ack, now waiting for challenge response
5353
WaitChallengeResponse {
54-
polynomial_commitments: PolynomialCommitments,
55-
garbling_table_commitments: GarblingTableCommitments,
54+
polynomial_commitments: Box<PolynomialCommitments>,
55+
garbling_table_commitments: Box<GarblingTableCommitments>,
5656
},
5757
// received challenge response
5858
// verified shares are correct
5959
// triggered garb table verification for opened tables
6060
// waiting for verification to complete
6161
ReceivedChallegeResponse {
6262
challenge_response_msg_id: MsgId,
63-
polynomial_commitments: PolynomialCommitments,
64-
garbling_table_commitments: GarblingTableCommitments,
65-
opened_input_shares: OpenedInputShares,
66-
opened_output_shares: OpenedOutputShares,
67-
reserved_setup_input_shares: ReservedSetupInputShares,
68-
opened_garbling_seeds: OpenedGarblingSeeds,
63+
polynomial_commitments: Box<PolynomialCommitments>,
64+
garbling_table_commitments: Box<GarblingTableCommitments>,
65+
opened_input_shares: Box<OpenedInputShares>,
66+
opened_output_shares: Box<OpenedOutputShares>,
67+
reserved_setup_input_shares: Box<ReservedSetupInputShares>,
68+
opened_garbling_seeds: Box<OpenedGarblingSeeds>,
6969
},
7070
// verified commitments are valid for opened tables
7171
// triggered receive and verify remaining tables
7272
// waiting for tables to be received
7373
VerifiedGarblingTableCommitments {
74-
polynomial_commitments: PolynomialCommitments,
75-
garbling_table_commitments: GarblingTableCommitments,
76-
challenge_indices: ChallengeIndices,
77-
opened_input_shares: OpenedInputShares,
78-
opened_output_shares: OpenedOutputShares,
79-
reserved_setup_input_shares: ReservedSetupInputShares,
80-
opened_garbling_seeds: OpenedGarblingSeeds,
74+
polynomial_commitments: Box<PolynomialCommitments>,
75+
garbling_table_commitments: Box<GarblingTableCommitments>,
76+
challenge_indices: Box<ChallengeIndices>,
77+
opened_input_shares: Box<OpenedInputShares>,
78+
opened_output_shares: Box<OpenedOutputShares>,
79+
reserved_setup_input_shares: Box<ReservedSetupInputShares>,
80+
opened_garbling_seeds: Box<OpenedGarblingSeeds>,
8181
},
8282
SetupComplete {
8383
// TODO: remove states that are not needed
84-
polynomial_commitments: PolynomialCommitments,
85-
garbling_table_commitments: GarblingTableCommitments,
86-
challenge_indices: ChallengeIndices,
87-
opened_input_shares: OpenedInputShares,
88-
opened_output_shares: OpenedOutputShares,
89-
reserved_setup_input_shares: ReservedSetupInputShares,
90-
opened_garbling_seeds: OpenedGarblingSeeds,
84+
polynomial_commitments: Box<PolynomialCommitments>,
85+
garbling_table_commitments: Box<GarblingTableCommitments>,
86+
challenge_indices: Box<ChallengeIndices>,
87+
opened_input_shares: Box<OpenedInputShares>,
88+
opened_output_shares: Box<OpenedOutputShares>,
89+
reserved_setup_input_shares: Box<ReservedSetupInputShares>,
90+
opened_garbling_seeds: Box<OpenedGarblingSeeds>,
9191
},
9292
SetupConsumed {
9393
by_deposit: StateMachinePairId,
@@ -115,7 +115,7 @@ pub enum Action {
115115
SendCommitAck(MsgId),
116116
SendChallengeMsg(ChallengeMsg),
117117
SendChallengeResponseAck(MsgId),
118-
VerifyOpenedGarbTableCommitments(OpenedGarblingSeeds, GarblingTableCommitments),
118+
VerifyOpenedGarbTableCommitments(Box<OpenedGarblingSeeds>, Box<GarblingTableCommitments>),
119119
ReceiveGarblingTables(()), // TODO: types
120120
}
121121

@@ -183,7 +183,7 @@ fn stf(config: &Config, state: State, input: Input) -> State {
183183
opened_garbling_seeds,
184184
..
185185
} => {
186-
let challenge_indices = generate_challenge_indices(&config.seed);
186+
let challenge_indices = Box::new(generate_challenge_indices(&config.seed));
187187
State::VerifiedGarblingTableCommitments {
188188
polynomial_commitments,
189189
garbling_table_commitments,
@@ -227,7 +227,7 @@ fn emit_actions(config: &Config, state: &State) -> Vec<Action> {
227227
match state {
228228
State::Initialized => vec![],
229229
State::ReceivedCommitments { commit_msg_id, .. } => {
230-
let challenge_indices = generate_challenge_indices(&config.seed);
230+
let challenge_indices = Box::new(generate_challenge_indices(&config.seed));
231231
vec![
232232
Action::SendCommitAck(*commit_msg_id),
233233
Action::SendChallengeMsg(ChallengeMsg { challenge_indices }),
@@ -243,8 +243,8 @@ fn emit_actions(config: &Config, state: &State) -> Vec<Action> {
243243
vec![
244244
Action::SendChallengeResponseAck(*challenge_response_msg_id),
245245
Action::VerifyOpenedGarbTableCommitments(
246-
*opened_garbling_seeds,
247-
*garbling_table_commitments,
246+
opened_garbling_seeds.clone(),
247+
garbling_table_commitments.clone(),
248248
),
249249
]
250250
}

crates/cac/protocol/src/setup/garbler.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,23 @@ pub enum State {
4040
///
4141
/// Q: should polynomial commitments be stored or re-generated when needed ?
4242
SendCommit {
43-
garbling_table_commitments: GarblingTableCommitments,
43+
garbling_table_commitments: Box<GarblingTableCommitments>,
4444
},
4545
/// Wait for challenge msg
4646
WaitForChallenge,
4747
/// Got challenge message, send ack and challenge response
4848
ReceivedChallege {
4949
challenge_msg_id: MsgId,
50-
challenge_idxs: ChallengeIndices,
50+
challenge_idxs: Box<ChallengeIndices>,
5151
},
5252
/// Challenge response msg ack received, send garbling tables
53-
TransferGarblingTables { challenge_idxs: ChallengeIndices },
53+
TransferGarblingTables {
54+
challenge_idxs: Box<ChallengeIndices>,
55+
},
5456
/// Setup is completed, ready to be used for deposits.
55-
SetupComplete { challenge_idxs: ChallengeIndices },
57+
SetupComplete {
58+
challenge_idxs: Box<ChallengeIndices>,
59+
},
5660
/// Setup is consumed by a withdrawal dispute. Cannot be reused.
5761
SetupConsumed { by_deposit: StateMachinePairId },
5862
/// Setup was aborted due to a protocol violation.
@@ -71,7 +75,7 @@ pub struct Config {
7175
#[derive(Debug)]
7276
#[expect(missing_docs, reason = "wip")]
7377
pub enum Input {
74-
GTCommitmentsGenerated(GarblingTableCommitments),
78+
GTCommitmentsGenerated(Box<GarblingTableCommitments>),
7579
RecvCommitMessageAck,
7680
RecvChallengeMsg(ChallengeMsg),
7781
RecvChallengeReponseAck,
@@ -140,7 +144,7 @@ fn emit_actions(config: &Config, state: &State) -> Vec<Action> {
140144
State::SendCommit {
141145
garbling_table_commitments,
142146
} => {
143-
let polynomial_commitments = generate_polynomial_commmitments(config.seed);
147+
let polynomial_commitments = Box::new(generate_polynomial_commmitments(config.seed));
144148
let commit_msg = CommitMsg {
145149
polynomial_commitments,
146150
garbling_table_commitments: garbling_table_commitments.clone(),
@@ -154,7 +158,7 @@ fn emit_actions(config: &Config, state: &State) -> Vec<Action> {
154158
} => {
155159
let challenge_response = prepare_challenge_response_msg(config.seed, challenge_idxs);
156160
vec![
157-
Action::SendChallengeMsgAck(challenge_msg_id.clone()),
161+
Action::SendChallengeMsgAck(*challenge_msg_id),
158162
Action::SendChallengeResponseMsg(challenge_response),
159163
]
160164
}

crates/cac/types/src/msgs.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,30 +48,30 @@ pub trait HasMsgId {
4848
#[derive(Clone, Debug)]
4949
pub struct CommitMsg {
5050
/// N_INPUT_WIRES * 256 + 1
51-
pub polynomial_commitments: PolynomialCommitments,
51+
pub polynomial_commitments: Box<PolynomialCommitments>,
5252
/// N_CIRCUITS
53-
pub garbling_table_commitments: GarblingTableCommitments,
53+
pub garbling_table_commitments: Box<GarblingTableCommitments>,
5454
}
5555

5656
/// ChallengeMsg: Evaluator -> Garbler
5757
#[derive(Clone, Debug)]
5858
pub struct ChallengeMsg {
5959
/// N_COEFFICIENTS
60-
pub challenge_indices: ChallengeIndices,
60+
pub challenge_indices: Box<ChallengeIndices>,
6161
}
6262

6363
/// ChallengeResponseMsg: Garbler -> Evaluator
6464
/// Note: Garbling Tables are sent separately
6565
#[derive(Clone, Debug)]
6666
pub struct ChallengeResponseMsg {
6767
/// N_COEFFICIENTS * N_INPUT_WIRES * 256
68-
pub opened_input_shares: OpenedInputShares,
68+
pub opened_input_shares: Box<OpenedInputShares>,
6969
/// N_SETUP_INPUT_WIRES * 256
70-
pub reserved_setup_input_shares: ReservedSetupInputShares,
70+
pub reserved_setup_input_shares: Box<ReservedSetupInputShares>,
7171
/// N_COEFFICIENTS
72-
pub opened_output_shares: OpenedOutputShares,
72+
pub opened_output_shares: Box<OpenedOutputShares>,
7373
/// N_COEFFICIENTS
74-
pub opened_garbling_seeds: OpenedGarblingSeeds,
74+
pub opened_garbling_seeds: Box<OpenedGarblingSeeds>,
7575
}
7676

7777
/// N_DEPOSIT_INPUT_WIRES
@@ -83,9 +83,9 @@ pub type WithdrawalAdaptors = [[Adaptor; 256]; N_WITHDRAWAL_INPUT_WIRES];
8383
#[derive(Clone, Debug)]
8484
pub struct AdaptorMsg {
8585
/// N_DEPOSIT_INPUT_WIRES
86-
pub deposit_adaptors: DepositAdaptors,
86+
pub deposit_adaptors: Box<DepositAdaptors>,
8787
/// N_WITHDRAWAL_INPUT_WIRES * 256
88-
pub withdrawal_adaptors: WithdrawalAdaptors,
88+
pub withdrawal_adaptors: Box<WithdrawalAdaptors>,
8989
}
9090

9191
impl HasMsgId for CommitMsg {

crates/network/api/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ use async_trait::async_trait;
55
use futures::stream::BoxStream;
66
use mosaic_common::{
77
PeerId,
8-
codec::{Decode, Encode},
8+
codec::{Decodable, Encodable},
99
};
1010
use thiserror::Error;
1111

1212
/// Trait alias for network message bounds.
13-
pub trait NetworkMessage: Send + Clone + Encode + Decode + 'static {}
13+
pub trait NetworkMessage: Send + Clone + Encodable + Decodable + 'static {}
1414

15-
impl<T> NetworkMessage for T where T: Send + Clone + Encode + Decode + 'static {}
15+
impl<T> NetworkMessage for T where T: Send + Clone + Encodable + Decodable + 'static {}
1616

1717
/// A message to be sent to a specific peer.
1818
#[derive(Debug, Clone)]

crates/state-machine/api/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ keywords.workspace = true
1414
mosaic-cac-proto-types.workspace = true
1515
mosaic-cac-types.workspace = true
1616
mosaic-common.workspace = true
17-
mosaic-vs3.workspace = true
1817

1918
[lints]
2019
workspace = true

crates/state-machine/api/src/types/id.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub enum StateMachinePhase {
1111

1212
/// Uniquely identifies a state machine pair run between 2 parties (type, garbler_peer,
1313
/// evaluator_peer, instance).
14+
///
1415
/// As a single mosaic instance only holds one side of the pair, this id also uniquely identifies a
1516
/// state machine inside one mosaic client.
1617
#[derive(Debug)]

crates/state-machine/api/src/types/msgs.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use mosaic_cac_types::{GarblingTableCommitments, Msg, OpenedGarblingSeeds, Seed, SetupInputs};
2-
use mosaic_common::constants::N_EVAL_CIRCUITS;
3-
use mosaic_vs3::Index;
1+
use mosaic_cac_types::{
2+
EvaluationIndices, GarblingTableCommitments, Msg, OpenedGarblingSeeds, Seed, SetupInputs,
3+
};
44

55
use crate::{StateMachineMetadata, StateMachinePairId};
66

@@ -43,7 +43,7 @@ pub enum ExecutorInputMsgType {
4343
#[derive(Debug)]
4444
#[expect(missing_docs, reason = "wip")]
4545
pub enum JobCompletionReport {
46-
GTCommitmentsGenerated(GarblingTableCommitments),
46+
GTCommitmentsGenerated(Box<GarblingTableCommitments>),
4747
GarblingTablesTransferred,
4848
GarblingTablesReceived(bool),
4949
GTCommitmentsVerified(bool),
@@ -99,8 +99,8 @@ pub enum ExecutorOutputMsgType {
9999
#[expect(missing_docs, reason = "wip")]
100100
pub enum JobExecution {
101101
GenerateGTCommitments(Seed),
102-
TransferGarblingTables(Seed, [Index; N_EVAL_CIRCUITS]),
103-
ReceiveAndVerifyGarblingTables([Index; N_EVAL_CIRCUITS], GarblingTableCommitments),
104-
VerifyGTCommitments(OpenedGarblingSeeds, GarblingTableCommitments),
102+
TransferGarblingTables(Seed, Box<EvaluationIndices>),
103+
ReceiveAndVerifyGarblingTables(Box<EvaluationIndices>, Box<GarblingTableCommitments>),
104+
VerifyGTCommitments(Box<OpenedGarblingSeeds>, Box<GarblingTableCommitments>),
105105
EvaluateGarbTables(()),
106106
}

crates/state-machine/executor/src/adaptor/setup_evaluator.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub struct AdaptorState {
1919
challenge_response_ack: Option<MsgId>,
2020
}
2121

22+
#[expect(clippy::derivable_impls, reason = "keeping this explicit")]
2223
impl Default for AdaptorState {
2324
fn default() -> Self {
2425
Self {

0 commit comments

Comments
 (0)