Skip to content

Latest commit

 

History

History
67 lines (50 loc) · 2.12 KB

11-unused-let-variables.md

File metadata and controls

67 lines (50 loc) · 2.12 KB

Unused Let Variables

Description

Do not declare variables inside a let function if you will not used it. This will optimize the contract's code and reduce gas.

Exploit Scenario

(define-public  (endPlay) 
    (let (
        (first (get j (unwrap-panic (map-get? sorted {o: u0}))))
        (second (get j (unwrap-panic (map-get? sorted {o: u1}))))
		    (not-used u8)
		)
        (begin 
            (asserts!  (> (var-get revelations ) u1) (err "It can not be reveal yet!")) 
            
            (if (is-eq (var-get booleans_played) 0) 
                (begin (map-set to_pay  first  u0 ) 
                    (map-set to_pay  second (var-get pozo) ) )
                (begin (map-set to_pay  second u0) 
                    (map-set to_pay  first (var-get pozo) ) )
            )
        ) 
        (ok true)
    )
)

The vulnerable code example can be found here.

Remediation

(define-public  (endPlay) 
    (let (
        (first (get j (unwrap-panic (map-get? sorted {o: u0}))))
        (second (get j (unwrap-panic (map-get? sorted {o: u1}))))
		)
        (begin 
            (asserts!  (> (var-get revelations ) u1) (err "It can not be reveal yet!")) 
            
            (if (is-eq (var-get booleans_played) 0) 
                (begin (map-set to_pay  first  u0 ) 
                    (map-set to_pay  second (var-get pozo) ) )
                (begin (map-set to_pay  second u0) 
                    (map-set to_pay  first (var-get pozo) ) )
            )
        ) 
        (ok true)
    )
)

The remediated code example can be found here.