Skip to main contentA-REX Foundation

System design · AREX-AUD-001

Audit Readiness Package

This document is what an external auditor receives on day one: scope, build instructions, invariants, threat model pointers, test coverage matrix, known limitations and the questions we want answered. It does not replace

Ready for external audit engagement
Document ID
AREX-AUD-001
Version
1.0
Date
2026-09-21
FieldValue
Document IDAREX-AUD-001
Version1.0
StatusReady for external audit engagement
Date2026-09-21
OwnerA-REX Contributors
Applies tocontracts/standard/*, contracts/reference/core/*, contracts/reference/hooks/*, contracts/reference/extensions/* at tag v2.0.0-alpha.2

1. Purpose

This document is what an external auditor receives on day one: scope, build instructions, invariants, threat model pointers, test coverage matrix, known limitations and the questions we want answered. It does not replace an audit; the audit is a stated precondition for a production anchor and for submitting the ERC.

2. Scope

ComponentFileDeployed size (bytes)In scope
Standard interfacescontracts/standard/*.sol—Yes (semantics)
Reference tokencontracts/reference/core/ARexToken.sol24,136Yes — primary
Attestation registrycontracts/reference/core/ARexAttestations.sol2,708Yes — primary
Hook basecontracts/reference/hooks/ARexHookBase.sol—Yes
EligibilityHookcontracts/reference/hooks/EligibilityHook.sol3,103Yes
ExpiryHookcontracts/reference/hooks/ExpiryHook.sol1,358Yes
AttestationHookcontracts/reference/hooks/AttestationHook.sol1,873Yes
PerishabilityHookcontracts/reference/hooks/PerishabilityHook.sol5,091Yes
SeasonalHookcontracts/reference/hooks/SeasonalHook.sol3,240Yes
DeliveryHookcontracts/reference/hooks/DeliveryHook.sol6,215Yes
TraceabilityHookcontracts/reference/hooks/TraceabilityHook.sol4,076Yes
CommodityPriceOraclecontracts/reference/extensions/CommodityPriceOracle.sol4,396Yes
CarbonImmobilizationWrappercontracts/reference/extensions/CarbonImmobilizationWrapper.sol4,588Yes
ParametricInsurancecontracts/reference/extensions/ParametricInsurance.sol3,716Yes
Test mocks**/mocks/*—No

Lines of Solidity in scope: about 2,600.

3. Build and test

4. Trust model

Role (contract)PowerExpected holder
DEFAULT_ADMIN_ROLE (token)grant/revoke roles, base URIgovernance multisig + timelock
UPGRADER_ROLE (token)replace implementation (total)governance multisig + timelock
HOOK_ADMIN_ROLE (token)add/remove/reorder rulesgovernance multisig + timelock
ENFORCER_ROLE (token)freeze any amount, force any transferenforcement multisig with documented procedure
PAUSER_ROLE (token)halt all but forced transfersincident response key
ISSUER_ROLE, STATUS_ROLE, TRANSFORMER_ROLE (token)create lots; change status/metadata; processoperational services, least privilege
ATTEST_ADMIN_ROLE (attestations)trusted issuers; admin revokecertification authority / platform
MANAGER_ROLE (hooks)rule parametersper hook owner
ARBITER_ROLE, SENSOR_ROLE (DeliveryHook)disputes; readingsarbitration provider; IoT gateway
REPORTER_ROLE, MANAGER_ROLE (oracle)price submissions; parametersdata providers
REGISTRAR_ROLE (carbon)immobilisation recordsparty with registry account
UNDERWRITER_ROLE (insurance)issue policiesinsurer

Hooks are trusted code: a hook can block all transfers. Registration verifies ERC-165 and non-zero flags only.

5. Invariants (with tests)

IDInvariantEnforced byTest
INV-1Σ balances(id) == totalSupply(id)ERC1155Supply, _updateInvariants.test.js I1; lineage tests
INV-2status 255 never changes againsetBatchStatusInvariants.test.js I2; status tests
INV-3retired: no mint/transfer, burn allowed_updateretired-batch test
INV-4holder moves ≤ balance − frozen_updatefreeze tests; I5
INV-5no re-entrance during hook sequencestorage lockReentrantHook test
INV-6hooks evaluated in order; removal preserves orderarray shiftordering test
INV-7rejection ⇒ no balance change, no onExecutedchecks before super._updaterejection test
INV-8canTransfer ⇔ transfer succeeds (balance sufficient)definitionInvariants.test.js I3
INV-9forced transfer leaves frozen ≤ remaining balanceforcedTransferforced tests
INV-10authority never from balancerole gates"holding grants nothing" tests
INV-11DeliveryHook: lockedUnits ≤ balance at schedule; settlement unlocks exactly amountschedule/onExecuteddelivery tests
INV-12Oracle: round ids strictly increase; answer = median of submissionssubmit/_finalizeoracle test
INV-13Carbon: linked + retired ≤ tonneslinkToBatch/retirecarbon test
INV-14Insurance: reserved ≤ pool balance at issuance; claim onceissue/claiminsurance test

6. Threat model pointers

See whitepaper chapter Security Framework and docs/SYSTEM-DESIGN.md §9 for actors, capabilities and scenarios (malicious hook, hook re-entrance, compromised enforcement or upgrader key, status abuse, issuer fraud, metadata substitution, pre-flight staleness, gas griefing, upgradeable hook trust).

7. Test coverage matrix

AreaFileTests
Batches, lineage, ERC-7943, pipeline, attestations, conformance, upgrade, view/transaction ordertest/standard/ARexToken.test.js31
Perishability, seasonal, delivery, traceability, sanctions TTLtest/standard/DomainHooks.test.js8
Price oracle, carbon wrapper, insurancetest/standard/Extensions.test.js3
Randomized invariantstest/standard/Invariants.test.js1 (120 steps default; configurable)
Implementation Guide and documentation examples, executedtest/standard/ImplementationGuide.test.js3

8. Known limitations and open questions for the auditor

  1. Data stash in storage. safeTransferFrom writes data to storage for hook consumption and deletes it afterwards. Cost is proportional to data length; no security impact identified. Confirm no path leaves opData populated.
  2. currentOp context. forcedTransfer and transform set a storage flag consumed by _update. Confirm no re-entrant path could observe a stale flag (the lock should prevent it).
  3. _isRebatch gating. A holder can transform without a role when commodity/unit are equal and quantities are conserved. Confirm this cannot be abused to launder a batch's identity (issuer becomes the operator; parents are recorded).
  4. Hook DoS. A hook that reverts blocks the token until removed. Accepted by design; confirm removeHook and pause are always reachable.
  5. ERC-1155 receiver callback runs after the lock is released (standard behaviour). Confirm state is final before the callback.
  6. DeliveryHook relies on data == abi.encode(deliveryId) for settlement. Confirm a third party cannot craft a settlement for someone else's delivery (sender/receiver/amount/batch must match).
  7. PerishabilityHook exponential approximation interpolates linearly within a half-life; check monotonicity.
  8. Oracle median uses insertion sort bounded by reporter count; confirm no unbounded growth (_values per round).
  9. Upgrade safety: ERC-7201 struct is append-only; confirm no inherited OpenZeppelin storage collisions (validated by the upgrades plugin in tests).

9. Out of scope

Off-chain metadata availability; the identity provider behind eligibility; the legal classification of any offering; the physical existence of goods.

10. Deliverables expected from the audit

Findings with severity and reproduction; confirmation or refutation of each invariant; an opinion on §8; a re-audit of fixes. Publication of the final report is a condition of the engagement.