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

[sbtc] Remove unused constants in sBTC token contract #1092

Merged
merged 7 commits into from
Dec 11, 2024
Merged
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
8 changes: 1 addition & 7 deletions contracts/Clarinet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,4 @@ path = 'contracts/sbtc-withdrawal.clar'
clarity_version = 3
epoch = 3.0
[repl.analysis]
passes = ['check_checker']

[repl.analysis.check_checker]
strict = false
trusted_sender = false
trusted_caller = true
callee_filter = true
passes = []
1 change: 0 additions & 1 deletion contracts/contracts/sbtc-bootstrap-signers.clar
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@

;; Signer Key Length Check
;; Checks that the length of each key is exactly 33 bytes
;; #[allow(unchecked_data)]
(define-private (signer-key-length-check (current-key (buff 33)) (helper-response (response uint uint)))
(match helper-response
index
Expand Down
1 change: 0 additions & 1 deletion contracts/contracts/sbtc-deposit.clar
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
)

;; private functions
;; #[allow(unchecked_data)]
(define-private (complete-individual-deposits-helper (deposit {txid: (buff 32), vout-index: uint, amount: uint, recipient: principal, burn-hash: (buff 32), burn-height: uint, sweep-txid: (buff 32)}) (helper-response (response uint uint)))
(match helper-response
index
Expand Down
5 changes: 0 additions & 5 deletions contracts/contracts/sbtc-registry.clar
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@
(id (increment-last-withdrawal-request-id))
)
(try! (is-protocol-caller))
;; #[allow(unchecked_data)]
(map-insert withdrawal-requests id {
amount: amount,
max-fee: max-fee,
Expand All @@ -188,7 +187,6 @@
;;
;; This function will emit a print event with the topic
;; "withdrawal-accept".
;; #[allow(unchecked_data)]
(define-public (complete-withdrawal-accept
(request-id uint)
(bitcoin-txid (buff 32))
Expand Down Expand Up @@ -228,7 +226,6 @@
;;
;; This function will emit a print event with the topic
;; "withdrawal-reject".
;; #[allow(unchecked_data)]
(define-public (complete-withdrawal-reject
(request-id uint)
(signer-bitmap uint)
Expand All @@ -253,7 +250,6 @@
;;
;; This function does not handle validation or moving the funds.
;; Instead, it is purely for the purpose of storing the completed deposit.
;; #[allow(unchecked_data)]
(define-public (complete-deposit
(txid (buff 32))
(vout-index uint)
Expand Down Expand Up @@ -288,7 +284,6 @@

;; Rotate the signer set, multi-sig principal, & aggregate pubkey
;; This function can only be called by the bootstrap-signers contract.
;; #[allow(unchecked_data)]
(define-public (rotate-keys
(new-keys (list 128 (buff 33)))
(new-address principal)
Expand Down
28 changes: 7 additions & 21 deletions contracts/contracts/sbtc-token.clar
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
(define-constant ERR_NOT_OWNER (err u4)) ;; `tx-sender` or `contract-caller` tried to move a token it does not own.
(define-constant ERR_NOT_AUTH (err u5)) ;; `tx-sender` or `contract-caller` is not the protocol caller
(define-constant ERR_TRANSFER_INDEX_PREFIX (unwrap-err! ERR_TRANSFER (err true)))
(define-constant ERR_TRANSFER (err u6))
(define-constant ERR_TRANSFER_INDEX_PREFIX u1000)

(define-fungible-token sbtc-token)
(define-fungible-token sbtc-token-locked)
Expand All @@ -13,15 +11,13 @@

;; --- Protocol functions

;; #[allow(unchecked_data)]
(define-public (protocol-transfer (amount uint) (sender principal) (recipient principal))
(begin
(try! (contract-call? .sbtc-registry validate-protocol-caller contract-caller))
(ft-transfer? sbtc-token amount sender recipient)
)
)

;; #[allow(unchecked_data)]
(define-public (protocol-lock (amount uint) (owner principal))
(begin
(try! (contract-call? .sbtc-registry validate-protocol-caller contract-caller))
Expand All @@ -30,7 +26,6 @@
)
)

;; #[allow(unchecked_data)]
(define-public (protocol-unlock (amount uint) (owner principal))
(begin
(try! (contract-call? .sbtc-registry validate-protocol-caller contract-caller))
Expand All @@ -39,60 +34,52 @@
)
)

;; #[allow(unchecked_data)]
(define-public (protocol-mint (amount uint) (recipient principal))
(begin
(try! (contract-call? .sbtc-registry validate-protocol-caller contract-caller))
(ft-mint? sbtc-token amount recipient)
)
)

;; #[allow(unchecked_data)]
(define-public (protocol-burn (amount uint) (owner principal))
(begin
(try! (contract-call? .sbtc-registry validate-protocol-caller contract-caller))
(ft-burn? sbtc-token amount owner)
)
)

;; #[allow(unchecked_data)]
(define-public (protocol-burn-locked (amount uint) (owner principal))
(begin
(try! (contract-call? .sbtc-registry validate-protocol-caller contract-caller))
(ft-burn? sbtc-token-locked amount owner)
)
)

;; #[allow(unchecked_data)]
(define-public (protocol-set-name (new-name (string-ascii 32)))
(begin
(try! (contract-call? .sbtc-registry validate-protocol-caller contract-caller))
(ok (var-set token-name new-name))
)
)

;; #[allow(unchecked_data)]
(define-public (protocol-set-symbol (new-symbol (string-ascii 10)))
(begin
(try! (contract-call? .sbtc-registry validate-protocol-caller contract-caller))
(ok (var-set token-symbol new-symbol))
)
)

;; #[allow(unchecked_data)]
(define-public (protocol-set-token-uri (new-uri (optional (string-utf8 256))))
(begin
(try! (contract-call? .sbtc-registry validate-protocol-caller contract-caller))
(ok (var-set token-uri new-uri))
)
)

;; #[allow(unchecked_data)]
(define-private (protocol-mint-many-iter (item {amount: uint, recipient: principal}))
(ft-mint? sbtc-token (get amount item) (get recipient item))
)

;; #[allow(unchecked_data)]
(define-public (protocol-mint-many (recipients (list 200 {amount: uint, recipient: principal})))
(begin
(try! (contract-call? .sbtc-registry validate-protocol-caller contract-caller))
Expand All @@ -107,17 +94,17 @@
sender: principal,
to: principal,
memo: (optional (buff 34)) })))
(fold complete-individual-transfer recipients (ok u0))
(fold transfer-many-iter recipients (ok u0))
setzeus marked this conversation as resolved.
Show resolved Hide resolved
)

(define-private (complete-individual-transfer
(define-private (transfer-many-iter
(individual-transfer {
amount: uint,
sender: principal,
to: principal,
memo: (optional (buff 34)) })
(helper-response (response uint uint)))
(match helper-response
(result (response uint uint)))
(match result
index
(begin
(unwrap!
Expand All @@ -129,14 +116,13 @@
(err (+ ERR_TRANSFER_INDEX_PREFIX index)))
(ok (+ index u1))
)
err-response
(err err-response)
err-index
(err err-index)
)
)

;; sip-010-trait

;; #[allow(unchecked_data)]
(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34))))
(begin
(asserts! (or (is-eq tx-sender sender) (is-eq contract-caller sender)) ERR_NOT_OWNER)
Expand Down
1 change: 0 additions & 1 deletion contracts/contracts/sbtc-withdrawal.clar
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@
)
)

;; #[allow(unchecked_data)]
(define-private (complete-individual-withdrawal-helper (withdrawal
{request-id: uint,
status: bool,
Expand Down
20 changes: 10 additions & 10 deletions contracts/docs/sbtc-bootstrap-signers.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ the signer set is updated.

### signer-key-length-check

[View in file](../contracts/sbtc-bootstrap-signers.clar#L66)
[View in file](../contracts/sbtc-bootstrap-signers.clar#L65)

`(define-private (signer-key-length-check ((current-key (buff 33)) (helper-response (response uint uint))) (response uint uint))`

Signer Key Length Check
Checks that the length of each key is exactly 33 bytes #[allow(unchecked_data)]
Checks that the length of each key is exactly 33 bytes

<details>
<summary>Source code:</summary>
Expand Down Expand Up @@ -127,7 +127,7 @@ Checks that the length of each key is exactly 33 bytes #[allow(unchecked_data)]

### pubkeys-to-spend-script

[View in file](../contracts/sbtc-bootstrap-signers.clar#L81)
[View in file](../contracts/sbtc-bootstrap-signers.clar#L80)

`(define-read-only (pubkeys-to-spend-script ((pubkeys (list 128 (buff 33))) (m uint)) (buff 513))`

Expand Down Expand Up @@ -160,7 +160,7 @@ Generate the p2sh redeem script for a multisig

### pubkeys-to-hash

[View in file](../contracts/sbtc-bootstrap-signers.clar#L93)
[View in file](../contracts/sbtc-bootstrap-signers.clar#L92)

`(define-read-only (pubkeys-to-hash ((pubkeys (list 128 (buff 33))) (m uint)) (buff 20))`

Expand Down Expand Up @@ -189,7 +189,7 @@ hash160 of the p2sh redeem script

### pubkeys-to-principal

[View in file](../contracts/sbtc-bootstrap-signers.clar#L101)
[View in file](../contracts/sbtc-bootstrap-signers.clar#L100)

`(define-read-only (pubkeys-to-principal ((pubkeys (list 128 (buff 33))) (m uint)) principal)`

Expand Down Expand Up @@ -221,7 +221,7 @@ Given a set of pubkeys and an m-of-n, generate a principal

### pubkeys-to-bytes

[View in file](../contracts/sbtc-bootstrap-signers.clar#L112)
[View in file](../contracts/sbtc-bootstrap-signers.clar#L111)

`(define-read-only (pubkeys-to-bytes ((pubkeys (list 128 (buff 33)))) (buff 510))`

Expand All @@ -246,7 +246,7 @@ Concat a list of pubkeys into a buffer with length prefixes

### concat-pubkeys-fold

[View in file](../contracts/sbtc-bootstrap-signers.clar#L119)
[View in file](../contracts/sbtc-bootstrap-signers.clar#L118)

`(define-read-only (concat-pubkeys-fold ((pubkey (buff 33)) (iterator (buff 510))) (buff 510))`

Expand Down Expand Up @@ -280,7 +280,7 @@ for the public keys and 15 bytes for the length prefixes.

### bytes-len

[View in file](../contracts/sbtc-bootstrap-signers.clar#L131)
[View in file](../contracts/sbtc-bootstrap-signers.clar#L130)

`(define-read-only (bytes-len ((bytes (buff 33))) (buff 1))`

Expand All @@ -303,7 +303,7 @@ for the public keys and 15 bytes for the length prefixes.

### uint-to-byte

[View in file](../contracts/sbtc-bootstrap-signers.clar#L135)
[View in file](../contracts/sbtc-bootstrap-signers.clar#L134)

`(define-read-only (uint-to-byte ((n uint)) (buff 1))`

Expand Down Expand Up @@ -403,4 +403,4 @@ equal to 100% of the total number of signer keys.
))
```

[View in file](../contracts/sbtc-bootstrap-signers.clar#L139)
[View in file](../contracts/sbtc-bootstrap-signers.clar#L138)
Loading
Loading