AgentDAO::_castVote doesn’t check the array of votes emitted, which determine the number of battles fought in EloCalculator.sol , allowing the user to increase the ELO of a contribution unfairly, inflating the maturity/impact of ServiceNFTs
Submitted by Jeremias, also found by oakcobalt and Shinobi
Finding description
We have this in their whitepaper:
- When validating a model, validators are presented with two models anonymously for comparison. They go through 10 rounds of interaction with each model pair, selecting the better responses. After 10 rounds, a vote is submitted with the final outcomes.
- Anonymity in model comparison prevents collusion and bias among validators and contributors, ensuring a fair model selection process.
- Virtual Protocol has opted for the Elo Rating System for model comparison.”
Other than the issue of direct on-chain transactions submitted by validators, the elo calculation system of serviceNft isn’t actually capped at 10 rounds, but receives an arbitrary amount of votes that a user directly interacting with the service can determine, both in rounds and value.
This is the AgentDAO override of the _castVote function (to be called by castVoteWithReasonAndParams). It takes params as argument. Which is an encoded uint8[] array representing the result (votes) of those rounds.
function _castVote(
uint256 proposalId,
address account,
uint8 support,
string memory reason,
bytes memory params //@audit params can also be passed as arguments
) internal override returns (uint256) {
.
.
.
if (!votedPreviously && hasVoted(proposalId, account)) {
++_totalScore;
_scores[account].push(SafeCast.toUint48(block.number), SafeCast.toUint208(scoreOf(account)) + 1);
if (params.length > 0 && support == 1) {
@> _updateMaturity(account, proposalId, weight, params); //@audit params is never checked
}
}
.
.
return weight;
}
As we saw in agentDAO::_castVote, the params are passed to the agentDAO::_updateMaturity function:
_updateMaturity passes those to _calculateMaturity, to update the “maturity” of the proposal (which should be construed as a relevant measure that weights in the final importance of implementing a new service or not, related to the ELO and weight of vote):
function _updateMaturity(address account, uint256 proposalId, uint256 weight, bytes memory params /*votes*/) internal {
.
.
.
uint8[] memory votes = abi.decode(params, (uint8[])); //@audit params has been decoded, but the length isn't checked
uint256 maturity = _calcMaturity(proposalId, votes); //@audit this calls eloCalculator (shown below)
_proposalMaturities[proposalId] += (maturity * weight); //@audit here maturity is updated, affecting ServiceNfts' elo and impact
emit ValidatorEloRating(proposalId, account, maturity, votes);
}
The issue arises in the fact that votes can be any amount of uint8[] votes that the user decided to pass as an argument.
_calcMaturity calls the eloCalculator::battleElo(maturity, votes), where votes will be the uint8[]. We can also know which elo participant is the one we vote for.
function _calcMaturity(uint256 proposalId, uint8[] memory votes) internal view returns (uint256) {
address contributionNft = IAgentNft(_agentNft).getContributionNft();
address serviceNft = IAgentNft(_agentNft).getServiceNft();
uint256 virtualId = IContributionNft(contributionNft).tokenVirtualId(proposalId);
uint8 core = IContributionNft(contributionNft).getCore(proposalId);
uint256 coreService = IServiceNft(serviceNft).getCoreService(virtualId, core);
uint256 maturity = 100;
if (coreService > 0) {
maturity = IServiceNft(serviceNft).getMaturity(coreService);
@> maturity = IEloCalculator(IAgentNft(_agentNft).getEloCalculator()).battleElo(maturity, votes);
//@audit, battleElo is called with an arbitrary amount of uint8[] votes
}
return maturity;
}
In eloCalculator::battleElo, the array of votes is used to determine the number of battles that the two elos fight, and the result of the vote determines how the ELO of each of the two participants (models) is affected. Since the ELO is affected by the amount and the result, a user could arbitrarily set both, increasing the ELO of the ServiceNft, and the proposal impact.
The function goes as follows:
function battleElo(uint256 currentRating, uint8[] memory battles) public view returns (uint256) {
uint256 eloA = 1000;
uint256 eloB = 1000;
//@audit battles is the votes params, the length of which we didn't check
for (uint256 i = 0; i < battles.length; i++) {
uint256 result = mapBattleResultToGameResult(battles[i]); //@audit function that maps vote value to result
(uint256 change, bool negative) = Elo.ratingChange(eloB, eloA, result, k);
change = _roundUp(change, 100);
if (negative) {
eloA -= change;
eloB += change;
} else {
eloA += change;
eloB -= change;
}
}
//@audit we can arbitrarily raise the ELO to make our vote more impactful in maturity
return currentRating + eloA - 1000;
}
The amount of times the change is affected to the ELO rating, is defined by that unchecked uint8[] array. Thus, allowing users to increase more than due maturity/ELO. The maturity of the proposal would be bigger than it should, and the serviceNft would also get a bigger impact than it should have.
An impact is a value calculated from the serviceNft::maturity[proposalId] (taken from agentDAO::getMaturity(proposalId) at mint call, and stored in the contract’s array), and is the difference of the current service, and the previous service maturity.
function updateImpact(uint256 virtualId, uint256 proposalId) public {
// Calculate impact
// Get current service maturity
uint256 prevServiceId = _coreServices[virtualId][_cores[proposalId]];
uint256 rawImpact = (_maturities[proposalId] > _maturities[prevServiceId])
? _maturities[proposalId] - _maturities[prevServiceId] //@audit raw-impact is the difference of maturities between proposals. An inflated votation might result in an inflated difference.
: 0;
uint256 datasetId = IContributionNft(contributionNft).getDatasetId(proposalId);
_impacts[proposalId] = rawImpact;
if (datasetId > 0) {
.
.
.
}
emit SetServiceScore(proposalId, _maturities[proposalId], _impacts[proposalId]);
}
We don’t know what the current implementation of agentReward is, but for version of v2 or lower, it would allow for an inflated reward to contributor.
function _distributeContributorRewards(
uint256 amount,
uint256 virtualId,
RewardSettingsCheckpoints.RewardSettings memory settings
) private {
IAgentNft nft = IAgentNft(agentNft);
uint8[] memory coreTypes = nft.virtualInfo(virtualId).coreTypes;
IServiceNft serviceNftContract = IServiceNft(serviceNft);
IContributionNft contributionNftContract = IContributionNft(contributionNft);
Reward storage reward = _rewards[virtualId][_rewards[virtualId].length - 1];
reward.coreAmount = amount / coreTypes.length;
uint256[] memory services = nft.getAllServices(virtualId);
// Populate service impacts
uint256 serviceId;
uint256 impact;
for (uint i = 0; i < services.length; i++) {
serviceId = services[i];
impact = serviceNftContract.getImpact(serviceId); //@audit <--here impacts are taken from serviceNft
if (impact == 0) {
continue;
}
ServiceReward storage serviceReward = _serviceRewards[serviceId];
if (serviceReward.impact == 0) {
serviceReward.impact = impact;
}
_rewardImpacts[reward.id][serviceNftContract.getCore(serviceId)] += impact; //<-- impacts are rewarded
}
Impact
Users, or even contributors can spam it, leaving the ServiceNft of a proposal with an ELO that severely misrepresents what the actual value of the proposal could be, up to the limit differences that they required in elo.sol.
Moreover, since the impact (a param of a serviceNft which represents a value of sorts for the service over the previous implementation) is used to calculate contributor rewards (at least as it is shown in AgentRewardv2.sol and AgentRewardv1.sol), this could also inflate them, giving more rewards than due.
For AgentRewardv3 we’d have to think that either it doesn’t rewards contributions, is partially used, or is unfinished. We don’t really know which one it is.
Recommended mitigation steps
Inside agentDAO::_updateMaturity add a statement after decoding the params to check that the length of the array of votes/battles is 10 (you could also replace it with a variable):
function _updateMaturity(address account, uint256 proposalId, uint256 weight, bytes memory params) internal {
address contributionNft = IAgentNft(_agentNft).getContributionNft();
address owner = IERC721(contributionNft).ownerOf(proposalId);
if (owner == address(0)) {
return;
}
bool isModel = IContributionNft(contributionNft).isModel(proposalId);
if (!isModel) {
return;
}
uint8[] memory votes = abi.decode(params, (uint8[]));
+ if(votes.length() != 10) revert();
uint256 maturity = _calcMaturity(proposalId, votes);
_proposalMaturities[proposalId] += (maturity * weight);
emit ValidatorEloRating(proposalId, account, maturity, votes);
}
Proof of Concept
- There’s a proposal for a model update.
- A user or the contributor submits a malicious (or many malicious) vote directly to the chain, with more rounds than the 10 determined in the whitepaper, either for or against the proposal.
- The ELO and the maturity increases (or decreases) more sharply with those votes.
- The resulting
serviceNftwould have really incorrect information. - The resulting maturity of the
serviceNftcould end up with an impact of 0 (or a low value) and leave contributor without (or with reduced) rewards, or it could get inflated (and give more rewards than it is fair).
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is known
A medium-severity business logic bug in Virtuals Protocol. Code4rena made it public on 4 August 2025. Found in the 2025-04-virtuals-protocol audit contest (finding M-11), also found by 2 other wardens.
About Business logic
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.