From 9a596c6b0fd5941571de54a4decd5692052adbe5 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Tue, 4 May 2021 14:48:22 -0300 Subject: [PATCH] update validate section --- rfcs/0001-messages.md | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/rfcs/0001-messages.md b/rfcs/0001-messages.md index bdac4f8..a6dd776 100644 --- a/rfcs/0001-messages.md +++ b/rfcs/0001-messages.md @@ -136,18 +136,35 @@ FROST inherit types from `jubjub` such as `Scalar`, `ExtendedPoint`, `AffinePoin ## Validation -Validation is implemented to each new data type as needed. This will ensure the creation of valid messages before they are sent. For example, in the header sender and receiver can't be the same: +Validation is implemented to each new data type as needed. This will ensure the creation of valid messages before they are sent. We create a trait for this as follows: ```rust -impl Header { - pub fn validate(&self) { +pub trait Validate { + fn validate(&self) -> &Self; +} +``` + +And we implement where needed. For example, in the header sender and receiver can't be the same: + +```rust +impl Validate for Header { + fn validate(&self) -> &Self { if self.sender.0 == self.receiver.0 { panic!("sender and receiver are the same"); } + self } } ``` +Then to create a valid `Header` we call: + +```rust +let header = Validate::validate(&Header { + .. +}).clone(); +``` + ## Testing plan - Create a happy path unit test similar to https://github.com/ZcashFoundation/redjubjub/blob/frost-messages/tests/frost.rs#L7 and: