4

In Solidity, people use a SafeMath library to prevent overflow/underflow attack. So, I wonder what's the best way to prevent overflow/underflow attack for EOS contract. Is there an easy-to-use SafeMath library available?

1 Answer 1

1

EOS uses C ++, and C ++ assert can be used to check for overflow or underflow.

ex) assert( quantity + a.quantity >= a.quantity,"integer overflow adding token balance" );

See the link below for this.

https://steemit.com/eos/@dan/eos-example-exchange-contract-and-benefits-of-c

Also, eosio provides eosio_assert to enable various assertions.

2
  • 1
    That check only works for unsigned types. Optimizing compilers often strip out that check on signed types since ISO C and ISO C++ make signed overflow undefined behavior. Asset uses signed. Commented Jun 24, 2018 at 20:31
  • 1
    AFAIK assert() is a macro and not active in the production compiled code, instead it is preprocessed out. So this would not prevent attack. Commented Jun 25, 2018 at 9:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.