@ballkidz/defifa 0.0.11 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/AUDIT_INSTRUCTIONS.md +2 -2
  2. package/CHANGE_LOG.md +60 -5
  3. package/CRYPTO_ECON.md +505 -270
  4. package/CRYPTO_ECON.pdf +0 -0
  5. package/CRYPTO_ECON.tex +438 -241
  6. package/RISKS.md +9 -1
  7. package/SKILLS.md +3 -2
  8. package/STYLE_GUIDE.md +2 -2
  9. package/foundry.toml +1 -1
  10. package/package.json +7 -7
  11. package/script/Deploy.s.sol +1 -1
  12. package/script/helpers/DefifaDeploymentLib.sol +1 -1
  13. package/src/DefifaDeployer.sol +129 -131
  14. package/src/DefifaGovernor.sol +279 -84
  15. package/src/DefifaHook.sol +159 -172
  16. package/src/DefifaProjectOwner.sol +1 -1
  17. package/src/DefifaTokenUriResolver.sol +1 -1
  18. package/src/enums/DefifaScorecardState.sol +1 -0
  19. package/src/interfaces/IDefifaGovernor.sol +41 -2
  20. package/src/libraries/DefifaFontImporter.sol +1 -1
  21. package/src/libraries/DefifaHookLib.sol +70 -63
  22. package/src/structs/DefifaAttestations.sol +3 -3
  23. package/src/structs/DefifaLaunchProjectData.sol +1 -0
  24. package/src/structs/DefifaScorecard.sol +2 -0
  25. package/test/BWAFunctionComparison.t.sol +1320 -0
  26. package/test/DefifaAdversarialQuorum.t.sol +53 -38
  27. package/test/DefifaAuditLowGuards.t.sol +10 -6
  28. package/test/DefifaFeeAccounting.t.sol +3 -2
  29. package/test/DefifaGovernanceHardening.t.sol +1311 -0
  30. package/test/DefifaGovernor.t.sol +5 -3
  31. package/test/DefifaHookRegressions.t.sol +3 -2
  32. package/test/DefifaMintCostInvariant.t.sol +3 -2
  33. package/test/DefifaNoContest.t.sol +4 -3
  34. package/test/DefifaSecurity.t.sol +55 -42
  35. package/test/DefifaUSDC.t.sol +4 -3
  36. package/test/Fork.t.sol +12 -13
  37. package/test/SVG.t.sol +1 -1
  38. package/test/TestAuditGaps.sol +7 -5
  39. package/test/TestQALastMile.t.sol +5 -3
  40. package/test/audit/{CodexAttestationDoubleCount.t.sol → AttestationDoubleCount.t.sol} +4 -3
  41. package/test/audit/FixPendingReserveDilution.t.sol +366 -0
  42. package/test/audit/PendingReserveDilution.t.sol +298 -0
  43. package/test/audit/PendingReserveQuorumGrief.t.sol +355 -0
  44. package/test/deployScript.t.sol +1 -1
  45. package/test/regression/AttestationDelegateBeneficiary.t.sol +3 -2
  46. package/test/regression/FulfillmentBlocksRatification.t.sol +3 -2
  47. package/test/regression/GracePeriodBypass.t.sol +3 -2
@@ -421,7 +421,7 @@ forge test --match-contract DefifaMintCostInvariant -vvv
421
421
  | `initialSupply` per tier | 999,999,999 | `DefifaDeployer` |
422
422
  | Max tiers per game | 128 | `DefifaHook` (`uint256[128]`) |
423
423
  | Min grace period | 1 day | `DefifaGovernor` |
424
- | Compiler | Solidity ^0.8.26 | All files |
424
+ | Compiler | Solidity 0.8.28 | All files |
425
425
 
426
426
  ---
427
427
 
@@ -489,7 +489,7 @@ No prior formal audit with finding IDs has been conducted for defifa-collection-
489
489
 
490
490
  | Setting | Value | Source |
491
491
  |---------|-------|--------|
492
- | Solidity version | `^0.8.26` | `foundry.toml` `solc` field; all `src/*.sol` files use `pragma solidity ^0.8.26` (library uses `^0.8.17`) |
492
+ | Solidity version | `0.8.28` | `foundry.toml` `solc` field; all `src/*.sol` files use `pragma solidity ^0.8.26` (library uses `0.8.28`) |
493
493
  | EVM target | `cancun` | `foundry.toml` `evm_version` field |
494
494
  | Optimizer | Enabled, 200 runs | `foundry.toml` `optimizer_runs = 200` |
495
495
  | Via IR | `true` | `foundry.toml` `via_ir = true` -- uses the Yul-based compilation pipeline |
package/CHANGE_LOG.md CHANGED
@@ -8,7 +8,20 @@ This document describes the changes between `defifa-collection-deployer` (v5) an
8
8
  - **Dependency modernization**: Core, permission IDs, address registry, and ownable dependencies all updated to v6. New ecosystem dependencies on `croptop-core-v6` and `revnet-core-v6`.
9
9
  - **Error naming standardized**: Error names changed from bare names (e.g., `InvalidCashoutWeights`) to contract-prefixed names (e.g., `DefifaHook_InvalidCashoutWeights`).
10
10
  - **Cash out hook spec gains `noop` field**: `beforeCashOutRecordedWith` now returns `noop=false` in all specifications, ensuring the terminal always calls the hook callback.
11
- - **Game lifecycle unchanged**: The core game phases (COUNTDOWN MINT REFUND SCORING COMPLETE) and governance model (50% quorum, scorecard ratification) remain identical.
11
+ - **Compiler/tooling updated**: The v6 repo now builds and tests on Solidity `0.8.28`, matching the rest of the V6 ecosystem.
12
+ - **Game lifecycle preserved**: The core game phases (COUNTDOWN → MINT → REFUND → SCORING → COMPLETE) and governance model (50% quorum, scorecard ratification) remain the same at the product level even though the underlying hook/controller integrations changed.
13
+
14
+ ## ABI Status
15
+
16
+ This repo does have meaningful ABI migration surface. The main ABI-facing contracts for integrators are:
17
+ - `IDefifaDeployer`
18
+ - `IDefifaHook`
19
+ - `IDefifaGovernor`
20
+
21
+ The largest ABI risks are:
22
+ - inherited 721-hook/core-v6 struct and return-shape changes flowing through Defifa interfaces;
23
+ - event families now living on v6 interfaces/contracts with prefixed errors and updated dependent types;
24
+ - hook return values that now include v6 `noop`-aware hook-spec structures.
12
25
 
13
26
  ---
14
27
 
@@ -42,7 +55,8 @@ The v6 `JBCashOutHookSpecification` struct has a `noop` boolean field. `DefifaHo
42
55
 
43
56
  ### 1.4 Solidity Version
44
57
 
45
- Compiler remains at `pragma solidity 0.8.23` (not bumped to 0.8.26 unlike most other v6 repos).
58
+ - **v5:** `pragma solidity 0.8.23`
59
+ - **v6:** `pragma solidity 0.8.28`
46
60
 
47
61
  ### 1.5 721 Hook API Changes
48
62
 
@@ -52,6 +66,14 @@ Inherited from `nana-721-hook-v6`:
52
66
  - `JB721TierConfig` gained `splitPercent` and `splits` fields
53
67
  - `JB721TiersHookFlags` gained `issueTokensForSplits` field
54
68
 
69
+ ### 1.6 Function-Level Integration Changes
70
+
71
+ These are the main V6 surface changes integrators should care about:
72
+ - `beforeCashOutRecordedWith(...)` now returns a `JBCashOutHookSpecification` that includes the new `noop` field from core-v6.
73
+ - Any integration constructing or decoding `JB721TierConfig` must account for the added `splitPercent` and `splits` fields.
74
+ - Any integration reading pricing context from the inherited 721 hook must expect 2 return values, not 3.
75
+ - Defifa deployer integrations should re-check `launchGameWith(...)`, `fulfillCommitmentsOf(...)`, `triggerNoContestFor(...)`, `nextPhaseNeedsQueueing(...)`, `safetyParamsOf(...)`, and `timesFor(...)` against the v6 ABIs and dependent core-v6 structs.
76
+
55
77
  ---
56
78
 
57
79
  ## 2. Game Lifecycle (Unchanged)
@@ -89,9 +111,22 @@ DefifaHook instances are deployed as minimal proxy clones via `Clones.cloneDeter
89
111
  - One-time `initialize()` call per clone
90
112
  - Owned by DefifaGovernor for scorecard weight setting
91
113
 
114
+ ## 4. Events and Errors
115
+
116
+ The most important integration-facing patterns are:
117
+ - Errors are now consistently contract-prefixed (`DefifaHook_*`, `DefifaDeployer_*`, `DefifaGovernor_*`, `DefifaProjectOwner_*`) instead of using the older unprefixed style.
118
+ - Defifa-specific events remain centered around game launch, phase transitions, fulfillment, scoring, minting, claims, and delegation, but they now live against the V6 hook/controller stack and should be indexed using the V6 ABIs.
119
+ - `CommitmentPayoutFailed`, `LaunchGame`, `QueuedRefundPhase`, `QueuedScoringPhase`, `QueuedNoContest`, `GameInitialized`, `ScorecardSubmitted`, `ScorecardAttested`, `ScorecardRatified`, `Mint`, `MintReservedToken`, `ClaimedTokens`, and `TierCashOutWeightsSet` are the key integration events to watch across the deployer, governor, and hook.
120
+ - Other hook-level events worth indexing for governance clients are `TierDelegateAttestationsChanged` and `DelegateChanged`.
121
+
122
+ Key runtime errors now exposed by the v6 contracts include:
123
+ - `DefifaDeployer_*` errors such as `DefifaDeployer_InvalidGameConfiguration`, `DefifaDeployer_TerminalNotFound`, `DefifaDeployer_SplitsDontAddUp`, `DefifaDeployer_CantFulfillYet`, and `DefifaDeployer_NoContestAlreadyTriggered`.
124
+ - `DefifaHook_*` errors such as `DefifaHook_InvalidCashoutWeights`, `DefifaHook_InvalidTierId`, `DefifaHook_ReservedTokenMintingPaused`, `DefifaHook_TransfersPaused`, and `DefifaHook_Unauthorized(...)`.
125
+ - `DefifaGovernor_*` errors such as `DefifaGovernor_AlreadyAttested`, `DefifaGovernor_AlreadyRatified`, `DefifaGovernor_DuplicateScorecard`, `DefifaGovernor_NotAllowed`, and `DefifaGovernor_UnknownProposal`.
126
+
92
127
  ---
93
128
 
94
- ## 4. Migration Table
129
+ ## 5. Migration Table
95
130
 
96
131
  | Aspect | v5 | v6 |
97
132
  |--------|----|----|
@@ -100,8 +135,28 @@ DefifaHook instances are deployed as minimal proxy clones via `Clones.cloneDeter
100
135
  | Permission IDs | Not a direct dependency | `@bananapus/permission-ids-v6` |
101
136
  | Error naming | Bare names | Contract-prefixed names |
102
137
  | `JBCashOutHookSpecification` | No `noop` field | `noop=false` on all specs |
103
- | Solidity version | `0.8.23` | `0.8.23` (unchanged) |
138
+ | Solidity version | `0.8.23` | `0.8.28` |
104
139
  | Game lifecycle | COUNTDOWN->MINT->REFUND->SCORING->COMPLETE | Identical |
105
140
  | Governance model | 50% quorum, tier-delegated | Identical |
106
141
 
107
- > **Cross-repo impact**: Uses `nana-721-hook-v6` for all tier management and cashout weight distribution. The `nana-permission-ids-v6` ID shifts affect any hardcoded permission checks. Not yet included in `deploy-all-v6` deployment phases (awaiting source updates).
142
+ > **Cross-repo impact**: Uses `nana-721-hook-v6` for all tier management and cashout weight distribution. The `nana-permission-ids-v6` ID shifts affect any hardcoded permission checks. `deploy-all-v6` now includes Defifa as Phase 10, so canonical deployments can source Defifa addresses from the top-level rollout.
143
+
144
+ ---
145
+
146
+ ## 6. Post-Audit Fixes (Codex R2)
147
+
148
+ ### 6.1 H-1: Prevent same-block double attestation via timestamp snapshot
149
+
150
+ **File:** `DefifaGovernor.sol` -- `attestToScorecardFrom()`
151
+
152
+ Previously, attestation weight was snapshot at `_scorecard.attestationsBegin`, which could equal `block.timestamp` during the same block as a transfer. This allowed a holder to attest, transfer the NFT, and have the recipient also attest in the same block -- both counting because `upperLookup(block.timestamp)` includes same-block checkpoints.
153
+
154
+ **Fix:** Changed the snapshot to `block.timestamp - 1`, ensuring only state from before the current block is visible. Same-block transfer recipients now receive zero attestation weight.
155
+
156
+ ### 6.2 H-2: Include pending reserve NFTs in cash-out weight denominator
157
+
158
+ **File:** `DefifaHookLib.sol` -- `computeCashOutWeight()`
159
+
160
+ Previously, the cash-out weight denominator only counted actually minted tokens. Pending (unminted) reserve NFTs were excluded, allowing paid holders to cash out before reserves were minted and extract more than their fair share of the surplus.
161
+
162
+ **Fix:** Added `hookStore.numberOfPendingReservesFor()` to the denominator in `computeCashOutWeight()`. Each token's share of the tier weight is now computed against the full eventual supply (minted + pending reserves), protecting reserve holders' shares.