eos icon indicating copy to clipboard operation
eos copied to clipboard

Action to delegatebw causes addition overflow

Open PhillipHamnett opened this issue 8 years ago • 3 comments

The following minimum working code in a smart contract:

    asset stake_cpu_quantity(1);
    asset stake_net_quantity(1);
    eosio::action out(eosio::permission_level{_self, N(active) }, N(eosio), N(delegatebw), std::make_tuple(_self, N(receiver), stake_net_quantity, stake_cpu_quantity, false));
    out.send();

causes the following error: wasm_interface.cpp:929 eosio_assert ] message: addition overflow

The error appears to be thrown from the operator+= function from the eosio::asset struct. However, I can not understand or see why this is the case.

I have additionally tested that the assert does not come from within the delegatebw function or the changebw function in delegate_bandwidth.cpp, but some time after that.

PhillipHamnett avatar Aug 16 '18 16:08 PhillipHamnett

Update: I have noticed that if you call delegatebw from the command line, using the smart contract as the "from" field, then it also gives the addition overflow assert. However it does not do this for my non-smart-contract account.

Calling delegatebw with the smart contract account also works fine as long as the contract isn't loaded. So it isn't a problem with the permission of the contract or something along those lines

PhillipHamnett avatar Aug 16 '18 21:08 PhillipHamnett

The problem also does not occur within the contract if I call undelegate bandwidth on myself:

   asset stake_cpu_quantity(1);
    asset stake_net_quantity(1);
    eosio::action out(eosio::permission_level{_self, N(active) }, N(eosio), N(undelegatebw), std::make_tuple(_self, _self, stake_net_quantity, stake_cpu_quantity, false));
    out.send();

In this case, the output is as expected

PhillipHamnett avatar Aug 16 '18 21:08 PhillipHamnett

I solved the problem. When calling delegatebw, the transfer function is also called. I have a function that is executed when a transfer occurs, but as the memo was not as expected, it causes this addition overflow

PhillipHamnett avatar Aug 16 '18 22:08 PhillipHamnett