Skip to main content

Assert violation


The assert! macro can cause the contract to panic. This is not a good practice.

Exploit Scenario

Consider the following ink! contract:

pub fn assert_if_greater_than_10(&self, value: u128) -> bool {
assert!(value <= 10, "value should be less than 10");

The problem arises from the use of the assert! macro, if the condition is not met, the contract panics.

The vulnerable code example can be found here.


Avoid the use of assert! macro. Instead, use a proper error and return it.

The remediated code example can be found here.