@rev-net/core-v6 0.0.32 → 0.0.34

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.
@@ -1,144 +1,90 @@
1
1
  # Audit Instructions
2
2
 
3
- Revnets are autonomous Juicebox projects with staged economics and token-collateralized loans. Audit this repo as both a privileged deployer layer and a live economic system.
3
+ Revnet is a staged, owner-minimized product layer on top of Juicebox core. Audit it as an economic system, not just a deployer plus a loan contract.
4
4
 
5
- ## Objective
5
+ ## Audit Objective
6
6
 
7
7
  Find issues that:
8
- - let a participant borrow more than intended against revnet collateral
9
- - break stage transitions or immutable revnet economics
10
- - mis-scale weights, fees, or split behavior in composed payment flows
11
- - grant owner-like or operator-like powers outside the documented model
12
- - leave deployed revnets or loans in states that cannot settle safely
8
+
9
+ - break stage progression or let users act under the wrong stage assumptions
10
+ - overstate or understate borrowability
11
+ - mis-handle hidden tokens or burned-collateral accounting
12
+ - give operators or integrations more power than the revnet model intends
13
+ - make omnichain supply, surplus, or sucker assumptions drift from runtime behavior
13
14
 
14
15
  ## Scope
15
16
 
16
17
  In scope:
18
+
17
19
  - `src/REVDeployer.sol`
18
20
  - `src/REVOwner.sol`
19
21
  - `src/REVLoans.sol`
20
22
  - `src/REVHiddenTokens.sol`
21
- - `src/interfaces/`
22
- - `src/structs/`
23
- - deployment scripts in `script/`
24
-
25
- Key dependencies:
26
- - `nana-core-v6`
27
- - `nana-721-hook-v6`
28
- - `nana-buyback-hook-v6`
29
- - `nana-suckers-v6`
30
- - `croptop-core-v6`
23
+ - structs, interfaces, and deployment helpers
31
24
 
32
25
  ## Start Here
33
26
 
34
- Read in this order:
35
- - `REVOwner`
36
- - `REVDeployer`
37
- - `REVLoans`
38
-
39
- `REVOwner` is the fastest way to understand how a live revnet differs from plain Juicebox behavior.
40
- `REVDeployer` explains why that behavior exists.
41
- `REVLoans` is where those economics are turned into extractable collateral value.
27
+ 1. `src/REVDeployer.sol`
28
+ 2. `src/REVOwner.sol`
29
+ 3. `src/REVLoans.sol`
30
+ 4. `src/REVHiddenTokens.sol`
42
31
 
43
- ## System Model
32
+ ## Security Model
44
33
 
45
- The repo splits responsibilities:
46
- - `REVDeployer`: launches revnets, encodes stage configs, manages optional 721 and sucker composition
47
- - `REVOwner`: runtime data/cash-out hook used by deployed revnets
48
- - `REVLoans`: loan system that burns collateral on borrow and re-mints on repayment
49
- - `REVHiddenTokens`: temporary token hiding that burns tokens to exclude from totalSupply and re-mints on reveal
50
-
51
- Important composition behavior:
52
- - revnet payments may be proxied through 721 and buyback hooks
53
- - cash-out behavior may be altered for suckers or by revnet-specific fee handling
54
- - loan health depends on bonding-curve value and surplus, so core accounting and stage timing directly matter
55
-
56
- Two mental models help here:
57
- - `REVDeployer` is mostly a launch-time authority that permanently shapes economics
58
- - `REVOwner` is a runtime hook that can make a launched revnet behave very differently from a plain Juicebox project
59
-
60
- ## Critical Invariants
34
+ Revnet composes several sensitive systems:
61
35
 
62
- 1. Stage immutability
63
- Once a revnet is launched, future stage economics must follow the encoded schedule and not become mutable through helper paths.
36
+ - staged rulesets and launch-time immutability
37
+ - runtime pay and cash-out policy in `REVOwner`
38
+ - burned-collateral lending in `REVLoans`
39
+ - hidden-token supply exclusion in `REVHiddenTokens`
64
40
 
65
- 2. Payment accounting is scaled correctly
66
- If only part of a payment enters the treasury because of split or hook routing, token issuance must reflect only that treasury-entering portion.
41
+ The main audit mindset is composition:
67
42
 
68
- 3. Loan collateralization is sound
69
- Borrow, repay, refinance, and liquidation paths must never let a borrower extract more value than the design permits.
43
+ - stage economics affect borrowability
44
+ - hidden supply affects cash-out math
45
+ - omnichain state can affect reclaim and borrowing power
46
+ - optional integrations can widen the effective trust surface
70
47
 
71
- 4. Hook privilege stays narrow
72
- `REVOwner` and deployer-only setters must not be callable by arbitrary actors or stale deployment helpers.
48
+ ## Roles And Privileges
73
49
 
74
- 5. Sucker and operator exemptions are precise
75
- Fee-free or mint-enabled paths meant for registered omnichain components must not be reusable by arbitrary callers.
50
+ | Role | Powers | How constrained |
51
+ |------|--------|-----------------|
52
+ | Revnet deployer path | Define long-lived stage and operator shape | Must not retain unexpected mutable governance |
53
+ | Split operator | Use the allowed runtime envelope | Must stay within deployment-defined permissions |
54
+ | Borrower or delegated operator | Open or manage loans | Must not escape collateral, delay, or source limits |
55
+ | Hidden-token user or delegate | Burn and reveal visible supply | Must not create extra supply or break accounting |
76
56
 
77
- 6. Collateral burn/remint symmetry holds
78
- Loan collateral that is burned on borrow and re-minted on repay must not be duplicable, strandable, or recoverable by the wrong party.
57
+ ## Integration Assumptions
79
58
 
80
- 7. Hidden token accounting is sound
81
- Tokens hidden via REVHiddenTokens must be exactly recoverable on reveal. The hidden balance must not allow minting more tokens than were burned, and totalHiddenOf must equal the sum of all per-holder hidden balances.
59
+ | Dependency | Assumption | What breaks if wrong |
60
+ |------------|------------|----------------------|
61
+ | `nana-core-v6` | Rulesets, reclaim math, and surplus views stay coherent | Stage and cash-out behavior drift |
62
+ | `nana-suckers-v6` | Remote supply/surplus snapshots are authentic | Omnichain reclaim and borrowability drift |
63
+ | Buyback and 721 integrations | Hook composition remains consistent with revnet expectations | Pay-path and mint-permission behavior drift |
82
64
 
83
- 8. Stage transitions do not create hidden refinancing windows
84
- Changes in issuance or cash-out economics across stages must not let a borrower lock in value that the system intended to become unavailable.
85
-
86
- ## Threat Model
87
-
88
- Prioritize:
89
- - surplus manipulation before and after borrowing
90
- - stage-boundary timing attacks
91
- - cash-out delay bypasses
92
- - array or hook-spec assumptions that depend on non-empty returns
93
- - split-weight accounting during 721 compositions
94
- - Permit2 and ERC-2771 assisted loan flows
95
- - operator delegation abuse: `OPEN_LOAN`, `REPAY_LOAN`, `REALLOCATE_LOAN`, `HIDE_TOKENS`, `REVEAL_TOKENS` permission checks — verify collateral and loan NFTs always flow to the holder/owner, never the operator
96
-
97
- The best attacker mindsets here are:
98
- - a borrower who can move surplus or stage timing before and after borrowing
99
- - a caller exploiting the fact that revnets are composed from several optional subsystems, not one monolith
100
- - an operator or deployer helper that retained one capability too many
101
- - a delegated operator who tricks a holder into granting permission, then exploits the delegation to extract value (e.g., borrowing on behalf of a holder and directing funds to a beneficiary they control)
102
-
103
- ## Hotspots
65
+ ## Critical Invariants
104
66
 
105
- - `REVOwner.beforePayRecordedWith`
106
- - `REVOwner.beforeCashOutRecordedWith`
107
- - deployer-only linkage between `REVDeployer` and `REVOwner`
108
- - `REVLoans` borrowable amount, fee accrual, and liquidation logic
109
- - `REVHiddenTokens.hideTokensOf` and `revealTokensOf` burn/mint symmetry and `HIDE_TOKENS`/`REVEAL_TOKENS` permission checks
110
- - `REVLoans` operator delegation: `OPEN_LOAN`, `REPAY_LOAN`, `REALLOCATE_LOAN` inline permission checks — verify holder/owner receives collateral and loan NFTs in all delegation paths
111
- - any path that assumes a valid tiered 721 hook or sucker mapping exists
67
+ 1. Stage progression stays monotonic and follows deployed timing.
68
+ 2. Borrowability respects cash-out delay, surplus, supply, and source limits.
69
+ 3. Burned collateral is not accidentally treated like escrowed collateral.
70
+ 4. Hidden-token accounting preserves total claims while changing visible supply intentionally.
71
+ 5. Optional integrations do not silently widen revnet authority or mint rights.
112
72
 
113
- ## Sequences Worth Replaying
73
+ ## Attack Surfaces
114
74
 
115
- 1. Pay into a revnet with 721 and buyback composition enabled, then inspect how weight is scaled before and after hook specs are consumed.
116
- 2. Borrow near a stage boundary, then repay, refinance, or liquidate after the next stage becomes active.
117
- 3. Borrow after surplus inflation, then force or observe surplus contraction before liquidation.
118
- 4. Cash out through a legitimate sucker path versus a near-sucker spoof path.
119
- 5. Any path where `REVOwner` expects hook arrays or external replies to be non-empty.
120
- 6. Hide tokens, have an accomplice cash out at the inflated rate, then reveal — check whether the net outcome is profitable.
75
+ - stage-transition boundaries
76
+ - live borrowability and cross-currency debt aggregation
77
+ - hidden-token burn and reveal flows
78
+ - omnichain surplus and sucker exemptions
79
+ - payment and cash-out hook composition in `REVOwner`
121
80
 
122
- ## Finding Bar
81
+ ## Accepted Risks Or Behaviors
123
82
 
124
- The best findings in this repo usually prove one of these:
125
- - a revnet mints or redeems on economics different from the stage schedule users think they are on
126
- - the runtime hook scales payment or cash-out accounting incorrectly during composition
127
- - the loan system can externalize loss to the treasury through timing, surplus movement, or fee math
128
- - a deployer-only or operator-only assumption survives launch and remains exploitable at runtime
83
+ - Revnets intentionally trade recoverability for predictable launch-time economics.
84
+ - Some economic surfaces are conservative by design and may refuse otherwise-valid actions rather than risk an unsafe result.
129
85
 
130
- ## Build And Verification
86
+ ## Verification
131
87
 
132
- Standard workflow:
133
88
  - `npm install`
134
89
  - `forge build`
135
90
  - `forge test`
136
-
137
- Current tests emphasize:
138
- - lifecycle and invincibility properties
139
- - loan invariants and attacks
140
- - fee recovery
141
- - split-weight adjustments
142
- - regressions around low-severity edge cases
143
-
144
- Strong findings in this repo usually combine economics and composition: a bug is especially valuable if it only appears once a revnet is wired into the rest of the ecosystem.
package/CHANGELOG.md CHANGED
@@ -26,12 +26,12 @@ This file describes the verified change from `revnet-core-v5` to the current `re
26
26
  ## Operator delegation (permission IDs 35–39)
27
27
 
28
28
  - Added five new `JBPermissionIds` for operator delegation in `@bananapus/permission-ids-v6`:
29
- - `HIDE_TOKENS` (35) — hide tokens on behalf of a holder via `REVHiddenTokens.hideTokensOf`
29
+ - `HIDE_TOKENS` (35) — lets an authorized operator allow or disallow holders to hide their own tokens via `REVHiddenTokens`
30
30
  - `OPEN_LOAN` (36) — open a loan on behalf of a token holder via `REVLoans.borrowFrom`
31
31
  - `REALLOCATE_LOAN` (37) — reallocate loan collateral on behalf of a loan owner via `REVLoans.reallocateCollateralFromLoan`
32
32
  - `REPAY_LOAN` (38) — repay a loan on behalf of a loan owner via `REVLoans.repayLoan`
33
- - `REVEAL_TOKENS` (39) — reveal hidden tokens on behalf of a holder via `REVHiddenTokens.revealTokensOf`
34
- - `REVHiddenTokens` now inherits `JBPermissioned` and accepts a `holder` parameter on `hideTokensOf` and `revealTokensOf`. An operator with the appropriate permission can act on behalf of the holder.
33
+ - `REVEAL_TOKENS` (39) — legacy permission id; hidden-token reveal no longer depends on it
34
+ - `REVHiddenTokens` now inherits `JBPermissioned` and accepts a `holder` parameter on `hideTokensOf` and `revealTokensOf`. Hiding is available to an operator-managed holder allowlist, and also to the project owner or any operator with `HIDE_TOKENS`. Revealing is holder-only and does not require special permission.
35
35
  - `REVLoans.borrowFrom` now accepts a `holder` parameter. The loan NFT is minted to `holder`, and collateral is burned from `holder`. An operator with `OPEN_LOAN` permission can borrow on behalf of a holder.
36
36
  - `REVLoans.repayLoan` now allows permissioned operators with `REPAY_LOAN` to repay on behalf of the loan NFT owner. Replacement loans are minted to the original loan owner.
37
37
  - `REVLoans.reallocateCollateralFromLoan` now allows permissioned operators with `REALLOCATE_LOAN` to reallocate on behalf of the loan NFT owner. Returned collateral and replacement loans go to the original loan owner.
@@ -41,6 +41,7 @@ This file describes the verified change from `revnet-core-v5` to the current `re
41
41
 
42
42
  - `IREVHiddenTokens.hideTokensOf` signature changed: added `address holder` parameter
43
43
  - `IREVHiddenTokens.revealTokensOf` signature changed: added `address holder` parameter
44
+ - `IREVHiddenTokens.setTokenHidingAllowedFor` added for operator-managed holder allowlisting
44
45
  - `IREVHiddenTokens.HideTokens` event: added `address holder` field
45
46
  - `IREVHiddenTokens.RevealTokens` event: added `address holder` field
46
47
  - `IREVLoans.borrowFrom` signature changed: added `address holder` as last parameter
package/README.md CHANGED
@@ -1,25 +1,29 @@
1
1
  # Revnet Core
2
2
 
3
- `@rev-net/core-v6` deploys and operates Revnets: autonomous Juicebox projects with staged economics, optional tiered NFTs, cross-chain support, buyback integration, and token-collateralized loans.
3
+ `@rev-net/core-v6` deploys and operates Revnets: Juicebox project shapes with staged economics, optional tiered NFTs, cross-chain support, buyback integration, hidden-token mechanics, and token-collateralized loans.
4
4
 
5
5
  Docs: <https://docs.juicebox.money>
6
- Architecture: [ARCHITECTURE.md](./ARCHITECTURE.md)
6
+ Architecture: [ARCHITECTURE.md](./ARCHITECTURE.md)
7
+ User journeys: [USER_JOURNEYS.md](./USER_JOURNEYS.md)
8
+ Skills: [SKILLS.md](./SKILLS.md)
9
+ Risks: [RISKS.md](./RISKS.md)
10
+ Administration: [ADMINISTRATION.md](./ADMINISTRATION.md)
11
+ Audit instructions: [AUDIT_INSTRUCTIONS.md](./AUDIT_INSTRUCTIONS.md)
7
12
 
8
13
  ## Overview
9
14
 
10
- A Revnet is meant to run without a human owner after launch. Its economics are encoded up front as a sequence of stages, and the runtime hook plus loan system enforce those rules over time.
15
+ A Revnet is meant to minimize human administration after launch. Its economics are encoded up front as a sequence of stages, and the runtime hook plus loan system enforce those rules over time.
11
16
 
12
17
  This package provides:
13
18
 
14
19
  - a deployer that launches Revnets and stores their long-lived configuration
15
20
  - a runtime hook that mediates pay, cash-out, mint-permission, and delayed-cash-out behavior
16
- - an ERC-721 loan system that burns token collateral on borrow and remints on repayment
21
+ - a loan system that burns token collateral on borrow and remints on repayment
22
+ - a hidden-token system that temporarily removes tokens from visible supply
17
23
 
18
24
  It also composes with the 721 hook stack, buyback hook, router terminal, Croptop, and suckers where needed.
19
25
 
20
- Use this repo when the product is an autonomous treasury-backed network with encoded stage transitions. Do not use it when governance, mutable operator control, or simple project deployment is the goal.
21
-
22
- The key point is that a Revnet is not just "a Juicebox project with presets." It is a project shape whose admin surface is intentionally collapsed into deployment-time configuration plus constrained runtime operators.
26
+ Use this repo when the product is a treasury-backed network with encoded stage transitions and a tightly constrained post-launch admin surface. Do not use it when the goal is ordinary governance or a simple project deploy.
23
27
 
24
28
  ## Key Contracts
25
29
 
@@ -28,48 +32,46 @@ The key point is that a Revnet is not just "a Juicebox project with presets." It
28
32
  | `REVDeployer` | Launches and configures Revnets, stages, split operators, and optional auxiliary features. |
29
33
  | `REVOwner` | Runtime data-hook and cash-out-hook surface used by active Revnets. |
30
34
  | `REVLoans` | Loan surface that lets users borrow against Revnet tokens with burned collateral and NFT loan positions. |
31
- | `REVHiddenTokens` | Lets token holders temporarily hide (burn) tokens, excluding them from totalSupply and increasing cash-out value for remaining holders. Hidden tokens can be revealed (re-minted) at any time. |
35
+ | `REVHiddenTokens` | Lets token holders temporarily hide tokens, excluding them from visible supply until reveal. |
32
36
 
33
37
  ## Mental Model
34
38
 
35
39
  Read the package in two halves:
36
40
 
37
41
  1. deployment-time shape: `REVDeployer` decides what the network will be allowed to do
38
- 2. runtime enforcement: `REVOwner` and `REVLoans` decide how that shape behaves over time
39
-
40
- That split matters because most mistakes are one of these:
41
-
42
- - assuming a deploy-time parameter can be changed later
43
- - assuming a runtime hook is only advisory rather than economically binding
42
+ 2. runtime enforcement: `REVOwner`, `REVLoans`, and `REVHiddenTokens` decide how that shape behaves over time
44
43
 
45
- The shortest useful reading order is:
46
-
47
- 1. `REVDeployer`
48
- 2. `REVOwner`
49
- 3. `REVLoans`
50
- 4. any integrated hook or bridge repo the deployment enables
44
+ Most mistakes come from assuming a deploy-time parameter can be changed later or that a runtime hook is only advisory.
51
45
 
52
46
  ## Read These Files First
53
47
 
54
48
  1. `src/REVDeployer.sol`
55
49
  2. `src/REVOwner.sol`
56
50
  3. `src/REVLoans.sol`
57
- 4. the integrated hook or bridge repo used by the deployment
51
+ 4. `src/REVHiddenTokens.sol`
52
+ 5. the integrated hook or bridge repo used by the deployment
58
53
 
59
54
  ## Integration Traps
60
55
 
61
- - the deployer holding the project NFT is not an implementation detail; it is part of the ownership model
56
+ - the deployer holding the project NFT is part of the ownership model, not an implementation detail
62
57
  - split operators are constrained, not equivalent to general protocol governance
63
- - the loan system depends on live revnet economics, so it should be reviewed together with the runtime hook and treasury assumptions
64
- - optional integrations like buybacks, 721 hooks, and suckers are compositional, but they materially change the resulting network
58
+ - the loan system depends on live revnet economics and should be reviewed together with the runtime hook
59
+ - optional integrations like buybacks, 721 hooks, and suckers materially change the resulting network
65
60
 
66
61
  ## Where State Lives
67
62
 
68
63
  - deployment-time configuration and operator envelope live in `REVDeployer`
69
64
  - runtime pay and cash-out behavior live in `REVOwner`
70
65
  - loan positions and loan-specific state live in `REVLoans`
66
+ - hidden-token state lives in `REVHiddenTokens`
67
+
68
+ ## High-Signal Tests
71
69
 
72
- Do not audit those contracts in isolation if the deployment enables cross-package features; the composed network is the real product.
70
+ 1. `test/REVLifecycle.t.sol`
71
+ 2. `test/REVLoans.invariants.t.sol`
72
+ 3. `test/TestLongTailEconomics.t.sol`
73
+ 4. `test/fork/TestLoanBorrowFork.t.sol`
74
+ 5. `test/audit/CodexPhantomSurplusTerminal.t.sol`
73
75
 
74
76
  ## Install
75
77
 
@@ -94,7 +96,7 @@ Useful scripts:
94
96
 
95
97
  ## Deployment Notes
96
98
 
97
- Revnet deployment assumes the core protocol, 721 hook, buyback hook, router terminal, suckers, and Croptop packages are available. Every Revnet is intentionally unowned after deployment in the human sense; the deployer contract itself retains the project NFT.
99
+ Revnet deployment assumes the core protocol, 721 hook, buyback hook, router terminal, suckers, and Croptop packages are available. Revnets are intentionally unowned in the direct human sense after deployment, but the deployer contract itself remains part of the ownership model.
98
100
 
99
101
  ## Repository Layout
100
102
 
@@ -103,6 +105,7 @@ src/
103
105
  REVDeployer.sol
104
106
  REVOwner.sol
105
107
  REVLoans.sol
108
+ REVHiddenTokens.sol
106
109
  interfaces/
107
110
  structs/
108
111
  test/
@@ -115,8 +118,12 @@ script/
115
118
  ## Risks And Notes
116
119
 
117
120
  - Revnets are intentionally hard to change after launch, so bad stage design is expensive
118
- - `REVLoans` relies on live treasury conditions and is therefore sensitive to surplus and pricing assumptions
119
- - the deployer and runtime hook have a tight relationship that should be treated as one design, not two independent contracts
120
- - burned-collateral lending is operationally different from escrowed-collateral lending and needs clear integrator expectations
121
+ - `REVLoans` relies on live treasury conditions and is sensitive to surplus and pricing assumptions
122
+ - the deployer and runtime hook should be treated as one design, not two separate systems
123
+ - burned-collateral lending is operationally different from escrowed-collateral lending
124
+
125
+ ## For AI Agents
121
126
 
122
- The usual review failure mode is to focus on the loans or the stages in isolation. The real system is the combination of stage economics, runtime hook behavior, and who is still allowed to act after deployment.
127
+ - Describe Revnets as treasury-backed Juicebox project shapes with encoded stage transitions, not as simple presets.
128
+ - Read `REVDeployer`, `REVOwner`, `REVLoans`, and `REVHiddenTokens` together before answering economic or admin-surface questions.
129
+ - If a deployment enables buybacks, 721 hooks, or suckers, inspect those sibling repos before making definitive claims.