Skip to content

Commit e5fb7dc

Browse files
committed
chore(agent): add signer recovery
1 parent c0804cf commit e5fb7dc

File tree

1 file changed

+52
-7
lines changed

1 file changed

+52
-7
lines changed

crates/tap-agent/src/agent/sender_allocation_task.rs

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ use super::{
1919
unaggregated_receipts::UnaggregatedReceipts,
2020
};
2121
use crate::{
22-
tap::context::{NetworkVersion, TapAgentContext},
22+
tap::{
23+
context::{NetworkVersion, TapAgentContext},
24+
CheckingReceipt,
25+
},
2326
task_lifecycle::{LifecycleManager, RestartPolicy, TaskHandle},
2427
};
2528
use indexer_receipt::TapReceipt;
@@ -85,6 +88,9 @@ struct TaskState<T: NetworkVersion> {
8588
/// Aggregator client for signing RAVs
8689
#[allow(dead_code)]
8790
sender_aggregator: T::AggregatorClient,
91+
/// EIP-712 domain separator for signature recovery
92+
#[allow(dead_code)]
93+
domain_separator: thegraph_core::alloy::sol_types::Eip712Domain,
8894
}
8995

9096
/// Different types of operations that can fail and need retry logic
@@ -314,6 +320,7 @@ where
314320
sender,
315321
indexer_address,
316322
sender_aggregator,
323+
domain_separator: thegraph_core::alloy::sol_types::Eip712Domain::default(), // TODO: Get real domain separator
317324
};
318325

319326
lifecycle
@@ -842,9 +849,28 @@ where
842849
// Extract receipt details based on version
843850
match receipt {
844851
TapReceipt::V1(v1_receipt) => {
845-
// For V1, we'll store the signer from the notification or use a placeholder
846-
// In a real implementation, we'd recover the signer using domain separator
847-
let signer = Address::ZERO; // TODO: Get actual signer from notification
852+
// Recover the actual signer address from the V1 receipt signature
853+
let signer = match CheckingReceipt::new(TapReceipt::V1(v1_receipt.clone()))
854+
.signed_receipt()
855+
.recover_signer(&state.domain_separator)
856+
{
857+
Ok(recovered_signer) => {
858+
tracing::debug!(
859+
signer = %recovered_signer,
860+
allocation_id = %v1_receipt.message.allocation_id,
861+
"Successfully recovered signer from V1 receipt signature"
862+
);
863+
recovered_signer
864+
}
865+
Err(e) => {
866+
tracing::warn!(
867+
error = %e,
868+
allocation_id = %v1_receipt.message.allocation_id,
869+
"Failed to recover signer from V1 receipt signature, using zero address"
870+
);
871+
Address::ZERO
872+
}
873+
};
848874
signer_addresses.push(signer.encode_hex());
849875
signatures.push(v1_receipt.signature.as_bytes().to_vec());
850876
allocation_ids.push(v1_receipt.message.allocation_id.encode_hex());
@@ -854,9 +880,28 @@ where
854880
error_logs.push(error_message.clone());
855881
}
856882
TapReceipt::V2(v2_receipt) => {
857-
// For V2, we'll store the signer from the notification or use a placeholder
858-
// In a real implementation, we'd recover the signer using domain separator
859-
let signer = Address::ZERO; // TODO: Get actual signer from notification
883+
// Recover the actual signer address from the V2 receipt signature
884+
let signer = match CheckingReceipt::new(TapReceipt::V2(v2_receipt.clone()))
885+
.signed_receipt()
886+
.recover_signer(&state.domain_separator)
887+
{
888+
Ok(recovered_signer) => {
889+
tracing::debug!(
890+
signer = %recovered_signer,
891+
collection_id = %v2_receipt.message.collection_id,
892+
"Successfully recovered signer from V2 receipt signature"
893+
);
894+
recovered_signer
895+
}
896+
Err(e) => {
897+
tracing::warn!(
898+
error = %e,
899+
collection_id = %v2_receipt.message.collection_id,
900+
"Failed to recover signer from V2 receipt signature, using zero address"
901+
);
902+
Address::ZERO
903+
}
904+
};
860905
signer_addresses.push(signer.encode_hex());
861906
signatures.push(v2_receipt.signature.as_bytes().to_vec());
862907
// For V2, we need the collection_id from the message

0 commit comments

Comments
 (0)