@croptop/core-v6 0.0.38 → 0.0.40

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 (43) hide show
  1. package/README.md +2 -2
  2. package/foundry.toml +2 -1
  3. package/package.json +25 -13
  4. package/script/ConfigureFeeProject.s.sol +8 -5
  5. package/src/CTDeployer.sol +67 -58
  6. package/src/CTProjectOwner.sol +6 -4
  7. package/src/CTPublisher.sol +14 -4
  8. package/src/interfaces/ICTDeployer.sol +2 -2
  9. package/src/structs/CTProjectConfig.sol +7 -6
  10. package/ADMINISTRATION.md +0 -94
  11. package/ARCHITECTURE.md +0 -96
  12. package/AUDIT_INSTRUCTIONS.md +0 -88
  13. package/RISKS.md +0 -78
  14. package/SKILLS.md +0 -46
  15. package/STYLE_GUIDE.md +0 -610
  16. package/USER_JOURNEYS.md +0 -134
  17. package/foundry.lock +0 -11
  18. package/slither-ci.config.json +0 -10
  19. package/sphinx.lock +0 -507
  20. package/test/CTDeployer.t.sol +0 -616
  21. package/test/CTProjectOwner.t.sol +0 -185
  22. package/test/CTPublisher.t.sol +0 -869
  23. package/test/ClaimCollectionOwnership.t.sol +0 -315
  24. package/test/CroptopAttacks.t.sol +0 -437
  25. package/test/Fork.t.sol +0 -227
  26. package/test/TestAuditGaps.sol +0 -696
  27. package/test/Test_MetadataGeneration.t.sol +0 -79
  28. package/test/audit/CodexNemesisCroptopPublisherBoundary.t.sol +0 -329
  29. package/test/audit/CodexNemesisCurrencyPoCs.t.sol +0 -371
  30. package/test/audit/CodexNemesisFreshRound.t.sol +0 -395
  31. package/test/audit/CodexNemesisMetadataShadow.t.sol +0 -196
  32. package/test/audit/CodexNemesisPoCs.t.sol +0 -263
  33. package/test/audit/CodexNemesisPolicyReuse.t.sol +0 -168
  34. package/test/audit/CodexNemesisUriDrift.t.sol +0 -252
  35. package/test/audit/DeployerPermissionBypass.t.sol +0 -213
  36. package/test/audit/EmptyPostFeeBypass.t.sol +0 -53
  37. package/test/audit/FeeBeneficiaryReentrancy.t.sol +0 -247
  38. package/test/audit/FeeFallbackBlackhole.t.sol +0 -263
  39. package/test/audit/Pass12Fixes.t.sol +0 -388
  40. package/test/fork/PublishFork.t.sol +0 -440
  41. package/test/regression/DuplicateUriFeeEvasion.t.sol +0 -312
  42. package/test/regression/FeeEvasion.t.sol +0 -286
  43. package/test/regression/StaleTierIdMapping.t.sol +0 -228
package/ARCHITECTURE.md DELETED
@@ -1,96 +0,0 @@
1
- # Architecture
2
-
3
- ## Purpose
4
-
5
- `croptop-core-v6` turns a Juicebox project with a 721 tiers hook into a permissioned publishing market. Project owners define what posts are valid, third parties publish content by minting or reusing tiers, and Croptop routes a fixed publish fee to the canonical fee project.
6
-
7
- ## System Overview
8
-
9
- `CTPublisher` is the runtime policy and fee-routing surface. `CTDeployer` is the launch wrapper that can package a project, its 721 hook config, posting rules, and optional omnichain setup in one transaction. `CTProjectOwner` is the irreversible ownership helper for projects that want Croptop-mediated administration instead of a plain owner EOA.
10
-
11
- ## Core Invariants
12
-
13
- - A post can only be published if it satisfies the configured category, pricing, supply, split, and allowlist rules.
14
- - Publish fees must be computed from the call value, not from ambient contract balance.
15
- - `CTPublisher` must not trap fee funds. If fee-project payment fails, the fee is refunded to `_msgSender()`, and if that refund fails the publish reverts.
16
- - Tier creation and minting must still respect `nana-721-hook-v6` invariants.
17
- - `CTDeployer` intentionally creates a temporary owner-bypass period before collection ownership is claimed away from the deployer.
18
- - `CTProjectOwner` is a burn-lock primitive, not a flexible admin panel.
19
-
20
- ## Modules
21
-
22
- | Module | Responsibility | Notes |
23
- | --- | --- | --- |
24
- | `CTPublisher` | Post validation, tier reuse or creation, first-copy minting, fee routing | Main runtime contract |
25
- | `CTDeployer` | Project launch, hook wiring, optional sucker setup, wrapper behavior | Launch-time and runtime wrapper |
26
- | `CTProjectOwner` | Irreversible ownership helper | Governance-sensitive |
27
- | `CTAllowedPost`, `CTPost`, related structs | Publishing policy and request encoding | Shared config surface |
28
-
29
- ## Trust Boundaries
30
-
31
- - Tier storage and minting semantics live in `nana-721-hook-v6`.
32
- - Terminal accounting and project ownership live in `nana-core-v6`.
33
- - When omnichain setup is enabled, this repo composes patterns from `nana-suckers-v6` and `nana-omnichain-deployers-v6`.
34
-
35
- ## Critical Flows
36
-
37
- ### Publish
38
-
39
- ```text
40
- poster
41
- -> calls mintFrom(...)
42
- -> publisher validates each post against project policy
43
- -> publisher creates or reuses 721 tiers
44
- -> project terminal receives the publish payment
45
- -> fee project receives the fixed fee slice, or _msgSender() is refunded if that fee payment fails
46
- -> first copy of each post tier is minted to the poster
47
- ```
48
-
49
- ### Launch
50
-
51
- ```text
52
- creator
53
- -> CTDeployer launches the project and 721-hook shape
54
- -> configures Croptop posting rules
55
- -> optionally wires omnichain sucker deployment
56
- -> may remain in the flow as a runtime wrapper when hook composition is enabled
57
- ```
58
-
59
- ## Accounting Model
60
-
61
- This repo does not define treasury accounting. Its critical economic logic is publish-fee routing and the mapping from valid post data to tier creation or reuse.
62
-
63
- `CTPublisher` also relies on duplicate-content and pricing checks to stop fee evasion through batch composition or tier reuse.
64
-
65
- ## Security Model
66
-
67
- - Fee routing is liveness-first but still value-sensitive; fallback refunds must stay correct.
68
- - `CTDeployer` has a larger review surface than a normal deployer because it can also participate at runtime.
69
- - Croptop's product boundary is partly social: until collection ownership is claimed away from `CTDeployer`, the project owner can interact through the granted permissions rather than only through the publisher surface.
70
- - Posting-policy bugs are product-level authorization bugs, not just metadata bugs.
71
-
72
- ## Safe Change Guide
73
-
74
- - Put generic tier logic in `nana-721-hook-v6`, not here.
75
- - If fee behavior changes, review payment ordering, fee-project fallback, and refund failure handling together.
76
- - If deployer ownership or permission grants change, re-check the temporary bypass window and post-claim ownership behavior together.
77
- - If `CTDeployer` changes, test both project launch and any wrapped hook flow it participates in.
78
- - Treat `CTProjectOwner` changes as governance changes.
79
-
80
- ## Canonical Checks
81
-
82
- - publish-path fee routing and policy enforcement:
83
- `test/CTPublisher.t.sol`
84
- - fee fallback and refund safety:
85
- `test/audit/FeeFallbackBlackhole.t.sol`
86
- - duplicate-content and batch-fee-evasion resistance:
87
- `test/regression/DuplicateUriFeeEvasion.t.sol`
88
-
89
- ## Source Map
90
-
91
- - `src/CTPublisher.sol`
92
- - `src/CTDeployer.sol`
93
- - `src/CTProjectOwner.sol`
94
- - `test/CTPublisher.t.sol`
95
- - `test/audit/FeeFallbackBlackhole.t.sol`
96
- - `test/regression/DuplicateUriFeeEvasion.t.sol`
@@ -1,88 +0,0 @@
1
- # Audit Instructions
2
-
3
- Croptop is a publishing layer on top of Juicebox projects and the tiered 721 stack. Audit it as a permissions, fee-routing, and project-launch system.
4
-
5
- ## Audit Objective
6
-
7
- Find issues that:
8
-
9
- - let publishers create or mint posts outside configured criteria
10
- - let users evade Croptop fees or route them incorrectly
11
- - grant fee-free or privileged cash-outs to the wrong actors
12
- - make tier reuse bypass stale-content, fee, or policy checks
13
- - leave a project in an unintended ownership or admin state
14
-
15
- ## Scope
16
-
17
- In scope:
18
-
19
- - `src/CTPublisher.sol`
20
- - `src/CTDeployer.sol`
21
- - `src/CTProjectOwner.sol`
22
- - all interfaces in `src/interfaces/`
23
- - all structs in `src/structs/`
24
- - deployment helpers in `script/`
25
-
26
- ## Start Here
27
-
28
- 1. `src/CTPublisher.sol`
29
- 2. `src/CTDeployer.sol`
30
- 3. `src/CTProjectOwner.sol`
31
-
32
- ## Security Model
33
-
34
- Croptop composes several subsystems:
35
-
36
- - `CTPublisher` enforces posting criteria, creates or adjusts tiers, and routes fees
37
- - `CTDeployer` launches projects and wires hooks, criteria, and ownership helpers
38
- - `CTProjectOwner` lets a project follow Croptop-specific admin rules instead of a fixed EOA
39
-
40
- Trust boundaries that matter:
41
-
42
- - project owners choose policy, but should not be able to bypass the policy they configured
43
- - fee recipients and external hooks may revert or reenter
44
- - sucker-based privileges must stay limited to genuine omnichain components
45
-
46
- ## Roles And Privileges
47
-
48
- | Role | Powers | How constrained |
49
- |------|--------|-----------------|
50
- | Project owner | Choose policy and ownership mode | Must not bypass the active policy through helper paths |
51
- | `CTPublisher` | Create or reuse tiers and route fees | Must stay within configured criteria |
52
- | `CTDeployer` | Launch projects and wire helpers | Must not retain unexpected post-launch authority |
53
- | Sucker integration | Access narrow omnichain-only paths | Must be backed by authentic registry state |
54
-
55
- ## Integration Assumptions
56
-
57
- | Dependency | Assumption | What breaks if wrong |
58
- |------------|------------|----------------------|
59
- | `nana-721-hook-v6` | Tier state and tier adjustments match Croptop policy checks | Posting criteria and tier-reuse safety break |
60
- | `nana-core-v6` | Terminal and project routing are authentic | Fee routing and publish settlement drift |
61
- | `nana-ownable-v6` | Ownership helper resolves the intended admin | Projects can end up misowned or stranded |
62
- | `nana-suckers-v6` | Registry identifies genuine omnichain actors | Fee-free or privileged paths widen incorrectly |
63
-
64
- ## Critical Invariants
65
-
66
- 1. Minimum price, supply bounds, split limits, category restrictions, and allowlists stay binding on every publish path.
67
- 2. Every Croptop mint either pays the configured fee or takes the documented fallback path without underpaying Croptop.
68
- 3. Existing tiers cannot be reused in a way that revives stale criteria or dodges fee collection.
69
- 4. Sucker-only or fee-exempt paths cannot be reached through spoofed registry state or stale deployment wiring.
70
- 5. Ownership handoff and burn-lock flows do not accidentally widen privileges or strand administration.
71
-
72
- ## Attack Surfaces
73
-
74
- - publish and mint entrypoints
75
- - fee computation from user input versus onchain state
76
- - tier creation, adjustment, and reuse logic
77
- - deployer-mediated pay or cash-out data-hook behavior
78
- - permission grants during deployment and ownership transfer
79
-
80
- ## Accepted Risks Or Behaviors
81
-
82
- - Fee routing may degrade to a fallback path rather than block publishing entirely.
83
-
84
- ## Verification
85
-
86
- - `npm install`
87
- - `forge build`
88
- - `forge test`
package/RISKS.md DELETED
@@ -1,78 +0,0 @@
1
- # Croptop Core Risk Register
2
-
3
- This file focuses on the publishing, fee-routing, and hook-composition risks that matter once third parties can create NFT tiers on someone else's Juicebox project.
4
-
5
- ## How to use this file
6
-
7
- - Read `Priority risks` first.
8
- - Use the detailed sections for contract-level reasoning about posting criteria, fee routing, and deployer composition.
9
- - Treat `Accepted Behaviors` and `Invariants to Verify` as the boundary between intentional tradeoffs and defects.
10
-
11
- ## Priority risks
12
-
13
- | Priority | Risk | Why it matters | Primary controls |
14
- |----------|------|----------------|------------------|
15
- | P0 | Hook/store and terminal trust | `mintFrom` depends on hook storage and directory terminal resolution; a bad integration can misprice posts or redirect value. | Audit integration assumptions, verify hook/store pairings, and monitor terminal configuration. |
16
- | P1 | Tier ID race during concurrent posting | `_setupPosts` predicts future tier IDs before `adjustTiers`; concurrent writes can shift those IDs and break the batch. | Application-layer ordering, atomic reverts on mismatch, and operator awareness. |
17
- | P1 | Fee-path degradation without mint failure | The fee terminal is fail-open via try/catch, so publishing continues even if the fee project temporarily stops receiving revenue. | Terminal health monitoring, fallback-beneficiary handling, and explicit fee-routing checks. |
18
-
19
- ## 1. Trust Assumptions
20
-
21
- - **Trusted forwarder.** ERC-2771 `_msgSender()` is trusted in both publisher and deployer for permission checks, allowlists, and payment routing.
22
- - **CTDeployer as permanent data-hook proxy.** `CTDeployer` sets itself as the data hook for projects it deploys. `dataHookOf[projectId]` is set once and has no setter.
23
- - **Sucker registry.** `CTDeployer.beforeCashOutRecordedWith` trusts `SUCKER_REGISTRY.isSuckerOf()` for 0% tax cash outs.
24
- - **Sucker deployment is fail-open at launch time.** Launch can continue on chains where the configured sucker deployer cascade cannot complete.
25
- - **CTProjectOwner as burn target.** Projects transferred to `CTProjectOwner` cannot be recovered.
26
- - **JBDirectory / terminal resolution.** `CTPublisher.mintFrom` trusts `DIRECTORY.primaryTerminalOf()`.
27
- - **721 hook store.** `_setupPosts` trusts the hook store for tier state, removal checks, and prices.
28
-
29
- ## 2. Economic And Manipulation Risks
30
-
31
- - **Fee evasion via duplicate posts across hooks.** Duplicate-content checks are keyed per hook, so the same URI can be reused across different hooks.
32
- - **Fee calculation rounding.** Fee is `totalPrice / 20`, so integer division truncates small amounts.
33
- - **Fee is computed from `msg.value`.** Force-sent ETH does not affect the fee calculation.
34
- - **Fee terminal fallback refunds the caller.** If the fee project cannot accept the fee, Croptop refunds `_msgSender()`. Relayers or contracts that cannot receive ETH will make the mint revert.
35
- - **Split percent manipulation.** Posters can direct large shares of tier revenue away from the project if `maximumSplitPercent` is configured high.
36
-
37
- ## 3. Access Control
38
-
39
- - **Allowlist is O(n).** `_isAllowed` linearly scans the full allowlist.
40
- - **Categories cannot be disabled cleanly.** Once configured, a category can only be made impractical through stricter bounds.
41
- - **CTDeployer grants broad permissions.** Wildcard permissions to the sucker registry and publisher apply to all projects deployed by that deployer instance.
42
- - **`deployProjectFor` is permissionless for new projects.** Anyone can create a project with arbitrary owners.
43
- - **`claimCollectionOwnershipOf` only checks current NFT ownership.** After claiming, the project owner must still grant `CTPublisher` the needed tier-adjust permission or publishing stops working.
44
-
45
- ## 4. DoS Vectors
46
-
47
- - **Large batch posts.** `_setupPosts` does O(n^2) duplicate detection within a batch.
48
- - **External hook calls in loops.** Tier-store calls inside the post loop can revert or become gas-heavy.
49
- - **Terminal resolution failure.** If `DIRECTORY.primaryTerminalOf()` returns `address(0)`, payment calls revert.
50
- - **`adjustTiers` revert.** Hook-level tier rules can block the whole `mintFrom` call.
51
-
52
- ## 5. Reentrancy Surface
53
-
54
- - **`mintFrom` external call chain.** The function calls into the hook and terminals. It currently relies on local-call state isolation rather than a `ReentrancyGuard`.
55
- - **Fee payment ordering.** The fee is sent after the main payment. This is safe under the current `msg.value`-based accounting model, but future mutable storage in the publisher would make the surface riskier.
56
-
57
- ## 6. Integration Risks
58
-
59
- - **Null data-hook forwarding in deployer.** `beforePayRecordedWith` and `beforeCashOutRecordedWith` return defaults when `dataHookOf` is null.
60
- - **No hook migration path.** `dataHookOf` is written once and never updated.
61
- - **Sucker support can be absent even when requested.** A launch can complete while omnichain support is still missing.
62
- - **Tier ID prediction.** `_setupPosts` predicts new tier IDs ahead of the actual `adjustTiers` call.
63
- - **CTProjectOwner accepts any project NFT.** Accidentally transferring a non-Croptop project there still grants publisher permissions.
64
- - **Fee payment destination.** If the fee project changes terminal behavior incompatibly, mints fall back to refund or revert.
65
-
66
- ## 7. Accepted Behaviors
67
-
68
- ### 7.1 O(n^2) duplicate detection is accepted
69
-
70
- Duplicate detection within a batch is quadratic, but expected real-world batch sizes are small enough that this tradeoff is acceptable.
71
-
72
- ### 7.2 Tier ID prediction assumes no concurrent tier writes
73
-
74
- This is a known race. The mitigation is application-layer ordering and the fact that a bad prediction reverts the whole batch cleanly.
75
-
76
- ### 7.3 Project owners can bypass the publisher path while they still have direct hook permissions
77
-
78
- `CTDeployer.deployProjectFor` intentionally grants the initial owner enough hook permissions to manage the collection directly. That is part of the trust model until ownership is moved into a narrower surface.
package/SKILLS.md DELETED
@@ -1,46 +0,0 @@
1
- # Croptop Core
2
-
3
- ## Use This File For
4
-
5
- - Use this file when the task touches Croptop publishing, project deployment, data-hook forwarding, fee routing, or burn-locked ownership.
6
- - Start here, then decide whether the issue is posting-policy validation, tier reuse and content identity, deployer-packaged project shape, or burn-locked ownership.
7
-
8
- ## Read This Next
9
-
10
- | If you need... | Open this next |
11
- |---|---|
12
- | Repo overview and expected flow | [`README.md`](./README.md), [`ARCHITECTURE.md`](./ARCHITECTURE.md) |
13
- | Publishing and metadata behavior | [`src/CTPublisher.sol`](./src/CTPublisher.sol) |
14
- | Deployment and fee-project wiring | [`src/CTDeployer.sol`](./src/CTDeployer.sol), [`script/Deploy.s.sol`](./script/Deploy.s.sol), [`script/ConfigureFeeProject.s.sol`](./script/ConfigureFeeProject.s.sol) |
15
- | Ownership burn-lock behavior | [`src/CTProjectOwner.sol`](./src/CTProjectOwner.sol) |
16
- | Runtime and operational invariants | [`references/runtime.md`](./references/runtime.md), [`references/operations.md`](./references/operations.md) |
17
- | Publishing, metadata, and attack coverage | [`test/CTPublisher.t.sol`](./test/CTPublisher.t.sol), [`test/Test_MetadataGeneration.t.sol`](./test/Test_MetadataGeneration.t.sol), [`test/CroptopAttacks.t.sol`](./test/CroptopAttacks.t.sol) |
18
- | Deployment, ownership, and fork coverage | [`test/CTDeployer.t.sol`](./test/CTDeployer.t.sol), [`test/CTProjectOwner.t.sol`](./test/CTProjectOwner.t.sol), [`test/ClaimCollectionOwnership.t.sol`](./test/ClaimCollectionOwnership.t.sol), [`test/Fork.t.sol`](./test/Fork.t.sol), [`test/TestAuditGaps.sol`](./test/TestAuditGaps.sol) |
19
-
20
- ## Repo Map
21
-
22
- | Area | Where to look |
23
- |---|---|
24
- | Main contracts | [`src/`](./src/) |
25
- | Types | [`src/structs/`](./src/structs/), [`src/interfaces/`](./src/interfaces/) |
26
- | Scripts | [`script/`](./script/) |
27
- | Tests | [`test/`](./test/) |
28
-
29
- ## Purpose
30
-
31
- Permissioned publishing layer for Juicebox 721 projects. Project owners define posting rules, publishers mint content as tiers through a 721 hook, Croptop routes fees, and the deployer can package the whole project shape in one transaction.
32
-
33
- ## Reference Files
34
-
35
- - Open [`references/runtime.md`](./references/runtime.md) for publisher behavior, fee routing, data-hook forwarding, and the main invariants around posting criteria and tier reuse.
36
- - Open [`references/operations.md`](./references/operations.md) for deployer behavior, burn-lock implications, script breadcrumbs, and common stale assumptions.
37
-
38
- ## Working Rules
39
-
40
- - Start in [`src/CTPublisher.sol`](./src/CTPublisher.sol) for posting-rule and fee behavior, but check [`src/CTDeployer.sol`](./src/CTDeployer.sol) when the bug might come from project shape or hook forwarding.
41
- - Treat posting criteria, fee routing, and duplicate-content handling as treasury-sensitive and product-sensitive at the same time.
42
- - Category policy is part of the product surface. Changes to allowlists, supply bounds, or split caps change what can be published.
43
- - If the task mentions project immutability or admin recovery, inspect [`src/CTProjectOwner.sol`](./src/CTProjectOwner.sol) before changing deployer or publisher code.
44
- - Metadata bugs can be publishing bugs, resolver-shape bugs, or duplicate-content bugs. Check all three before assuming a simple formatting issue.
45
- - Duplicate-post and tier-reuse behavior are runtime semantics, not convenience logic.
46
- - When a bug looks like generic 721 issuance, confirm it is not actually in `nana-721-hook-v6`.