Reject from smart contract with pre-defined error message?

Lol, I appreciate the kind words in your tweet. :smile:

This is a smart solution, and if you can afford the additional opcode budget and it’s beneficial for you then you should definitely use it. Since you brought this up I had been meaning to create a minimal demo that parses the error and reads the PC, mapping it to a range which provides a human readable error. Although it’s very tricky and can only really be done by hand atm without new tooling.

Unfortunately the bad news, we have seen this type of trick before, and I think it was the AlgoFi team who introduced it to me. It was something similar to this:

def magic_assert(a: Expr) -> Expr:
    return Assert(And(a, Int(currentframe().f_back.f_lineno)))

They use it when they’re testing and debugging their contracts, so it returns back the line number of their code.

1 Like