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

Add checks for try_loc, try_contribute, and try_verifier

Open apruden2008 opened this issue 4 years ago • 0 comments

When attempting to write a new contribution, the coordinator should check that contributor hasn't exceeded the maximum allowable number of locks. Also, there is no check to ensure that a given contributor holds the lock for a given chunkID.

src/api/contributor/try_lock/rs

pub fn try_lock(
    operator: State<Arc<Operator>>,
    authentication_header: AuthenticationHeader,
) -> Result<Json<ContributorLockResponse>, Status> {
    // Check that the request authenticates
    let method = "post".to_string();
    let path = format!("/v1/contributor/try_lock");

  (snip)

    // TODO (raychu86): Add an additional check that the contributor doesn't already hold the maximum
    //  number of allowed locks.

    trace!("Contributor {} attempting to lock a chunk", participant);

    // Attempt to lock the chunk for the given contributor.
    match operator.try_lock(&participant) {
        Ok((chunk_id, previous_response_locator, challenge_locator, response_locator)) => {
            // Construct the lock response
            let lock_response = ContributorLockResponse {
                chunk_id,
                locked: true,
                participant_id: participant.to_string(),
                previous_response_locator,
                challenge_locator,
                response_locator,
            };

            Ok(Json(lock_response))
        }
        Err(err) => {
            error!("Error acquiring lock for contributor: {}", err);
            Err(Status::InternalServerError)
        }
    }
}

src/api/contributor/try_contribute.rs

pub fn try_contribute(
    operator: State<Arc<Operator>>,
    authentication_header: AuthenticationHeader,
    chunk_id: u64,
) -> Result<String, Status> {

    (snip)

    // TODO (raychu86): Enforce that the contributor currently holds the lock for the chunkId.

    trace!(
        "Attempting to add a contribution with chunkID {} for participant {}",
        chunk_id,
        participant
    );

    // Attempt to add the contribution to the ceremony round
    match operator.try_contribute(&participant, chunk_id) {
        Ok(_) => Ok(json!({ "status": "ok" }).to_string()),
        Err(CoordinatorError::UnauthorizedChunkContributor) => Err(Status::Unauthorized),
        Err(CoordinatorError::ChunkNotLockedOrByWrongParticipant) => Err(Status::Unauthorized),
        Err(CoordinatorError::ChunkMissing) => Err(Status::BadRequest),
        Err(CoordinatorError::ChunkIdMismatch) => Err(Status::BadRequest),
        Err(err) => {
            error!("Error adding contribution (error {:?})", err);
            Err(Status::InternalServerError)
        }
    }
}


The same should be true of a verifier attempting to write a response, so src/api/verifier/try_verify.rs and try_lock.rs should also be modified.

apruden2008 avatar Feb 28 '21 00:02 apruden2008