11//! Evaluations API handlers
22
3+ use crate :: api:: auth:: verify_signature;
34use crate :: db:: queries;
45use crate :: models:: * ;
56use crate :: state:: AppState ;
@@ -9,12 +10,56 @@ use axum::{
910 Json ,
1011} ;
1112use std:: sync:: Arc ;
12- use tracing:: info;
13+ use tracing:: { info, warn } ;
1314
1415pub async fn submit_evaluation (
1516 State ( state) : State < Arc < AppState > > ,
1617 Json ( req) : Json < SubmitEvaluationRequest > ,
1718) -> Result < Json < serde_json:: Value > , ( StatusCode , Json < serde_json:: Value > ) > {
19+ // Verify signature - message format: "evaluation:{validator_hotkey}:{submission_id}:{agent_hash}"
20+ let message = format ! (
21+ "evaluation:{}:{}:{}" ,
22+ req. validator_hotkey, req. submission_id, req. agent_hash
23+ ) ;
24+
25+ if !verify_signature ( & req. validator_hotkey , & message, & req. signature ) {
26+ warn ! (
27+ "Invalid signature for evaluation submission from {}" ,
28+ & req. validator_hotkey[ ..16 . min( req. validator_hotkey. len( ) ) ]
29+ ) ;
30+ return Err ( (
31+ StatusCode :: UNAUTHORIZED ,
32+ Json ( serde_json:: json!( {
33+ "success" : false ,
34+ "error" : "Invalid signature"
35+ } ) ) ,
36+ ) ) ;
37+ }
38+
39+ // Verify validator is registered
40+ let validator = queries:: get_validator ( & state. db , & req. validator_hotkey )
41+ . await
42+ . map_err ( |e| {
43+ (
44+ StatusCode :: INTERNAL_SERVER_ERROR ,
45+ Json ( serde_json:: json!( { "success" : false , "error" : e. to_string( ) } ) ) ,
46+ )
47+ } ) ?;
48+
49+ if validator. is_none ( ) {
50+ warn ! (
51+ "Evaluation submission from unregistered validator: {}" ,
52+ & req. validator_hotkey[ ..16 . min( req. validator_hotkey. len( ) ) ]
53+ ) ;
54+ return Err ( (
55+ StatusCode :: UNAUTHORIZED ,
56+ Json ( serde_json:: json!( {
57+ "success" : false ,
58+ "error" : "Not a registered validator"
59+ } ) ) ,
60+ ) ) ;
61+ }
62+
1863 let evaluation = queries:: create_evaluation ( & state. db , & req)
1964 . await
2065 . map_err ( |e| {
0 commit comments