[BUG]: A tiny stake takes almost the whole reward on a quiet feed

Open
#31 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
18/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
solidity
Domain
blockchain

Research direction

Read the reward payout path at src/Oracle.sol:130 and the activity/weight math at src/Oracle.sol:228-235, then run the reported reproduction with forge test --match-path test/QuietFeedReward.t.sol -vv to confirm the 1e6 wei staker draining the pool. The payload itself says the fix is a design choice (paying by share of deposits instead of decayed weight) and ties it to #30, so agree on the formula change with maintainers before editing. Done means the reproduction test passes, i.e. the tiny stake receives less than pool / 1000.

Written by the indexing model from the issue text.

Description

bug
Bug Description

Each submit pays a reward of rewardPool * w * activity / newQ (src/Oracle.sol:130 and src/Oracle.sol:228-235) where newQ is the decayed total weight plus the submitter's weight. On a quiet feed the old weight has decayed to about zero so newQ is basically just the submitter's own weight. That means whoever submits next gets close to the full reward no matter how small their stake is.

In my test a staker with 1e6 wei (about 1e-12 of the stake) waited two hours and then took 99.9% of the reward pool in one submit. Resubmitting every 12 seconds keeps paying out too. In 100 submits it took about 1.1% of a 1 ETH balance. Each submit is capped at REWARD_BPS of the balance so this drains slowly but the rewards meant for real stakers go to someone who has almost nothing at stake.

It isn't caused by tof starting at 0 for a new address. A returning staker after a quiet period gets the same full activity factor and setting tof at deposit doesn't stop the repeated submits.

This has the same root as #30. Decayed weight goes to zero on a quiet feed while deposits don't. The reward formula follows Eq. 12 in the paper so changing it is a design choice. One option is to pay by share of deposits instead of share of decayed weight.

Steps to Reproduce
  1. Fund an oracle with 1 ETH. An honest user stakes 1e18 and submits.
  2. Another user stakes 1e6 wei.
  3. Nobody submits for two hours.
  4. The 1e6 wei user submits and gets almost the whole reward pool.
Logs and Screenshots
Test I used: test/QuietFeedReward.t.sol run with forge test --match-path test/QuietFeedReward.t.sol -vv
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {Test, console2} from "lib/forge-std/src/Test.sol";
import {ERC20} from "lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
import {Oracle} from "../src/Oracle.sol";

contract Tok is ERC20 {
    constructor() ERC20("W", "W") {}

    function mint(address to, uint256 a) external {
        _mint(to, a);
    }
}

contract QuietFeedRewardTest is Test {
    function test_tinyStakeTakesTheRewardOnAQuietFeed() public {
        Tok t = new Tok();
        // halfLife 60s, q 50000, both locks 60s, rewardBps 100, gamma 0, sampleSize 5
        Oracle o = new Oracle(address(this), "Feed", "d", address(t), 60, 50_000, 60, 60, 100, 0, 5);
        vm.deal(address(o), 1 ether);
        address honest = makeAddr("honest");
        address tiny = makeAddr("tiny");
        t.mint(honest, 1e18);
        t.mint(tiny, 1e6);
        vm.startPrank(honest);
        t.approve(address(o), 1e18);
        o.depositTokens(1e18);
        vm.stopPrank();
        vm.startPrank(tiny);
        t.approve(address(o), 1e6);
        o.depositTokens(1e6);
        vm.stopPrank();

        vm.warp(vm.getBlockTimestamp() + 61);
        vm.prank(honest);
        o.submitValue(3000e18);

        // nobody submits for 2 hours
        vm.warp(vm.getBlockTimestamp() + 2 hours);
        uint256 pool = address(o).balance * 100 / 1e5;
        vm.prank(tiny);
        o.submitValue(3000e18);
        console2.log("reward pool for this submit:", pool);
        console2.log("paid to a 1e6 wei staker:   ", tiny.balance);

        // tiny holds 1e-12 of the stake so it should get about nothing
        assertLt(tiny.balance, pool / 1000, "tiny stake took most of the reward");
    }
}

Output on main 86df9c0:

Ran 1 test for test/QuietFeedReward.t.sol:QuietFeedRewardTest
[FAIL: tiny stake took most of the reward: 999489668518663 >= 999491667500] test_tinyStakeTakesTheRewardOnAQuietFeed() (gas: 2239899)
Logs:
  reward pool for this submit: 999491667500000
  paid to a 1e6 wei staker:    999489668518663
Suite result: FAILED. 0 passed; 1 failed; 0 skipped; finished in 7.02ms (3.81ms CPU time)
Environment Details

macOS with forge 1.8.7 (same as CI) and solc 0.8.33 with via_ir. Upstream main at 86df9c0. Local tests only.

Impact

Medium - Feature works but has issues

Code of Conduct
  • I have joined the Discord server and will post updates there
  • I have searched existing issues to avoid duplicates
Dominant language
Solidity
Stars
3
Forks
6
Avg merge
14h 14m
Merged PRs (30d)
5

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from StabilityNexus/OrbOracle-Solidity

All issues in StabilityNexus/OrbOracle-Solidity

Similar issues

More Blockchain issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.