Skip to content

security: [T1-08] add regtest-only runtime guards to MockOracleManager (DGB-SEC-005)#377

Merged
JaredTate merged 8 commits intofeature/digidollar-v1from
fix/digidollar-sec-005-mock-oracle-guard
Feb 13, 2026
Merged

security: [T1-08] add regtest-only runtime guards to MockOracleManager (DGB-SEC-005)#377
JaredTate merged 8 commits intofeature/digidollar-v1from
fix/digidollar-sec-005-mock-oracle-guard

Conversation

@gto90
Copy link
Member

@gto90 gto90 commented Feb 13, 2026

Summary

  • DGB-SEC-005: MockOracleManager::GetCurrentPrice() was called in validation.cpp without a REGTEST chain-type check — mock prices could leak into consensus on mainnet/testnet
  • Fix adds a REGTEST guard at the call site in validation.cpp
  • Defense-in-depth: GetCurrentPrice() and SetMockPrice() now reject calls on non-REGTEST networks internally

Test plan

  • Verify mock oracle still works in REGTEST mode (setmockoracleprice RPC)
  • Verify GetCurrentPrice() returns 0 on non-REGTEST
  • Run test_digibyte --run_test=digidollar_dca_tests

…r (DGB-SEC-005)

MockOracleManager::GetCurrentPrice() was called without a REGTEST
check in validation.cpp, meaning mock oracle prices could leak into
consensus code on mainnet/testnet if the singleton was instantiated.

Fix adds guards at two layers:
- validation.cpp: gate mock oracle access behind REGTEST chain check
- MockOracleManager: GetCurrentPrice() and SetMockPrice() now reject
  calls on non-REGTEST networks as defense-in-depth
Copilot AI review requested due to automatic review settings February 13, 2026 03:16
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request addresses a security vulnerability (DGB-SEC-005) where the MockOracleManager::GetCurrentPrice() function could potentially be called on non-REGTEST networks, allowing mock prices to leak into consensus validation on mainnet/testnet. The fix implements defense-in-depth by adding both call-site guards and internal runtime checks.

Changes:

  • Added REGTEST guard at the call site in validation.cpp for GetOraclePriceForTransaction()
  • Added internal runtime guards in MockOracleManager::GetCurrentPrice() and SetMockPrice() to reject calls on non-REGTEST networks
  • Updated code comments to clarify security implications

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/validation.cpp Added ChainType::REGTEST check before accessing MockOracleManager in GetOraclePriceForTransaction()
src/oracle/mock_oracle.cpp Added internal runtime guards to reject GetCurrentPrice() and SetMockPrice() calls on non-REGTEST networks

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

OpenSSL 1.1.1w Configure misparses multi-word flags like "-arch arm64"
when passed as positional args — the shell splits them and Configure
treats the second word as a target name, causing "target already
defined" on ARM64 macOS. Pass CFLAGS/CPPFLAGS as VAR=value assignments
per OpenSSL's official INSTALL docs.

libcurl 8.5.0 fopen.c uses fileno/fdopen (POSIX) which are hidden by
the depends system's strict -std=c11. Add -D_GNU_SOURCE for Linux.
Use $$ deferred evaluation for CFLAGS/CPPFLAGS assignments so
OS-specific flags (cflags_linux, cppflags_linux) appended by funcs.mk
after set_vars are included. Route -fPIC and -D_GNU_SOURCE through
proper cflags/cppflags variables instead of bare config_opts to avoid
OpenSSL's "Mixing make variables" rejection.
The depends system never defines $(package)_arflags, so
ARFLAGS=$($(package)_arflags) in config_env exported an empty
ARFLAGS="" to the environment. When CFLAGS/CPPFLAGS are passed
as VAR=value assignments (not positional flags), OpenSSL 1.1.1w's
Configure sets $anyuseradd=false and falls back to reading env
vars. The empty ARFLAGS overrides the target default "r" from
Configurations/00-base-templates.conf, producing a Makefile with
ARFLAGS= (empty). This causes "ar: two different operation options
specified" on Linux and "ar: illegal option -- /" on macOS during
build_libs, as ar interprets the archive path as flags.

Fix: remove ARFLAGS from config_env entirely, letting Configure
use its target default ARFLAGS="r".

Verified locally:
- Linux x86_64: ar r apps/libapps.a ... (ARFLAGS=r in Makefile)
- macOS ARM64: ar r apps/libapps.a ... (ARFLAGS=r in Makefile)
- Full build_libs completes successfully on darwin64-arm64-cc
Replace BOOST_CHECK with BOOST_CHECK_MESSAGE in 5 mint validation
tests that fail on CI but pass locally. Diagnostic output captures
the exact reject reason, script sizes, collateral amounts, and
script type identification to help debug the CI-specific failure.
Replace ClearFreeze() with ClearHistory() in the validation test
fixture. ClearFreeze() only clears freeze flags, but UpdateState()
(called during ValidateDigiDollarTransaction) recalculates volatility
from stale price history left by earlier test suites (e.g.,
digidollar_health_tests) and re-sets the freeze. This caused all
"valid mint" tests to fail with "minting-frozen-volatility" on CI
where the test suite ordering (linker-dependent) places health_tests
before validation_tests.

ClearHistory() resets price history, volatility state, and all freeze
flags, ensuring each test starts from a clean state.
The merge with feature/digidollar-v1 silently dropped critical code:

1. DD amount double-counting prevention in ValidateMintTransaction()
   The OP_RETURN and DD token output both encode ddAmount. Without the
   consistency check, totalDD was counted twice (e.g. 10000 + 10000 =
   20000), requiring 2x the collateral and failing all valid mint tests.

2. Missing #include <digidollar/health.h>

3. Improved log format for insufficient-collateral diagnostic

Also adopts the base branch's test file which includes:
- DD OP_RETURN outputs required for T1-04b NUMS verification
- Proper NUMS key usage via GetCollateralNUMSKey()
- ClearHistory() fix for cross-suite volatility state pollution
@DigiSwarm
Copy link

Reviewed and merged manually into feature/digidollar-v1 (commit c089d99fce).

What was applied:

  1. mock_oracle.cpp GetCurrentPrice() — Added Params().GetChainType() != ChainType::REGTEST runtime guard. Returns 0 on non-REGTEST networks.
  2. mock_oracle.cpp SetMockPrice() — Same REGTEST guard with LogPrintf security warning on rejection.
  3. validation.cpp GetOraclePriceForTransaction() — Added Params().GetChainType() == ChainType::REGTEST check before calling MockOracleManager::GetInstance().IsEnabled().

Defense-in-depth: even though MockOracleManager was only called behind REGTEST checks in err.cpp, these internal guards ensure mock prices can never leak into consensus on mainnet/testnet regardless of future call sites.

What was NOT applied:

  • Test file changes (digidollar_validation_tests.cpp) — already resolved differently
  • Build system changes — unrelated

Verification:

  • All 1740 unit tests pass ✅
  • Full build clean ✅

Closing as manually merged. Good defense-in-depth @gto90.

@DigiSwarm DigiSwarm closed this Feb 13, 2026
@DigiSwarm DigiSwarm reopened this Feb 13, 2026
@JaredTate JaredTate merged commit 310ede1 into feature/digidollar-v1 Feb 13, 2026
@gto90 gto90 deleted the fix/digidollar-sec-005-mock-oracle-guard branch February 14, 2026 18:18
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.

3 participants