[BUG]: Two submits in one block list the same timestamp twice and lose the first price
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 72/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- solidity
- Ambito
- blockchain
Direzione di ricerca
Inizia da submitValue in src/Oracle.sol intorno alla riga 140, dove priceTimestamps.push(nowTs) viene eseguito incondizionatamente mentre i prezzi sono memorizzati in mapping indicizzati per timestamp; leggi poi getPriceHistoryRange e getPriceHistoryLength per vedere come vengono consumati gli array. Metti la riproduzione in test/SameBlockHistory.t.sol ed esegui forge test --match-path test/SameBlockHistory.t.sol -vv per confermare l'output duplicato 62/62 sul main attuale. Scegli una correzione (saltare il push quando l'ultimo timestamp corrisponde, oppure spostare la cronologia in un array di struct) e verifica che ogni lettore degli array di cronologia compili ancora; fatto è che quel test passa senza timestamp duplicati e con il valore del primo submit preservato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- Solidity
- Stelle
- 3
- Fork
- 6
- Merge medio
- 14h 14m
- PR unite (30g)
- 5
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di StabilityNexus/OrbOracle-Solidity
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
-
[BUG]: Oracle with rewardBps above 1e5 can never accept a funded price submissionForse già presa @kansalakshat l’ha presa 10 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
StabilityNexus/OrbOracle-Solidity#27 · 1 commento ·
-
bug
Difficoltà 5/5 Più di una settimana Idoneità per principianti 18/100
-
bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
StabilityNexus/OrbOracle-Solidity#30 · 1 commento ·
-
[BUG]: Old prices stay in the feed after someone resubmits (decay is not multiplicative)Forse già presa @Deepak-negi11 l’ha presa 15 giorni fa. Apertabug
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
StabilityNexus/OrbOracle-Solidity#25 · 1 commento ·
Tutte le issue di StabilityNexus/OrbOracle-Solidity
Issue simili
-
eth_get_proof reports another account's fields for an absent accountForse già presa @Indian-boult l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
bug good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
eth_blobBaseFee should return the blob base fee of the next blockForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
ethereum/go-ethereum#36196 ·
I maintainer di solito rispondono entro 3 giorni
-
bug Contract security
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
DogStark/PetChain-Contracts#1644 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
solana-foundation/solana-web3.js#4081 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno