Skip to content

Commit 61849ab

Browse files
committed
fix: comments, var-name in pox-5
1 parent b3823f1 commit 61849ab

8 files changed

Lines changed: 57 additions & 48 deletions

File tree

changelog.d/pox-5-comments.fixed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Clarify PoX-5 naming and comments: add `BOND_LENGTH_PERIODS`, rename `stake-update`'s `prev-unlock-height` response field to `prev-unlock-cycle`, and fix outdated comments around signer grants, prepare-phase callers, and `stake-update` lock handling

contrib/core-contract-tests/tests/clarigen-types.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5708,7 +5708,7 @@ export const contracts = {
57085708
{ name: 'cycles-to-extend', type: 'uint128' },
57095709
{ name: 'num-cycles', type: 'uint128' },
57105710
{ name: 'old-signer', type: 'principal' },
5711-
{ name: 'prev-unlock-height', type: 'uint128' },
5711+
{ name: 'prev-unlock-cycle', type: 'uint128' },
57125712
{ name: 'signer', type: 'principal' },
57135713
{ name: 'staker', type: 'principal' },
57145714
{ name: 'unlock-burn-height', type: 'uint128' },
@@ -5734,7 +5734,7 @@ export const contracts = {
57345734
cyclesToExtend: bigint;
57355735
numCycles: bigint;
57365736
oldSigner: string;
5737-
prevUnlockHeight: bigint;
5737+
prevUnlockCycle: bigint;
57385738
signer: string;
57395739
staker: string;
57405740
unlockBurnHeight: bigint;
@@ -7380,6 +7380,11 @@ export const contracts = {
73807380
type: 'uint128',
73817381
access: 'constant',
73827382
} as TypedAbiVariable<bigint>,
7383+
BOND_LENGTH_PERIODS: {
7384+
name: 'BOND_LENGTH_PERIODS',
7385+
type: 'uint128',
7386+
access: 'constant',
7387+
} as TypedAbiVariable<bigint>,
73837388
ERR_ACTIVE_BOND_NOT_INCLUDED: {
73847389
name: 'ERR_ACTIVE_BOND_NOT_INCLUDED',
73857390
type: {
@@ -7994,6 +7999,7 @@ export const contracts = {
79947999
BITCOIN_LOCKTIME_THRESHOLD: 500_000_000n,
79958000
BOND_GAP_CYCLES: 2n,
79968001
BOND_LENGTH_CYCLES: 12n,
8002+
BOND_LENGTH_PERIODS: 6n,
79978003
ERR_ACTIVE_BOND_NOT_INCLUDED: {
79988004
isOk: false,
79998005
value: 33n,
@@ -8452,7 +8458,7 @@ export const contracts = {
84528458
{ name: 'cycles-to-extend', type: 'uint128' },
84538459
{ name: 'num-cycles', type: 'uint128' },
84548460
{ name: 'old-signer', type: 'principal' },
8455-
{ name: 'prev-unlock-height', type: 'uint128' },
8461+
{ name: 'prev-unlock-cycle', type: 'uint128' },
84568462
{ name: 'signer', type: 'principal' },
84578463
{ name: 'staker', type: 'principal' },
84588464
{ name: 'unlock-burn-height', type: 'uint128' },
@@ -8478,7 +8484,7 @@ export const contracts = {
84788484
cyclesToExtend: bigint;
84798485
numCycles: bigint;
84808486
oldSigner: string;
8481-
prevUnlockHeight: bigint;
8487+
prevUnlockCycle: bigint;
84828488
signer: string;
84838489
staker: string;
84848490
unlockBurnHeight: bigint;

contrib/core-contract-tests/tests/pox-5/commands/StakeExtend.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export const StakeExtend = (accounts: Real['accounts']) =>
136136
// Receipt reflects the new unlock cycle; amount and signer unchanged.
137137
expect(receipt.value.unlockCycle).toBe(expectedUnlockCycle);
138138
expect(receipt.value.unlockBurnHeight).toBe(expectedUnlockBurnHeight);
139-
expect(receipt.value.prevUnlockHeight).toBe(prevUnlockCycle);
139+
expect(receipt.value.prevUnlockCycle).toBe(prevUnlockCycle);
140140
expect(receipt.value.amountUstx).toBe(expectedAmountUstx);
141141
expect(receipt.value.signer).toBe(signer);
142142
expect(receipt.value.staker).toBe(r.sender);

contrib/core-contract-tests/tests/pox-5/commands/StakeUpdate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export const StakeUpdate = (accounts: Real['accounts']) =>
132132
// Receipt reflects the recomputed unlock cycle and new amount/signer.
133133
expect(receipt.value.unlockCycle).toBe(expectedUnlockCycle);
134134
expect(receipt.value.unlockBurnHeight).toBe(expectedUnlockBurnHeight);
135-
expect(receipt.value.prevUnlockHeight).toBe(prevUnlockCycle);
135+
expect(receipt.value.prevUnlockCycle).toBe(prevUnlockCycle);
136136
expect(receipt.value.amountUstx).toBe(expectedAmountUstx);
137137
expect(receipt.value.signer).toBe(newSigner);
138138
expect(receipt.value.staker).toBe(r.sender);

pox-locking/src/pox_5.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,8 @@ fn handle_lockup_pox_v5(
440440
}
441441
}
442442

443-
/// Handle responses from stake-extend and stake-extend-pooled in pox-5 -- functions that
444-
/// *extend already-locked* STX.
443+
/// Handle responses from `stake-update` in pox-5 -- the function that
444+
/// *extends or increases already-locked* STX.
445445
fn handle_stake_lockup_update_pox_v5(
446446
global_context: &mut GlobalContext,
447447
function_name: &str,
@@ -677,7 +677,7 @@ mod tests {
677677
),
678678
(ClarityName::from_literal("num-cycle"), Value::UInt(1)),
679679
(
680-
ClarityName::from_literal("prev-unlock-height"),
680+
ClarityName::from_literal("prev-unlock-cycle"),
681681
Value::UInt(2),
682682
),
683683
(

stackslib/src/chainstate/stacks/boot/pox-5.clar

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@
7474
(define-constant BOND_LENGTH_CYCLES u12)
7575
;; The gap between the start of different bond periods
7676
(define-constant BOND_GAP_CYCLES u2)
77+
;; Bond length measured in bond-period indices
78+
;; (`BOND_LENGTH_CYCLES / BOND_GAP_CYCLES`). Also the maximum number of
79+
;; concurrently active bond periods (and the `(list 6 ...)` bound used for
80+
;; bond-period arguments).
81+
(define-constant BOND_LENGTH_PERIODS u6)
7782
;; The maximum amount of time that a user can stake for
7883
(define-constant MAX_NUM_CYCLES u96)
7984

@@ -860,7 +865,7 @@
860865
(bond-index (get bond-index current-membership))
861866
(current-cycle (current-pox-reward-cycle))
862867
(bond-start-cycle (bond-period-to-reward-cycle bond-index))
863-
(bond-end-cycle (bond-period-to-reward-cycle (+ bond-index u6)))
868+
(bond-end-cycle (bond-period-to-reward-cycle (+ bond-index BOND_LENGTH_PERIODS)))
864869
(next-cycle (+ current-cycle u1))
865870
;; If the bond hasn't started yet, then the first cycle where
866871
;; this new signer is active is the start cycle. Otherwise, it's the next reward
@@ -1159,7 +1164,7 @@
11591164
staker: tx-sender,
11601165
signer: signer,
11611166
old-signer: old-signer,
1162-
prev-unlock-height: prev-unlock-cycle,
1167+
prev-unlock-cycle: prev-unlock-cycle,
11631168
unlock-cycle: unlock-cycle,
11641169
num-cycles: num-cycles,
11651170
amount-ustx: new-lock-amount,
@@ -1204,7 +1209,7 @@
12041209
(signer (get signer membership))
12051210
(current-cycle (current-pox-reward-cycle))
12061211
(bond-start-cycle (bond-period-to-reward-cycle bond-index))
1207-
(bond-end-cycle (bond-period-to-reward-cycle (+ bond-index u6)))
1212+
(bond-end-cycle (bond-period-to-reward-cycle (+ bond-index BOND_LENGTH_PERIODS)))
12081213
(current-total-staked (get-total-sbtc-staked-for-bond bond-index))
12091214
(first-changed-reward-cycle (clamp current-cycle bond-start-cycle bond-end-cycle))
12101215
(amount-sats (get amount-sats membership))
@@ -1271,7 +1276,7 @@
12711276
(signer (get signer membership))
12721277
(current-cycle (current-pox-reward-cycle))
12731278
(bond-start-cycle (bond-period-to-reward-cycle bond-index))
1274-
(bond-end-cycle (bond-period-to-reward-cycle (+ bond-index u6)))
1279+
(bond-end-cycle (bond-period-to-reward-cycle (+ bond-index BOND_LENGTH_PERIODS)))
12751280
(first-changed-reward-cycle (clamp current-cycle bond-start-cycle bond-end-cycle))
12761281
(num-cycles (- bond-end-cycle first-changed-reward-cycle))
12771282
(current-amount-sats (get amount-sats membership))
@@ -2279,7 +2284,7 @@
22792284
))
22802285
(calculation-height (get calculation-height accumulator))
22812286
(bond-start-height (bond-period-to-burn-height bond-index))
2282-
(bond-end-height (bond-period-to-burn-height (+ bond-index u6)))
2287+
(bond-end-height (bond-period-to-burn-height (+ bond-index BOND_LENGTH_PERIODS)))
22832288
)
22842289
;; Verify that we're paying out bonds in the right order
22852290
(match (get last-bond-stx-value-ratio accumulator)
@@ -2859,9 +2864,9 @@
28592864
)
28602865
)
28612866

2862-
;; Construct the message hash for validating a signer key grant. Unlike [get-signer-key-message-hash],
2863-
;; this message hash does not include `max-amount`, `period`, or `reward-cycle`. The topic is always `"grant-authorization"`.
2864-
;; The `pox-addr` field is optional. When `none`, it means the signer key can be used for any PoX address.
2867+
;; Construct the message hash for validating a signer key grant.
2868+
;; Unlike [get-signer-key-message-hash], this hash covers only
2869+
;; `signer-manager` and `auth-id`. The topic is always `"grant-authorization"`.
28652870
(define-read-only (get-signer-grant-message-hash
28662871
(signer-manager principal)
28672872
(auth-id uint)
@@ -2951,8 +2956,9 @@
29512956

29522957
;; Reject calls that would modify the next reward cycle's signer / staker
29532958
;; set during the current cycle's prepare phase, when that set is frozen.
2954-
;; Used by `stake`, `stake-update`, `register-for-bond`, and
2955-
;; `update-bond-registration` as `(try! (verify-not-prepare-phase))`.
2959+
;; Used by `stake`, `stake-update`, `register-for-bond`,
2960+
;; `update-bond-registration`, `announce-l1-early-exit`, and `unstake-sbtc`
2961+
;; as `(try! (verify-not-prepare-phase))`.
29562962
(define-private (verify-not-prepare-phase)
29572963
(ok (asserts! (not (is-in-prepare-phase (current-pox-reward-cycle)))
29582964
ERR_STAKE_IN_PREPARE_PHASE
@@ -3030,7 +3036,7 @@
30303036
)
30313037
(let (
30323038
(bond-start-height (bond-period-to-burn-height bond-index))
3033-
(bond-end-height (bond-period-to-burn-height (+ bond-index u6)))
3039+
(bond-end-height (bond-period-to-burn-height (+ bond-index BOND_LENGTH_PERIODS)))
30343040
)
30353041
(and
30363042
(is-some (map-get? protocol-bonds bond-index))
@@ -3340,7 +3346,7 @@
33403346
;; Returns the expected L1 unlock height for a given bond index.
33413347
;; This is equal to 1/2 of a reward cycle before the end of the bond period.
33423348
(define-read-only (get-bond-l1-unlock-height (bond-index uint))
3343-
(- (bond-period-to-burn-height (+ bond-index u6))
3349+
(- (bond-period-to-burn-height (+ bond-index BOND_LENGTH_PERIODS))
33443350
(/ (var-get pox-reward-cycle-length) u2)
33453351
)
33463352
)

stackslib/src/chainstate/tests/snapshots/blockstack_lib__chainstate__tests__static_analysis_tests__tuple_merge_exceeds_max_value_size_cdeploy.snap

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
---
22
source: stackslib/src/chainstate/tests/static_analysis_tests.rs
3-
assertion_line: 1453
43
expression: result.get_expected_results()
5-
snapshot_kind: text
64
---
75
[
86
Failure(ExpectedFailureOutput(
@@ -26,7 +24,7 @@ snapshot_kind: text
2624
error: "Invalid Stacks block 3ccc7959909eb66e4071780c595ac12e8236872140cd9898fd3b3ddf4ddd118e: ClarityError(StaticCheck(StaticCheckError { err: Unreachable(\"Unexpected error type during static analysis: InvariantViolation(\\\"FAIL: .size() overflowed on too large of a type. Construction should have failed!\\\")\"), expressions: Some([SymbolicExpression { expr: List([SymbolicExpression { expr: Atom(ClarityName(\"ok\")), id: 172 }, SymbolicExpression { expr: List([SymbolicExpression { expr: Atom(ClarityName(\"merge\")), id: 174 }, SymbolicExpression { expr: Atom(ClarityName(\"ta\")), id: 175 }, SymbolicExpression { expr: Atom(ClarityName(\"tb\")), id: 176 }]), id: 173 }]), id: 171 }]), diagnostic: Diagnostic { level: Error, message: \"unexpected and unacceptable interpreter behavior: Unexpected error type during static analysis: InvariantViolation(\\\"FAIL: .size() overflowed on too large of a type. Construction should have failed!\\\")\", spans: [Span { start_line: 0, start_column: 0, end_line: 0, end_column: 0 }], suggestion: None } }))",
2725
)),
2826
Success(ExpectedBlockOutput(
29-
marf_hash: "4307de3ba401cf8b0b249c3c14145052e474e176e0a4b17ccebdb16006d3f884",
27+
marf_hash: "c3cb6ffa4b392cac63da6cf938ca01098875febd46b39efc067810280c080aae",
3028
evaluated_epoch: Epoch40,
3129
transactions: [
3230
ExpectedTransactionOutput(
@@ -56,7 +54,7 @@ snapshot_kind: text
5654
),
5755
)),
5856
Success(ExpectedBlockOutput(
59-
marf_hash: "96f223ffc56a0c83b9fce945840bda9861f0d7335e3b108fa0f1cc0cdbb032d2",
57+
marf_hash: "411bce021acf12a5dcd67d012a1545c96676910b327c3c3dae1f9e1cb1869a50",
6058
evaluated_epoch: Epoch40,
6159
transactions: [
6260
ExpectedTransactionOutput(
@@ -86,7 +84,7 @@ snapshot_kind: text
8684
),
8785
)),
8886
Success(ExpectedBlockOutput(
89-
marf_hash: "0c0565210c0967c5b58775318b5f942c1e916b5ea814645ffc29b6ea01fcef47",
87+
marf_hash: "db7415eaa975289668950b202d9a6160f8e6f94077aba49b2c5cb0c12508f851",
9088
evaluated_epoch: Epoch40,
9189
transactions: [
9290
ExpectedTransactionOutput(
@@ -116,7 +114,7 @@ snapshot_kind: text
116114
),
117115
)),
118116
Success(ExpectedBlockOutput(
119-
marf_hash: "fc6b30082e15893859ac7d27713c9da144c9021c7ef5019f5685c2849513b97b",
117+
marf_hash: "ac9b94d79f0ed7a4806dc47191d9adeef9ca27b2df277e4381d17151c5dc3b16",
120118
evaluated_epoch: Epoch40,
121119
transactions: [
122120
ExpectedTransactionOutput(
@@ -146,7 +144,7 @@ snapshot_kind: text
146144
),
147145
)),
148146
Success(ExpectedBlockOutput(
149-
marf_hash: "4930824fd0b20fd53fe6459416c4b50a8431f0034c5e7e91cb907a29ceed52a2",
147+
marf_hash: "dafd367ffe49a2fff9ff44943379581af0ab0f9100699af4154077eb209fab30",
150148
evaluated_epoch: Epoch40,
151149
transactions: [
152150
ExpectedTransactionOutput(
@@ -176,7 +174,7 @@ snapshot_kind: text
176174
),
177175
)),
178176
Success(ExpectedBlockOutput(
179-
marf_hash: "3298dfbaaa0e99f41329fe74ed732d87cc19a92110803e63c8998a1ac6ddbf16",
177+
marf_hash: "004bedff0046a7d214bde0afe817287397de87ee37205378ea5c0f785e0446f2",
180178
evaluated_epoch: Epoch40,
181179
transactions: [
182180
ExpectedTransactionOutput(

0 commit comments

Comments
 (0)