Skip to content

Dimensional scores written to chain are 100× the expected basis-points value #22

Description

@evzans

I was tracing processAuditRequested and noticed something that looks like a unit-conversion bug between the off-chain scorer and the V2 contract schema.

In sandbox/src/audit/dimensionalScoring.ts:107-113, each per-dimension score is an integer in the range 0..100:

for (const dim of ALL_DIMENSIONS) {
  const scores = dimensionScores[dim];
  if (scores.length > 0) {
    const avg = scores.reduce((sum, s) => sum + s, 0) / scores.length;
    dimensions[dim] = Math.round(avg);
  }
}

Then processAuditRequested.ts:67-74 multiplies each by 100 before writeback:

dimensionalScores = {
  security: dimScores.dimensions.security * 100,
  taskExecution: dimScores.dimensions.task_execution * 100,
  ...
};

But DimensionalScores in contracts/src/AgentAuditRegistryV2.sol:22-29 is declared as:

struct DimensionalScores {
    uint16 security;       // 0-10000 basis points
    uint16 taskExecution;
    ...
}

So a score of 100 (i.e. "100%") becomes 10000 basis points, which is the documented max — that part is fine. But a score of 100 already represents 100%; multiplying every dimension by 100 means a 47% score gets written as 4700, which the radar chart then reads back via useAgentRiskProfile and passes to RadarScoreChart whose PolarRadiusAxis domain={[0, 100]}. The radar will saturate at 100 for almost every audit.

Either:

  • the contract comment should say "0-10000 basis points" but the off-chain computation should produce 0-100 percent and have the writeback step do the ×100, and the frontend (RiskProfileCard.toRadarData) should divide by 100 before passing to the chart, or
  • the multiplication in processAuditRequested.ts should be removed and the contract field renamed to 0..100.

Right now there is no division anywhere in the frontend before the radar render. Could you clarify which side owns the unit conversion?

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions