Skip to content

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

Open
hartz0 wants to merge 4 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 4 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
Contributor

closes #333

fix #333 : oracle validator quorum check + reserve tracker duplicate currency guard

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.

Summary by CodeRabbit

  • Bug Fixes

    • Oracle rate updates now reject non-empty submissions that do not meet the required source quorum.
    • Zero-source submissions continue to be supported as a valid path.
    • Added an explicit error for attempts to add a currency that is already being tracked.
  • Tests

    • Added coverage for insufficient, sufficient, zero-source, and higher-threshold oracle 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

📝 Walkthrough

Walkthrough

Oracle update_rate now rejects insufficient non-empty source lists while preserving zero-source updates. Oracle tests cover quorum thresholds and median behavior. The reserve tracker adds a DuplicateCurrency error variant and adjusts test-file closure structure.

Changes

Oracle quorum enforcement

Layer / File(s) Summary
Dynamic oracle source quorum validation
acbu_oracle/src/lib.rs, acbu_oracle/tests/test.rs
update_rate enforces max(min_signatures, MIN_ORACLE_SOURCE_FEEDS) for non-empty submissions. Tests cover insufficient, exact-minimum, zero-source, and higher-threshold cases.

Reserve tracker error update

Layer / File(s) Summary
Duplicate currency error declaration
acbu_reserve_tracker/src/lib.rs, acbu_reserve_tracker/tests/test.rs
ReserveTrackerError::DuplicateCurrency is added with discriminant 8008; the test file's closing brace is adjusted without changing test behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning Issue #319 is addressed, but #333 is not evidenced: the diff shows only a new error enum, not the duplicate-currency guard. Add the duplicate check in add_currency, return DuplicateCurrency for existing entries, and add regression tests.
✅ Passed checks (4 passed)
Check name Status Explanation
Out of Scope Changes check ✅ Passed The diff stays focused on the oracle quorum fix, reserve-tracker duplicate-currency work, and their tests.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the two main fixes: oracle quorum validation and duplicate currency handling in the reserve tracker.
✨ 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
Contributor Author

hello maintainer, please merge my pr

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
acbu_oracle/src/lib.rs (1)

434-455: 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Close the new guard and remove the obsolete quorum block.

The new if is never closed before the old check begins. This leaves update_rate open and makes the following pub fn items invalid nested declarations, so the crate cannot compile.

Proposed fix
         if sources.len() > 0 {
             let min_sigs: u32 = env
                 .storage()
                 .instance()
                 .get(&DATA_KEY.min_signatures)
                 .unwrap();
             let required = min_sigs.max(MIN_ORACLE_SOURCE_FEEDS);
             if sources.len() < required {
                 env.panic_with_error(OracleError::InsufficientOracleSources);
             }
-        let min_sigs: u32 = env
-            .storage()
-            .instance()
-            .get(&DATA_KEY.min_signatures)
-            .unwrap();
-        let required = min_sigs.max(MIN_ORACLE_SOURCE_FEEDS);
-        // The 0/1-source path below intentionally bypasses median/outlier
-        // aggregation, so the multi-source quorum floor only applies once
-        // there's more than one source to aggregate.
-        if sources.len() > 1 && sources.len() < required {
-            env.panic_with_error(OracleError::InsufficientOracleSources);
         }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@acbu_oracle/src/lib.rs` around lines 434 - 455, Fix update_rate by removing
the obsolete initial min-signatures/quorum block and ensuring the remaining
multi-source quorum check is properly closed before the following pub fn
declarations. Preserve the intended condition that only source counts greater
than one and below the required threshold panic with InsufficientOracleSources.
acbu_reserve_tracker/src/lib.rs (1)

24-31: 🗄️ Data Integrity & Integration | 🔴 Critical | ⚡ Quick win

Consolidate the duplicate ReserveTrackerError variants and regenerate the error catalog.

ReserveTrackerError cannot compile with duplicate variant names at acbu_reserve_tracker/src/lib.rs#L24-L31, while the docs/ERROR_CODES.md table only documents DuplicateCurrency and omits the other reserve-tracker variants added in this block.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@acbu_reserve_tracker/src/lib.rs` around lines 24 - 31, The
ReserveTrackerError definitions contain duplicate variant names and codes, and
the error catalog is incomplete. In acbu_reserve_tracker/src/lib.rs lines 24-31,
consolidate the duplicate variants while preserving one unique definition per
error and assign non-conflicting codes; then regenerate docs/ERROR_CODES.md line
192 to document every remaining reserve-tracker variant with its finalized code.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@acbu_oracle/src/lib.rs`:
- Around line 434-443: Replace the raw length-based source validation in the
surrounding oracle submission flow with uniquely identified, independently
authenticated feed or validator attestations; do not count caller-supplied i128
values as separate sources. Update the source representation and verification
logic so each attestation is authenticated and deduplicated by its
feed/validator identity before enforcing DATA_KEY.min_signatures and
MIN_ORACLE_SOURCE_FEEDS, then compute the median only from validated
attestations.

In `@acbu_oracle/tests/test.rs`:
- Line 708: Replace the broad #[should_panic] annotations at
acbu_oracle/tests/test.rs lines 708 and 803 with explicit assertions that the
insufficient-quorum tests return OracleError::InsufficientOracleSources (7009).
Use update_rate() with captured error handling or try_update_rate() assertions,
ensuring both sites validate the expected contract error rather than accepting
unrelated panics.

In `@docs/ERROR_CODES.md`:
- Line 192: Update the ReserveTrackerError code assignments to give every
variant a unique, non-overlapping code, including AttestationNotFound,
InvalidMerkleProof, InvalidCustodian, AttestationExpired, NonPositiveAmount, and
InconsistentReserve. Then regenerate docs/ERROR_CODES.md so the catalog reflects
all corrected variants and codes, including replacing the incorrect
DuplicateCurrency entry.

---

Outside diff comments:
In `@acbu_oracle/src/lib.rs`:
- Around line 434-455: Fix update_rate by removing the obsolete initial
min-signatures/quorum block and ensuring the remaining multi-source quorum check
is properly closed before the following pub fn declarations. Preserve the
intended condition that only source counts greater than one and below the
required threshold panic with InsufficientOracleSources.

In `@acbu_reserve_tracker/src/lib.rs`:
- Around line 24-31: The ReserveTrackerError definitions contain duplicate
variant names and codes, and the error catalog is incomplete. In
acbu_reserve_tracker/src/lib.rs lines 24-31, consolidate the duplicate variants
while preserving one unique definition per error and assign non-conflicting
codes; then regenerate docs/ERROR_CODES.md line 192 to document every remaining
reserve-tracker variant with its finalized code.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5eba746a-8de7-4015-a432-f0622d499ddd

📥 Commits

Reviewing files that changed from the base of the PR and between 2c278ed and 26db58c.

📒 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

Comment thread acbu_oracle/src/lib.rs
Comment thread acbu_oracle/tests/test.rs
Comment thread docs/ERROR_CODES.md Outdated
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

1 participant