Skip to content

Commit 3cd2292

Browse files
committed
Add constants for errors
1 parent 66c87c3 commit 3cd2292

File tree

2 files changed

+38
-12
lines changed
  • crates/kilt-dip-primitives/src/verifier

2 files changed

+38
-12
lines changed

crates/kilt-dip-primitives/src/verifier/parachain/v0/mod.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ mod mock;
4040
#[cfg(test)]
4141
mod tests;
4242

43+
const PARACHAIN_HEAD_PROOF_TOO_MANY_LEAVES_ERROR_CODE: u8 = 0;
44+
const PARACHAIN_HEAD_PROOF_LEAF_TOO_LARGE_ERROR_CODE: u8 = 1;
45+
const DIP_COMMITMENT_PROOF_TOO_MANY_LEAVES_ERROR_CODE: u8 = 2;
46+
const DIP_COMMITMENT_PROOF_LEAF_TOO_LARGE_ERROR_CODE: u8 = 3;
47+
const DIP_PROOF_TOO_MANY_LEAVES_ERROR_CODE: u8 = 4;
48+
const DIP_PROOF_LEAF_TOO_LARGE_ERROR_CODE: u8 = 5;
49+
4350
/// Proof verifier configured given a specific KILT runtime implementation.
4451
///
4552
/// The generic types
@@ -173,15 +180,17 @@ impl<
173180
// 1. Verify parachain state is finalized by relay chain and fresh.
174181
ensure!(
175182
proof.provider_head_proof.proof.len() <= MAX_PROVIDER_HEAD_PROOF_LEAVE_COUNT.saturated_into(),
176-
DipParachainStateProofVerifierError::ProofComponentTooLarge(0)
183+
DipParachainStateProofVerifierError::ProofComponentTooLarge(
184+
PARACHAIN_HEAD_PROOF_TOO_MANY_LEAVES_ERROR_CODE
185+
)
177186
);
178187
ensure!(
179188
proof
180189
.provider_head_proof
181190
.proof
182191
.iter()
183192
.all(|l| l.len() <= MAX_PROVIDER_HEAD_PROOF_LEAVE_SIZE.saturated_into()),
184-
DipParachainStateProofVerifierError::ProofComponentTooLarge(1)
193+
DipParachainStateProofVerifierError::ProofComponentTooLarge(PARACHAIN_HEAD_PROOF_LEAF_TOO_LARGE_ERROR_CODE)
185194
);
186195
let proof_without_relaychain = proof
187196
.verify_provider_head_proof::<RelaychainRuntime::Hashing, RelaychainStateRootStore, HeaderFor<KiltRuntime>>(
@@ -193,15 +202,17 @@ impl<
193202
ensure!(
194203
proof_without_relaychain.dip_commitment_proof.0.len()
195204
<= MAX_DIP_COMMITMENT_PROOF_LEAVE_COUNT.saturated_into(),
196-
DipParachainStateProofVerifierError::ProofComponentTooLarge(2)
205+
DipParachainStateProofVerifierError::ProofComponentTooLarge(
206+
DIP_COMMITMENT_PROOF_TOO_MANY_LEAVES_ERROR_CODE
207+
)
197208
);
198209
ensure!(
199210
proof_without_relaychain
200211
.dip_commitment_proof
201212
.0
202213
.iter()
203214
.all(|l| l.len() <= MAX_DIP_COMMITMENT_PROOF_LEAVE_SIZE.saturated_into()),
204-
DipParachainStateProofVerifierError::ProofComponentTooLarge(3)
215+
DipParachainStateProofVerifierError::ProofComponentTooLarge(DIP_COMMITMENT_PROOF_LEAF_TOO_LARGE_ERROR_CODE)
205216
);
206217
let proof_without_parachain = proof_without_relaychain
207218
.verify_dip_commitment_proof_for_subject::<KiltRuntime::Hashing, KiltRuntime>(subject)
@@ -210,15 +221,15 @@ impl<
210221
// 3. Verify DIP Merkle proof.
211222
ensure!(
212223
proof_without_parachain.dip_proof.blinded.len() <= MAX_DID_MERKLE_PROOF_LEAVE_COUNT.saturated_into(),
213-
DipParachainStateProofVerifierError::ProofComponentTooLarge(4)
224+
DipParachainStateProofVerifierError::ProofComponentTooLarge(DIP_PROOF_TOO_MANY_LEAVES_ERROR_CODE)
214225
);
215226
ensure!(
216227
proof_without_parachain
217228
.dip_proof
218229
.blinded
219230
.iter()
220231
.all(|l| l.len() <= MAX_DID_MERKLE_PROOF_LEAVE_SIZE.saturated_into()),
221-
DipParachainStateProofVerifierError::ProofComponentTooLarge(5)
232+
DipParachainStateProofVerifierError::ProofComponentTooLarge(DIP_PROOF_LEAF_TOO_LARGE_ERROR_CODE)
222233
);
223234
let proof_without_dip_merkle = proof_without_parachain
224235
.verify_dip_proof::<KiltRuntime::Hashing, MAX_DID_MERKLE_LEAVES_REVEALED>()

crates/kilt-dip-primitives/src/verifier/relaychain/v0/mod.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ use crate::{
3434
DipOriginInfo, DipRelaychainStateProofVerifierError, RelayDipDidProof, RevealedDidKey,
3535
};
3636

37+
const PARACHAIN_HEAD_PROOF_TOO_MANY_LEAVES_ERROR_CODE: u8 = 0;
38+
const PARACHAIN_HEAD_PROOF_LEAF_TOO_LARGE_ERROR_CODE: u8 = 1;
39+
const DIP_COMMITMENT_PROOF_TOO_MANY_LEAVES_ERROR_CODE: u8 = 2;
40+
const DIP_COMMITMENT_PROOF_LEAF_TOO_LARGE_ERROR_CODE: u8 = 3;
41+
const DIP_PROOF_TOO_MANY_LEAVES_ERROR_CODE: u8 = 4;
42+
const DIP_PROOF_LEAF_TOO_LARGE_ERROR_CODE: u8 = 5;
43+
3744
/// Proof verifier configured given a specific KILT runtime implementation.
3845
///
3946
/// The generic types are the following:
@@ -160,15 +167,19 @@ impl<
160167
ensure!(
161168
proof_without_header.provider_head_proof.proof.len()
162169
<= MAX_PROVIDER_HEAD_PROOF_LEAVE_COUNT.saturated_into(),
163-
DipRelaychainStateProofVerifierError::ProofComponentTooLarge(0)
170+
DipRelaychainStateProofVerifierError::ProofComponentTooLarge(
171+
PARACHAIN_HEAD_PROOF_TOO_MANY_LEAVES_ERROR_CODE
172+
)
164173
);
165174
ensure!(
166175
proof_without_header
167176
.provider_head_proof
168177
.proof
169178
.iter()
170179
.all(|l| l.len() <= MAX_PROVIDER_HEAD_PROOF_LEAVE_SIZE.saturated_into()),
171-
DipRelaychainStateProofVerifierError::ProofComponentTooLarge(1)
180+
DipRelaychainStateProofVerifierError::ProofComponentTooLarge(
181+
PARACHAIN_HEAD_PROOF_LEAF_TOO_LARGE_ERROR_CODE
182+
)
172183
);
173184
let proof_without_relaychain = proof_without_header
174185
.verify_provider_head_proof::<ConsumerRuntime::Hashing, HeaderFor<KiltRuntime>>(KILT_PARA_ID)
@@ -178,15 +189,19 @@ impl<
178189
ensure!(
179190
proof_without_relaychain.dip_commitment_proof.0.len()
180191
<= MAX_DIP_COMMITMENT_PROOF_LEAVE_COUNT.saturated_into(),
181-
DipRelaychainStateProofVerifierError::ProofComponentTooLarge(2)
192+
DipRelaychainStateProofVerifierError::ProofComponentTooLarge(
193+
DIP_COMMITMENT_PROOF_TOO_MANY_LEAVES_ERROR_CODE
194+
)
182195
);
183196
ensure!(
184197
proof_without_relaychain
185198
.dip_commitment_proof
186199
.0
187200
.iter()
188201
.all(|l| l.len() <= MAX_DIP_COMMITMENT_PROOF_LEAVE_SIZE.saturated_into()),
189-
DipRelaychainStateProofVerifierError::ProofComponentTooLarge(3)
202+
DipRelaychainStateProofVerifierError::ProofComponentTooLarge(
203+
DIP_COMMITMENT_PROOF_LEAF_TOO_LARGE_ERROR_CODE
204+
)
190205
);
191206
let proof_without_parachain = proof_without_relaychain
192207
.verify_dip_commitment_proof_for_subject::<KiltRuntime::Hashing, KiltRuntime>(subject)
@@ -195,15 +210,15 @@ impl<
195210
// 4. Verify DIP Merkle proof.
196211
ensure!(
197212
proof_without_parachain.dip_proof.blinded.len() <= MAX_DID_MERKLE_PROOF_LEAVE_COUNT.saturated_into(),
198-
DipRelaychainStateProofVerifierError::ProofComponentTooLarge(4)
213+
DipRelaychainStateProofVerifierError::ProofComponentTooLarge(DIP_PROOF_TOO_MANY_LEAVES_ERROR_CODE)
199214
);
200215
ensure!(
201216
proof_without_parachain
202217
.dip_proof
203218
.blinded
204219
.iter()
205220
.all(|l| l.len() <= MAX_DID_MERKLE_PROOF_LEAVE_SIZE.saturated_into()),
206-
DipRelaychainStateProofVerifierError::ProofComponentTooLarge(5)
221+
DipRelaychainStateProofVerifierError::ProofComponentTooLarge(DIP_PROOF_LEAF_TOO_LARGE_ERROR_CODE)
207222
);
208223
let proof_without_dip_merkle = proof_without_parachain
209224
.verify_dip_proof::<KiltRuntime::Hashing, MAX_DID_MERKLE_LEAVES_REVEALED>()

0 commit comments

Comments
 (0)