Skip to content

[AUD-002][Critical] Fix MRAC state-error indexing for non-square dimensions #302

Description

@gabrielsantosphilips

Audit finding

  • ID: AUD-002
  • Status: Verified defect
  • Severity: Critical
  • Confidence: High
  • Audited revision: 2f479320d805a1f9f35ebe4afaaeeded48913a94

Problem

ModelReferenceAdaptiveControl::ComputeControl() loops over InputSize but indexes e.at(i, 0) where e has StateSize rows. A valid ModelReferenceAdaptiveControl<float, 1, 2> aborts on the second input; without bounds assertions this is undefined memory access. When InputSize < StateSize, state-error components are silently ignored.

Source:

const StateVector& x, const InputVector& r, T dt)
{
xm = xm + (reference.A * xm + reference.B * r) * dt;
const StateVector e{ x - xm };
const InputVector u{ thetaX * x + thetaR * r };
const T scale{ gamma * signB * dt };
for (std::size_t i = 0; i < InputSize; ++i)
{
for (std::size_t j = 0; j < StateSize; ++j)
thetaX.at(i, j) -= scale * e.at(i, 0) * x.at(j, 0);
for (std::size_t j = 0; j < InputSize; ++j)
thetaR.at(i, j) -= scale * e.at(i, 0) * r.at(j, 0);
}

The current update is also not a dimensionally general MIMO Lyapunov law; it needs an adaptation direction such as B^T P e, rather than the first input-count error entries. AdaptationLaw is stored but not used.

Acceptance criteria

  • No state vector is indexed using InputSize unless dimensions guarantee safety.
  • The supported MIMO adaptation law is mathematically specified and dimensionally valid.
  • Unsupported dimension/law combinations fail at compile time or construction.
  • Add float-only TEST_F cases for InputSize > StateSize and InputSize < StateSize.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions