[BUG]: Two submits in one block list the same timestamp twice and lose the first price
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- solidity
- Domain
- blockchain
Research direction
Start at submitValue in src/Oracle.sol around line 140, where priceTimestamps.push(nowTs) runs unconditionally while prices are stored in timestamp-keyed mappings; read getPriceHistoryRange and getPriceHistoryLength next to see how the arrays are consumed. Drop the reproduction into test/SameBlockHistory.t.sol and run forge test --match-path test/SameBlockHistory.t.sol -vv to confirm the duplicate 62/62 output on the current main. Pick one fix (skip the push when the last timestamp matches, or move history to an array of structs) and check every reader of the history arrays still compiles; done is that test passing with no duplicate timestamps and the first submit's value preserved.
Written by the indexing model from the issue text.
Description
Bug Description
submitValue always does priceTimestamps.push(nowTs) but stores the prices in mappings keyed by timestamp (src/Oracle.sol:140). When two submits land in the same block the timestamp gets pushed twice and the second submit overwrites the first one's prices. So getPriceHistoryRange returns the same timestamp twice with the second values both times and the first submitted value is gone.
Nothing breaks on chain but anyone reading the history off chain gets duplicate points and a missing price. A fix could skip the push when the last timestamp is the same or store the history as an array of structs.
Steps to Reproduce
- Two users stake and wait out the deposit lock.
- Both submit in the same block (3000e18 and then 3100e18).
getPriceHistoryRange(0, 2)returns timestamp 62 twice and the 3000e18 submit is not there.
Logs and Screenshots
Test I used: test/SameBlockHistory.t.sol run with forge test --match-path test/SameBlockHistory.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 SameBlockHistoryTest is Test {
function test_twoSubmitsInOneBlock() public {
Tok t = new Tok();
Oracle o = new Oracle(address(this), "Feed", "d", address(t), 60, 50_000, 60, 60, 100, 0, 5);
address a = makeAddr("a");
address b = makeAddr("b");
t.mint(a, 1e18);
t.mint(b, 1e18);
vm.startPrank(a);
t.approve(address(o), 1e18);
o.depositTokens(1e18);
vm.stopPrank();
vm.startPrank(b);
t.approve(address(o), 1e18);
o.depositTokens(1e18);
vm.stopPrank();
vm.warp(vm.getBlockTimestamp() + 61);
vm.prank(a);
o.submitValue(3000e18);
vm.prank(b);
o.submitValue(3100e18); // same block
uint256 n = o.getPriceHistoryLength();
(uint256[] memory ts, uint256[] memory agg, uint256[] memory latest) = o.getPriceHistoryRange(0, n);
for (uint256 i = 0; i < n; i++) {
console2.log(ts[i], agg[i], latest[i]);
}
assertFalse(n == 2 && ts[0] == ts[1], "same timestamp listed twice");
}
}
Output on main 86df9c0:
Ran 1 test for test/SameBlockHistory.t.sol:SameBlockHistoryTest
[FAIL: same timestamp listed twice] test_twoSubmitsInOneBlock() (gas: 2147292)
Logs:
62 3050000000000000000000 3100000000000000000000
62 3050000000000000000000 3100000000000000000000
Suite result: FAILED. 0 passed; 1 failed; 0 skipped; finished in 1.08ms (821.33µs 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
Low - Minor inconvenience
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
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from StabilityNexus/OrbOracle-Solidity
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
-
[BUG]: Oracle with rewardBps above 1e5 can never accept a funded price submissionPossibly taken @kansalakshat claimed this 10 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
StabilityNexus/OrbOracle-Solidity#27 · 1 comment ·
-
bug
Difficulty 5/5 Over a week Newbie friendliness 18/100
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 35/100
StabilityNexus/OrbOracle-Solidity#30 · 1 comment ·
-
[BUG]: Old prices stay in the feed after someone resubmits (decay is not multiplicative)Possibly taken @Deepak-negi11 claimed this 15 days ago. Openbug
Difficulty 5/5 Over a week Newbie friendliness 35/100
StabilityNexus/OrbOracle-Solidity#25 · 1 comment ·
All issues in StabilityNexus/OrbOracle-Solidity
Similar issues
-
eth_get_proof reports another account's fields for an absent accountPossibly taken @Indian-boult claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
bug good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
eth_blobBaseFee should return the blob base fee of the next blockPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
ethereum/go-ethereum#36196 ·
Maintainers usually reply within 3 days
-
bug Contract security
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
DogStark/PetChain-Contracts#1644 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
solana-foundation/solana-web3.js#4081 · 1 comment ·
Maintainers usually reply within 1 day