update validate section

This commit is contained in:
Alfredo Garcia 2021-05-04 14:48:22 -03:00 committed by Deirdre Connolly
parent a9ab401f97
commit 9a596c6b0f
1 changed files with 20 additions and 3 deletions

View File

@ -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: