Ejemplos de Código Anotado
function calculateReward(
uint256 stakedAmount,
uint256 rewardRate,
uint256 duration
) public pure returns (uint256) {
return stakedAmount * rewardRate * duration / 1e18;
}
function calculateReward(
uint256 stakedAmount, /* D18{tok} */
uint256 rewardRate, /* D27{tok/sec} — RAY precision */
uint256 duration /* D0{sec} */
) public pure returns (uint256 /* D18{tok} */) {
return stakedAmount * rewardRate * duration / 1e27; /* → D18{tok} ✓ */
}
uint256 chainlinkPrice = oracle.latestAnswer(); /* D8{UoA/tok} */
uint256 collateralValue = (amount /* D18{tok} */ * chainlinkPrice) / 1e18;
uint256 scaledPrice = chainlinkPrice * 1e10; /* D18{UoA/tok} */
uint256 collateralValue = (amount * scaledPrice) / 1e18; /* D18{UoA} ✓ */
uint256 basisPoints; /* D4{bps} — sin dimensión física, 0-10000 */
uint256 totalSupply; /* D18{tok} */
uint256 share = (amount /* D18{tok} */ * basisPoints) / totalSupply;
uint256 share = (amount * basisPoints) / (10000 * totalSupply / 1e18);
Output JSON Estructurado (Final Summary)
{
"mode": "full-auto",
"project_root": "/cultiva-defi/contracts",
"vocabulary": {
"base_units": ["tok", "wei", "UoA", "bps", "sec"],
"derived_units": ["UoA/tok", "tok/sec", "UoA/wei"],
"precision_prefixes": ["D8", "D18", "D27", "D4"]
},
"annotations": {
"total_added": 24,
"by_confidence": { "CERTAIN": 18, "INFERRED": 5, "UNCERTAIN": 1 }
},
"findings": {
"critical": 1,
"high": 2,
"medium": 1,
"false_positives_refuted": 1,
"details": [
{ "id": "DIM-001", "severity": "CRITICAL", "file": "StakingPool.sol:87", "type": "Scale Mismatch D18×D27÷1e18" },
{ "id": "DIM-002", "severity": "HIGH", "file": "PriceOracle.sol:134", "type": "Precision Loss D8→D18 missing ×1e10" },
{ "id": "DIM-003", "severity": "HIGH", "file": "RewardDistributor.sol:62", "type": "Unit Mismatch bps×D18 without ÷10000" },
{ "id": "DIM-004", "severity": "MEDIUM", "file": "StakingPool.sol:201", "type": "Precision Truncation D27→D18 in accumulator loop" }
]
},
"coverage": {
"in_scope_files": 3,
"anchor_reviewed_files": "3/3",
"propagation_reviewed_files": "3/3",
"validation_reviewed_files": "3/3",
"annotated_functions": "14/14",
"annotated_variables": "31/37",
"unprocessed_files": []
}
}