[P2] Free inference exploit #554
Inference Request Processing: Security Architecture and Fix
Overview
This document explains the 2-phase inference request processing system and the security enhancement that prevents unauthorized free inference execution.
Provided exploit with a developer library that can send free inferences is provided here
Two-Phase Request Processing
Phase 1: Transfer Agent (TA) Processing
The Transfer Agent is responsible for the initial validation and routing of inference requests:
-
Balance Verification: The TA checks the requester's balance on-chain to ensure sufficient funds for the inference request.
-
On-Chain Transaction: The TA submits a
MsgStartInferencetransaction to the blockchain, which: - Records the inference request
- Escrows the required funds
-
Assigns an executor for the request
-
Request Forwarding: The TA forwards the modified request to the assigned executor, adding:
- TA address (
TransferAddress) - Prompt hash (
PromptHash) - Transfer signature (
TransferSignature) - Seed and InferenceId
Phase 2: Executor Agent (EA) Processing
The Executor Agent processes the inference request and executes it:
- Request Reception: The executor receives a request that includes:
SeedandInferenceId(added by TA)- TA signature and address
-
Original request payload
-
Trust Model: The executor trusts requests from TAs and does not re-check the requester's balance, assuming the TA has already performed this validation.
-
Execution: The executor:
- Validates the TA signature
- Executes the inference request
- Submits
MsgFinishInferenceto complete the transaction
Security Vulnerability
The Problem
The original implementation had a critical security flaw:
-
Executor Trust: The executor trusted any request that appeared to come from a TA (containing seed, InferenceId, and signature).
-
No TA Verification: The executor did not verify that the TA address (
TransferAddress) belonged to an active epoch participant. -
Exploitation Vector: An attacker could:
- Masquerade as a TA by crafting requests with a valid signature
- Send requests directly to executors, bypassing balance checks
- Execute inferences for free without proper on-chain validation
Impact
This vulnerability allowed unauthorized users to:
- Execute inference requests without proper balance verification
- Bypass the escrow mechanism
- Potentially abuse the system for free inference execution
Security Fix
Solution: Active Participant Verification
The fix adds a verification step in the executor's request validation to ensure that the TA is an active epoch participant.
Implementation
The fix is implemented in the getAllowedPubKeysForExecutorRequests function, which is called during executor request validation:
func (s *Server) getAllowedPubKeysForExecutorRequests(ctx echo.Context, granterAddress string) ([]string, error) {
if !s.isAddressActiveParticipantInCurrentEpoch(granterAddress) {
return nil, fmt.Errorf("granter is not active in the current epoch")
}
// ... rest of the function
}
Active Participant Check
The isAddressActiveParticipantInCurrentEpoch function performs a two-level verification:
-
Cache Check: First checks a cached epoch group data to quickly filter out non-participants.
-
On-Chain Verification: Queries the current epoch group data to verify:
- The address is in the
ValidationWeightslist - The participant has a non-zero weight (hasn't been marked as invalid)
This ensures that only validators who are:
- Active in the current epoch = participating in Proof of Compute (PoC) calculations
- Not marked as invalid (due to missed confirmations or inferences)
can act as Transfer Agents.
Economic Incentive Model (proposal)
The fix leverages the existing economic incentive structure:
-
Risk of Ban: Active epoch participants risk being banned if they don't properly validate requests.
-
Reward Loss: Participants who fail to check requester balances can lose all rewards for the epoch.
-
Accountability: By restricting TA functionality to active participants, the system ensures that only entities with "skin in the game" can route inference requests.
Benefits
-
Prevents Free Inference Abuse: Only active epoch participants can act as TAs, preventing unauthorized free inference execution.
-
Maintains Trust Model: The executor can still trust TA requests without re-checking balance, as TAs are now verified to be accountable participants.
-
Economic Security: The fix leverages existing economic incentives rather than adding complex technical checks.
-
Performance: The two-level check (cache + on-chain) balances security with performance.
Code Location
- Verification Function:
isAddressActiveParticipantInCurrentEpoch()(line 593) - Integration Point:
getAllowedPubKeysForExecutorRequests()(line 621) - Validation Flow:
validateFullRequest()(line 645)
Related Components
- Epoch Group Data Cache:
internal.NewEpochGroupDataCache()- Provides cached epoch participant data - Current Epoch Group Data Query:
QueryCurrentEpochGroupData()- On-chain verification of active participants - Validation Weights: Used to determine if a participant is active and has non-zero weight
💬 Comments (4)
postponing to 0.2.12+
@akup, probably, this issue could be canceled?
All inferences requests attacks are legacy and should be focused on devshards
🔄 Auto-synced from Issue #554 every hour.
potentially blocked by https://github.com/gonka-ai/gonka/pull/542, investigation is needed