Skip to content

Commit 0bf2419

Browse files
committed
fix: use is-standard to check new recipient addr
1 parent 7c9e90a commit 0bf2419

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4615,6 +4615,11 @@ export const contracts = {
46154615
type: "uint128",
46164616
access: "constant",
46174617
} as TypedAbiVariable<bigint>,
4618+
ERR_INVALID_RECIPIENT: {
4619+
name: "ERR_INVALID_RECIPIENT",
4620+
type: "uint128",
4621+
access: "constant",
4622+
} as TypedAbiVariable<bigint>,
46184623
ERR_NOTHING_TO_CLAIM: {
46194624
name: "ERR_NOTHING_TO_CLAIM",
46204625
type: "uint128",
@@ -4663,6 +4668,7 @@ export const contracts = {
46634668
},
46644669
constants: {
46654670
DEPLOY_BLOCK_HEIGHT: 3n,
4671+
ERR_INVALID_RECIPIENT: 103n,
46664672
ERR_NOTHING_TO_CLAIM: 102n,
46674673
ERR_NOT_ALLOWED: 101n,
46684674
INITIAL_MINT_AMOUNT: 200_000_000_000_000n,

contrib/core-contract-tests/tests/sip-031/sip-031.test.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { project, accounts } from '../clarigen-types'; // where your [types.output] was specified
2-
import { CoreNodeEventType, cvToValue, projectFactory } from '@clarigen/core';
2+
import {
3+
CoreNodeEventType,
4+
cvToValue,
5+
projectFactory,
6+
MAINNET_BURN_ADDRESS,
7+
} from '@clarigen/core';
38
import { filterEvents, rov, txErr, txOk } from '@clarigen/test';
49
import { test, expect } from 'vitest';
510

@@ -404,3 +409,25 @@ test('claiming after waiting more than 1 month', () => {
404409
constants.INITIAL_MINT_VESTING_AMOUNT / 24n,
405410
);
406411
});
412+
413+
test('recipient cannot be set to a non-standard address', () => {
414+
const mainnetStandard = MAINNET_BURN_ADDRESS;
415+
const standardReceipt = txErr(
416+
contract.updateRecipient(mainnetStandard),
417+
accounts.deployer.address,
418+
);
419+
expect(standardReceipt.value).toBe(constants.ERR_INVALID_RECIPIENT);
420+
421+
const mainnetContract = `${MAINNET_BURN_ADDRESS}.blah`;
422+
const contractReceipt = txErr(
423+
contract.updateRecipient(mainnetContract),
424+
accounts.deployer.address,
425+
);
426+
expect(contractReceipt.value).toBe(constants.ERR_INVALID_RECIPIENT);
427+
});
428+
429+
test('recipient can be set to a contract', () => {
430+
const contractAddr = `${accounts.deployer.address}.blah`;
431+
txOk(contract.updateRecipient(contractAddr), accounts.deployer.address);
432+
expect(rov(contract.getRecipient())).toBe(contractAddr);
433+
});

stackslib/src/chainstate/stacks/boot/sip-031.clar

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
(define-constant ERR_NOT_ALLOWED u101)
1616
(define-constant ERR_NOTHING_TO_CLAIM u102)
17+
(define-constant ERR_INVALID_RECIPIENT u103)
1718

1819
;; The amount initially minted to the contract is 200M STX
1920
(define-constant INITIAL_MINT_AMOUNT u200000000000000) ;; 200,000,000 STX
@@ -59,6 +60,7 @@
5960
(define-public (update-recipient (new-recipient principal))
6061
(begin
6162
(try! (validate-caller))
63+
(asserts! (is-standard new-recipient) (err ERR_INVALID_RECIPIENT))
6264
(print {
6365
topic: "update-recipient",
6466
old-recipient: (var-get recipient),

0 commit comments

Comments
 (0)