Skip to main content

Avoid fromat! macro usage


The format! macro is not recommended. A custom error is recommended instead.

Exploit Scenario

Consider the following ink! contract:

pub fn crash(&self) -> Result<(), Error> {
Err(Error::FormatError {
msg: (format!("{:?}", "false")),

The problem arises from the use of the format! macro. This is used to format a string with the given arguments. Returning a custom error is desirable.

The vulnerable code example can be found here.


Create a custom error to avoid using the macro.