cairo-contracts icon indicating copy to clipboard operation
cairo-contracts copied to clipboard

Ownable: split assertion checks in two statements

Open achab opened this issue 2 years ago • 0 comments

A misleading error message can happen when calling the guard assert_only_owner.

📝 Details

The function assert_only_owner currently contains two assertion statements in the same with_attr block. The associated error message only concerns the second statement. Then, when this function is called with a caller being 0, the error message is "Ownable: caller is not the owner", which is misleading.

🔢 Code to reproduce bug

Two files to reproduce it:

  • main.cairo

    %lang starknet
    
    from starkware.cairo.common.cairo_builtins import HashBuiltin
    from openzeppelin.access.ownable.library import Ownable
    
    func sum{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}(a : felt, b : felt) -> (sum : felt):
        Ownable.assert_only_owner()
        let (sum) = a + b
        return (sum)
    end
    
  • test_main.cairo

    from starkware.cairo.common.cairo_builtins import HashBuiltin
    
    from main import sum
    
    func test_sum{
        syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr
    }():
        sum(1, 2) # this raises "Ownable: caller is not the owner" instead of a message about zero address
        return ()
    end
    
    

achab avatar Aug 09 '22 11:08 achab