Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Argon: Pox 4 #4085

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions contrib/core-contract-tests/Clarinet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,18 @@ costs_version = 1
[contracts.bns]
path = "../../stackslib/src/chainstate/stacks/boot/bns.clar"
depends_on = []

# pox-4 contains concat of boot/pox-4 and boot/pox-testnet
# path = "../../stackslib/src/chainstate/stacks/boot/pox-4.clar"
# path = "../../stackslib/src/chainstate/stacks/boot/pox-testnet.clar"
[contracts.pox-4]
path = "./contracts/pox/pox-4.clar"
depends_on = []
clarity = 2
epoch = 2.4

[contracts.pox-helper]
path = "./contracts/pox/pox-helper.clar"
depends_on = []
clarity = 2
epoch = 2.4
1,355 changes: 1,355 additions & 0 deletions contrib/core-contract-tests/contracts/pox/pox-4.clar

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions contrib/core-contract-tests/contracts/pox/pox-helper.clar
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

(define-read-only (get-bbh)
burn-block-height)
8 changes: 4 additions & 4 deletions contrib/core-contract-tests/tests/bns/name_register.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,8 @@ describe("name revealing workflow", () => {
Cl.tuple({
owner: Cl.standardPrincipal(bob),
["zonefile-hash"]: Cl.bufferFromUtf8(cases[0].zonefile),
["lease-ending-at"]: Cl.some(Cl.uint(16)),
["lease-started-at"]: Cl.uint(6),
["lease-ending-at"]: Cl.some(Cl.uint(simnet.blockHeight + 10)),
["lease-started-at"]: Cl.uint(simnet.blockHeight),
})
);
});
Expand Down Expand Up @@ -589,8 +589,8 @@ describe("register a name again before and after expiration", () => {
Cl.tuple({
owner: Cl.standardPrincipal(charlie),
["zonefile-hash"]: Cl.bufferFromAscii("CHARLIE"),
["lease-ending-at"]: Cl.some(Cl.uint(5029)),
["lease-started-at"]: Cl.uint(5019),
["lease-ending-at"]: Cl.some(Cl.uint(simnet.blockHeight + 10)),
["lease-started-at"]: Cl.uint(simnet.blockHeight),
})
);
});
Expand Down
40 changes: 20 additions & 20 deletions contrib/core-contract-tests/tests/bns/name_register_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Clarinet.test({
],
cases[0].nameOwner.address),
]);
assertEquals(block.height, 2);
assertEquals(block.height, 3);
block.receipts[0].result
.expectErr()
.expectInt(1005);
Expand All @@ -119,7 +119,7 @@ Clarinet.test({
],
cases[1].namespaceOwner.address),
]);
assertEquals(block.height, 3);
assertEquals(block.height, 4);
block.receipts[0].result
.expectOk()
.expectUint(144 + block.height - 1);
Expand All @@ -136,7 +136,7 @@ Clarinet.test({
],
cases[1].namespaceOwner.address),
]);
assertEquals(block.height, 4);
assertEquals(block.height, 5);
block.receipts[0].result
.expectOk()
.expectBool(true);
Expand All @@ -158,7 +158,7 @@ Clarinet.test({
],
bob.address),
]);
assertEquals(block.height, 5);
assertEquals(block.height, 6);
block.receipts[0].result
.expectOk()
.expectUint(144 + block.height - 1);
Expand All @@ -174,7 +174,7 @@ Clarinet.test({
],
bob.address),
]);
assertEquals(block.height, 6);
assertEquals(block.height, 7);
block.receipts[0].result
.expectErr()
.expectInt(2004);
Expand All @@ -195,7 +195,7 @@ Clarinet.test({
],
cases[0].namespaceOwner.address),
]);
assertEquals(block.height, 7);
assertEquals(block.height, 8);
block.receipts[0].result
.expectOk()
.expectUint(144 + block.height - 1);
Expand All @@ -212,7 +212,7 @@ Clarinet.test({
],
cases[0].namespaceOwner.address),
]);
assertEquals(block.height, 8);
assertEquals(block.height, 9);
block.receipts[0].result
.expectOk()
.expectBool(true);
Expand All @@ -225,7 +225,7 @@ Clarinet.test({
],
cases[0].namespaceOwner.address),
]);
assertEquals(block.height, 9);
assertEquals(block.height, 10);
block.receipts[0].result
.expectOk()
.expectBool(true);
Expand All @@ -244,7 +244,7 @@ Clarinet.test({
],
bob.address),
]);
assertEquals(block.height, 10);
assertEquals(block.height, 11);
block.receipts[0].result
.expectErr()
.expectInt(2001);
Expand All @@ -266,7 +266,7 @@ Clarinet.test({
],
bob.address),
]);
assertEquals(block.height, 11);
assertEquals(block.height, 12);
block.receipts[0].result
.expectOk()
.expectUint(144 + block.height - 1);
Expand All @@ -282,7 +282,7 @@ Clarinet.test({
],
bob.address),
]);
assertEquals(block.height, 12);
assertEquals(block.height, 13);
block.receipts[0].result
.expectErr()
.expectInt(2007);
Expand All @@ -304,7 +304,7 @@ Clarinet.test({
],
bob.address),
]);
assertEquals(block.height, 13);
assertEquals(block.height, 14);
block.receipts[0].result
.expectOk()
.expectUint(144 + block.height - 1);
Expand All @@ -320,7 +320,7 @@ Clarinet.test({
],
bob.address),
]);
assertEquals(block.height, 14);
assertEquals(block.height, 15);
block.receipts[0].result
.expectErr()
.expectInt(2022);
Expand All @@ -342,7 +342,7 @@ Clarinet.test({
],
bob.address),
]);
assertEquals(block.height, 15);
assertEquals(block.height, 16);
block.receipts[0].result
.expectOk()
.expectUint(144 + block.height - 1);
Expand All @@ -358,7 +358,7 @@ Clarinet.test({
],
bob.address),
]);
assertEquals(block.height, 16);
assertEquals(block.height, 17);
block.receipts[0].result
.expectOk()
.expectBool(true);
Expand Down Expand Up @@ -388,7 +388,7 @@ Clarinet.test({
],
bob.address),
]);
assertEquals(block.height, 17);
assertEquals(block.height, 18);
block.receipts[0].result
.expectErr()
.expectInt(2004);
Expand All @@ -412,7 +412,7 @@ Clarinet.test({
],
charlie.address),
]);
assertEquals(block.height, 18);
assertEquals(block.height, 19);
block.receipts[0].result
.expectOk()
.expectUint(144 + block.height - 1);
Expand All @@ -428,7 +428,7 @@ Clarinet.test({
],
charlie.address),
]);
assertEquals(block.height, 19);
assertEquals(block.height, 20);
block.receipts[0].result
.expectErr()
.expectInt(2004);
Expand All @@ -452,7 +452,7 @@ Clarinet.test({
],
bob.address),
]);
assertEquals(block.height, 20);
assertEquals(block.height, 21);
block.receipts[0].result
.expectOk()
.expectUint(144 + block.height - 1);
Expand All @@ -468,7 +468,7 @@ Clarinet.test({
],
bob.address),
]);
assertEquals(block.height, 21);
assertEquals(block.height, 22);
block.receipts[0].result
.expectErr()
.expectInt(3001);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { Cl } from "@stacks/transactions";
import { beforeEach, describe, expect, it } from "vitest";
import { createHash } from "node:crypto";

const accounts = simnet.getAccounts();
const alice = accounts.get("wallet_1")!;
const bob = accounts.get("wallet_2")!;
const charlie = accounts.get("wallet_3")!;

function expectBurnBlockHeight(height: number) {
const { result: bbh } = simnet.callReadOnlyFn(
"pox-helper",
"get-bbh",
[],
alice
);
expect(bbh).toBeUint(height);
}

describe("test pox prepare phase check", () => {
it("should return false during prepare phase", () => {
simnet.mineEmptyBlocks(998);
expectBurnBlockHeight(999);
let { result } = simnet.callReadOnlyFn(
"pox-4",
"check-not-prepare-phase",
[],
alice
);
expect(result).toBeBool(true);

simnet.mineEmptyBlock();
expectBurnBlockHeight(1000);
({ result } = simnet.callReadOnlyFn(
"pox-4",
"check-not-prepare-phase",
[],
alice
));
expect(result).toBeBool(false);

simnet.mineEmptyBlocks(50);
expectBurnBlockHeight(1050);
({ result } = simnet.callReadOnlyFn(
"pox-4",
"check-not-prepare-phase",
[],
alice
));
expect(result).toBeBool(false);

simnet.mineEmptyBlock();
expectBurnBlockHeight(1051);
({ result } = simnet.callReadOnlyFn(
"pox-4",
"check-not-prepare-phase",
[],
alice
));
expect(result).toBeBool(true);
});
});
11 changes: 11 additions & 0 deletions stackslib/src/chainstate/stacks/boot/pox-4.clar
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
(define-constant ERR_DELEGATION_WRONG_REWARD_SLOT 29)
(define-constant ERR_STACKING_IS_DELEGATED 30)
(define-constant ERR_STACKING_NOT_DELEGATED 31)
(define-constant ERR_STACKING_DURING_PREPARE_PHASE 32)

;; PoX disabling threshold (a percent)
(define-constant POX_REJECTION_FRACTION u25)
Expand Down Expand Up @@ -504,6 +505,12 @@
(and (>= lock-period MIN_POX_REWARD_CYCLES)
(<= lock-period MAX_POX_REWARD_CYCLES)))

;; Is the current burn block height in the prepare phase?
(define-read-only (check-not-prepare-phase)
(> (mod (+ (- burn-block-height (var-get first-burnchain-block-height)) (var-get pox-prepare-cycle-length))
(var-get pox-reward-cycle-length))
(var-get pox-prepare-cycle-length)))

;; Evaluate if a participant can stack an amount of STX for a given period.
;; This method is designed as a read-only method so that it can be used as
;; a set of guard conditions and also as a read-only RPC call that can be
Expand Down Expand Up @@ -541,6 +548,10 @@
(asserts! (check-pox-lock-period num-cycles)
(err ERR_STACKING_INVALID_LOCK_PERIOD))

;; stacking must not happen during prepare phase
(asserts! (check-not-prepare-phase)
(err ERR_STACKING_DURING_PREPARE_PHASE))

;; address version must be valid
(asserts! (check-pox-addr-version (get version pox-addr))
(err ERR_STACKING_INVALID_POX_ADDRESS))
Expand Down