Skip to content

WIP: PoX-5 and Epoch 4#7197

Draft
hstove-stacks wants to merge 468 commits into
developfrom
pox-wf-integration
Draft

WIP: PoX-5 and Epoch 4#7197
hstove-stacks wants to merge 468 commits into
developfrom
pox-wf-integration

Conversation

@hstove-stacks

Copy link
Copy Markdown
Contributor

This is an in-progress PR for iterative development of pox-5 work

;; this is a list of outputs corresponding to their timelocks.
;; If the response is `err`, this is the amount of sBTC (in sats)
;; that they want to lock.
(btc-lockup (response {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this being a response is bad for UX. I'd rather see two optionals, btc-lockup and sbtc-lockup, with a check to ensure they are not both set.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I certainly see what you mean, but in general I like a compiler check more than a runtime check. I do agree it's not the best UX, but I'm not sure having two optionals is either.

Comment thread stackslib/src/chainstate/stacks/boot/pox-5.clar Outdated
Comment on lines +738 to +746
(ok {
unlock-burn-height: (reward-cycle-to-unlock-height unlock-cycle),
staker: tx-sender,
signer: signer,
prev-unlock-height: prev-unlock-cycle,
unlock-cycle: unlock-cycle,
num-cycles: num-cycles,
amount-ustx: new-lock-amount,
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, field ordering in tuples is nice to be consistent when possible.

         (ok {
-            unlock-burn-height: (reward-cycle-to-unlock-height unlock-cycle),
-            staker: tx-sender,
             signer: signer,
+            staker: tx-sender,
+            amount-ustx: new-lock-amount,
+            num-cycles: num-cycles,
             prev-unlock-height: prev-unlock-cycle,
+            unlock-burn-height: (reward-cycle-to-unlock-height unlock-cycle),
             unlock-cycle: unlock-cycle,
-            num-cycles: num-cycles,
-            amount-ustx: new-lock-amount,
         })
     )
 )

)
)

(define-public (calculate-rewards (bond-periods (list 6 uint)))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be nice to have a read-only version of this that could be called any time to estimate rewards, and then call that from the actual one that checks the proper height and sets the persistent storage.

Comment thread stackslib/src/chainstate/stacks/boot/pox-5.clar Outdated

;; Used to prevent fractional multiplication errors
;; during reward calculations
(define-constant PRECISION u1000000000000000000) ;; 1e18

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be better performance for this to be a power of 2 (multiplies and divides become shifts).

Comment thread stackslib/src/chainstate/stacks/boot/pox-5.clar Outdated
Comment thread stackslib/src/chainstate/stacks/boot/pox-5.clar Outdated
Comment thread stackslib/src/chainstate/stacks/boot/pox-5.clar Outdated
;; normally, stacking methods may only be invoked by _direct_ transactions
;; (i.e., the tx-sender issues a direct contract-call to the stacking methods)
;; by issuing an allowance, the tx-sender may call through the allowed contract
(define-public (allow-contract-caller

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we still going to consider the post-condition replacement for this? I think it would be nice. See discussion.

Comment thread stackslib/src/chainstate/stacks/boot/pox-5.clar Outdated
Comment thread stackslib/src/chainstate/stacks/boot/pox-5.clar Outdated
Comment thread stackslib/src/chainstate/stacks/boot/pox-5.clar Outdated
Comment thread stackslib/src/chainstate/stacks/boot/pox-5.clar Outdated
Comment thread stackslib/src/chainstate/stacks/boot/pox-5.clar Outdated
index: uint,
is-bond: bool,
staker: principal,
signer: principal,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to include the signer in the key here? I think we're already guaranteed to only have one entry per index/is-bond/staker, and adding the signer is just complicating it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah you're right about uniqueness, but it also acts as a kind of lookup variable, where we do want to answer "for this signer, how many shares ...". And so to answer that, you'd have to do either 2 queries, or add another field to the value. I can see arguments for putting signer in the value, though.

Comment thread stackslib/src/chainstate/stacks/boot/pox-5.clar Outdated
Comment thread stackslib/src/chainstate/stacks/boot/pox-5.clar Outdated
Comment thread stackslib/src/chainstate/stacks/boot/pox-5.clar Outdated
Comment thread stackslib/src/chainstate/stacks/boot/pox-5.clar Outdated
Comment thread stackslib/src/chainstate/stacks/boot/pox-5.clar Outdated
@CLAassistant

CLAassistant commented May 20, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Ok(SignerCalculation {
reward_set: RewardSet::Waterfall(WaterfallCycleSet {
sbtc_address,
signers: signer_set,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this fail if signer_set.is_empty()? pox_5_stake_entries can return an empty iterator when PoX-5 has no first signer for the
cycle, but this still stores RewardSet::Waterfall { signers: [] }. Since Waterfall signers() returns Some([]), later signature
validation computes total weight/threshold as 0 and accepts blocks with no signer signatures.

Comment on lines +1451 to +1456
(accumulation (try! (fold validate-l1-lockup (get outputs lockups)
(ok {
sum: u0,
expected-script-hash: expected-timelock-output,
})
)))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this reject duplicate L1 outpoints before summing? A caller can include the same {tx, output-index} multiple times in one outputs list; each entry passes validation and is added to sats-total, inflating bond shares before the single staker/bond-membership checks run.

brice-stacks and others added 30 commits June 11, 2026 11:40
Bump clarinet-sdk to 3.19.0 with lock-aware boot pox-5
This behavior at rollover time has been flagged multiple times by
reviewers, so this PR just adds some comments to clarify the intention
and another test to verify the behavior. The issue is that when rolling
over (bond->bond or stx-only->bond or bond->stx-only), the action is
allowed during the last half of the last cycle (the same timing as the
L1 unlock), but the rewards for that last cycle are unaffected.
fix: set /v2/pox's minimum to the hard-coded pox-5 value
fix: reject unstake-sbtc and announce-l1-early-exit during prepare
There seems to be a bug in vitest that causes it to stall when there
is that failure during setup. The latest v4 version fixes the hang, but
the error is hidden. I've opened an issue with `vitest` to fix this.
This gives us the variadic `concat` support needed to merge this PR.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…ng-logic

Fix: current cycle unstaking logic
…-stacks/stacks-core into fix/current-cycle-unstaking-logic
chore: document and verify the rollover behavior
…ntracts

fix: bump clarigen to fix clarigen-types issue
feat: replace `allow-contract-caller` with staking and pox PCs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.