Skip to content

fix(#319,#333): oracle quorum check + reserve tracker duplicate curre…#459

Open
hartz0 wants to merge 2 commits into
Pi-Defi-world:devfrom
hartz0:fix/319-333-oracle-quorum-reserve-dedup
Open

fix(#319,#333): oracle quorum check + reserve tracker duplicate curre…#459
hartz0 wants to merge 2 commits into
Pi-Defi-world:devfrom
hartz0:fix/319-333-oracle-quorum-reserve-dedup

Conversation

@hartz0

@hartz0 hartz0 commented Jul 2, 2026

Copy link
Copy Markdown

closes #319
closes #333

fix(#319, #333): oracle validator quorum check + reserve tracker duplicate currency guard

Summary

Fixes two security issues reported in issues #319 and #333.

Issue #319 — Oracle median with no quorum safety net

update_rate previously allowed 1 or 2 source feeds through as long as some sources were provided, meaning a single
potentially-malicious validator could set the median with no meaningful aggregation. The check now enforces a minimum of
max(min_signatures, MIN_ORACLE_SOURCE_FEEDS=3) sources whenever sources are provided. Passing zero sources (the existing bypass path
for direct rate submission) is unchanged.

Before:

if sources.len() > 0 && sources.len() < MIN_ORACLE_SOURCE_FEEDS {
env.panic_with_error(OracleError::InsufficientOracleSources);
}

After:

if sources.len() > 0 {
let required = min_sigs.max(MIN_ORACLE_SOURCE_FEEDS);
if sources.len() < required {
env.panic_with_error(OracleError::InsufficientOracleSources);
}
}

Issue #333 — Reserve tracker add_currency allows duplicates

add_currency pushed to a Vec without checking for duplicates. A duplicated currency entry causes iteration-based reserve lookups to
count the same reserve twice, inflating the reported total. The function now iterates the stored list before pushing and panics with
DuplicateCurrency (#8008) if the currency is already present.

Changes

  • acbu_oracle/src/lib.rs — quorum check uses max(min_signatures, 3) threshold
  • acbu_oracle/tests/test.rs — 4 new tests: too few sources panics, exactly 3 succeeds, zero sources bypasses, min_signatures >
    MIN_ORACLE_SOURCE_FEEDS enforces the larger value
  • acbu_reserve_tracker/src/lib.rs — DuplicateCurrency = 8008 error; add_currency dedup check; get_currencies getter; DataKey includes
    both last_verify_call and currencies
  • acbu_reserve_tracker/tests/test.rs — 3 new tests: add and retrieve currencies, duplicate panics with #8008, non-admin call rejected
  • docs/ERROR_CODES.md — regenerated with DuplicateCurrency = 8008

Notes

This branch is based on current dev with no merge conflicts. The old branch fix/319-333-oracle-quorum-reserve-duplicate-currency had a
DataKey conflict (both dev and that branch added a field simultaneously) and an incorrect quorum check that removed the > 0 guard, which would have broken zero-source submissions.

…ve tracker duplicate currency guard

Issue Pi-Defi-world#319 — update_rate now enforces max(min_signatures, MIN_ORACLE_SOURCE_FEEDS=3)
sources when sources are provided. A single-validator submission with < required
feeds is rejected with InsufficientOracleSources (#7009). Zero-source bypass is
preserved.

Issue Pi-Defi-world#333 — add_currency checks the stored list before push and panics with
DuplicateCurrency (#8008) on a duplicate, preventing double-counting of reserves.
Adds get_currencies() to expose the tracked list.

Also:
- Resolves DataKey merge conflict: both last_verify_call (rate-limit) and
  currencies (dedup) are present in the struct
- Adds tests for both fixes in their respective test files
- Regenerates docs/ERROR_CODES.md with DuplicateCurrency = 8008
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@hartz0, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 56 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ceed6881-2ea8-4600-8bbf-c95f5296fb98

📥 Commits

Reviewing files that changed from the base of the PR and between decb717 and c7dc1c4.

📒 Files selected for processing (5)
  • acbu_oracle/src/lib.rs
  • acbu_oracle/tests/test.rs
  • acbu_reserve_tracker/src/lib.rs
  • acbu_reserve_tracker/tests/test.rs
  • docs/ERROR_CODES.md
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

The variant was referenced in assert_currency_registered() but never declared
in the enum, causing a compile error whenever acbu_oracle is built. Adds the
variant and its Display arm, then regenerates ERROR_CODES.md.
@hartz0

hartz0 commented Jul 2, 2026

Copy link
Copy Markdown
Author

hello maintainer, please merge my pr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reserve tracker add_currency does not check for duplicate currency No check that oracle validator set size >= minimum before median calculation

1 participant