0f / 0F-ARK-2108

0 stars 0 forks source link

0f-ARK-012: Redundancy with (as-contract) constructs #13

Open lgalabru opened 3 years ago

lgalabru commented 3 years ago

Context

When a closure is passed to (as-contract ...), all the subsequent calls to tx-sender refers to the contract calling this construct. In multiple contracts, the following pattern is constructed:

(as-contract (contract-call? <token> transfer u1 (as-contract tx-sender) recipient none)))

The inner (as-contract ...) is unnecessary.

Instances

(define-public (redeem-tokens (usda-amount uint) (diko-amount uint))
    ...
    (try! (as-contract (contract-call? .arkadiko-token transfer diko-amount (as-contract tx-sender) (contract-call? .arkadiko-dao get-payout-address) none)))
    (as-contract (contract-call? .usda-token transfer usda-amount (as-contract tx-sender) (contract-call? .arkadiko-dao get-payout-address) none))
      )
    ...
    (as-contract (contract-call? .usda-token transfer usda-amount (as-contract tx-sender) (contract-call? .arkadiko-dao get-payout-address) none))
(define-public (redeem-usda (usda-amount uint))
    ...
    (as-contract (contract-call? .usda-token transfer usda-amount (as-contract tx-sender) (contract-call? .arkadiko-dao get-payout-address) none))
(define-public (request-stx-to-stack (name (string-ascii 256)) (requested-ustx uint))
    ...
    (as-contract
      (stx-transfer? requested-ustx (as-contract tx-sender) (unwrap-panic (contract-call? .arkadiko-dao get-qualified-name-by-name name))) ;; redundancy

Low-level severity issues can cause minor impact and or are just warnings that can remain unfixed for now. It would be better to fix these issues at some point in the future.

philiphacks commented 3 years ago

@lgalabru Thanks!

So we could just write e.g. (as-contract (contract-call? .usda-token transfer usda-amount tx-sender (contract-call? .arkadiko-dao get-payout-address) none))?

nieldeckx commented 3 years ago

Fixes in: https://github.com/arkadiko-dao/arkadiko/pull/245