Skip to content

Commit

Permalink
chore: addressed review
Browse files Browse the repository at this point in the history
  • Loading branch information
merklefruit committed Oct 16, 2024
1 parent afdcb8b commit 40d50e5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
13 changes: 7 additions & 6 deletions crates/api/src/constraints/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use axum::{
body::{to_bytes, Body}, extract::ws::{Message, WebSocket, WebSocketUpgrade}, http::{request, Request, StatusCode}, response::{IntoResponse, Response}, Extension
};
use ethereum_consensus::{primitives::{BlsPublicKey, BlsSignature}, deneb::{verify_signed_data, Slot}, ssz};
use helix_common::{api::constraints_api::{SignableBLS, SignedDelegation, SignedRevocation, MAX_CONSTRAINTS_PER_SLOT}, bellatrix::List, chain_info::ChainInfo, proofs::{ConstraintsMessage, ConstraintsWithProofData, ProofError, SignedConstraints, SignedConstraintsWithProofData}, ConstraintSubmissionTrace};
use helix_common::{api::constraints_api::{SignableBLS, SignedDelegation, SignedRevocation, DELEGATION_ACTION, MAX_CONSTRAINTS_PER_SLOT, REVOCATION_ACTION}, bellatrix::List, chain_info::ChainInfo, proofs::{ConstraintsMessage, ConstraintsWithProofData, ProofError, SignedConstraints, SignedConstraintsWithProofData}, ConstraintSubmissionTrace};
use helix_database::DatabaseService;
use helix_datastore::Auctioneer;
use ethereum_consensus::signing::verify_signature;
Expand Down Expand Up @@ -131,9 +131,10 @@ where
// Check if the constraint pubkey is delegated to submit constraints for this validator.
// - If there are no delegations, only the validator pubkey can submit constraints
// - If there are delegations, only delegatees can submit constraints
if (delegatees.is_empty() && constraint.message.pubkey != validator_pubkey) ||
(!delegatees.is_empty() && !delegatees.contains(&constraint.message.pubkey))
{
let message_not_signed_by_validator = delegatees.is_empty() && constraint.message.pubkey != validator_pubkey;
let message_not_signed_by_delegatee = !delegatees.is_empty() && !delegatees.contains(&constraint.message.pubkey);

if message_not_signed_by_validator && message_not_signed_by_delegatee {
error!(request_id = %request_id, pubkey = %constraint.message.pubkey, "Pubkey unauthorized");
return Err(ConstraintsApiError::PubkeyNotAuthorized(constraint.message.pubkey))
}
Expand Down Expand Up @@ -202,7 +203,7 @@ where
// Decode the incoming request body into a `SignedDelegation`.
let mut signed_delegation = match serde_json::from_slice::<SignedDelegation>(&body_bytes) {
Ok(delegation) => match delegation.message.action {
0 => delegation,
DELEGATION_ACTION => delegation,
other => {
warn!(request_id = %request_id, action = other, "Invalid delegation action. expected 0");
return Err(ConstraintsApiError::InvalidDelegation)
Expand Down Expand Up @@ -277,7 +278,7 @@ where
// Decode the incoming request body into a `SignedRevocation`.
let mut signed_revocation = match serde_json::from_slice::<SignedRevocation>(&body_bytes) {
Ok(revocation ) => match revocation.message.action {
1 => revocation,
REVOCATION_ACTION => revocation,
other => {
warn!(request_id = %request_id, action = other, "Invalid revocation action. expected 1");
return Err(ConstraintsApiError::InvalidRevocation)
Expand Down
6 changes: 6 additions & 0 deletions crates/common/src/api/constraints_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ use sha2::{Digest, Sha256};

pub const MAX_CONSTRAINTS_PER_SLOT: usize = 256;

/// The action type for a delegation message.
pub const DELEGATION_ACTION: u8 = 0;

/// The action type for a revocation message.
pub const REVOCATION_ACTION: u8 = 1;

#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
pub struct SignedDelegation {
pub message: DelegationMessage,
Expand Down

0 comments on commit 40d50e5

Please sign in to comment.