aleo-setup icon indicating copy to clipboard operation
aleo-setup copied to clipboard

Calculate the contribution signature file size when writing object to storage

Open apruden2008 opened this issue 4 years ago • 0 comments

Method for calculating signature size uses hard-coded values. We should properly calculate these and also add error-handling

aleo-setup/phase1-coordinator/src/storage/storage.rs

impl Object {
    pub fn to_bytes(&self) -> Vec<u8> {
        match self {
            Object::CoordinatorState(state) => {
                serde_json::to_vec_pretty(state).expect("coordinator state to bytes failed")
            }
            Object::RoundHeight(height) => serde_json::to_vec(height).expect("round height to bytes failed"),
            Object::RoundState(round) => serde_json::to_vec_pretty(round).expect("round state to bytes failed"),
            Object::RoundFile(round) => round.to_vec(),
            Object::ContributionFile(contribution) => contribution.to_vec(),
            Object::ContributionFileSignature(signature) => {
                serde_json::to_vec_pretty(signature).expect("contribution file signature to bytes failed")
            }
        }
    }

    // (snip)

    /// Returns the expected file size of a contribution signature.
    pub fn contribution_file_signature_size(verified: bool) -> u64 {
        // TODO (raychu86): Calculate contribution signature file size instead of using hard coded values.
        match verified {
            true => 628,  // Json object with signature + challenge_hash + response hash + next challenge hash
            false => 471, // Json object with signature + challenge_hash + response hash
        }
    }
}

apruden2008 avatar Feb 28 '21 15:02 apruden2008