[solved] MovePrimitiveRuntimeError while contract execution, gas reduced

Hi Friends! Here is a simple contract which holds a list of wallets to whom money (custom coin) should be spread and two entry functions. One adds given wallet to the list, another mints and sends money to all people in the list.

With this second function I got error:

Error calling module: Failure {
    error: "MovePrimitiveRuntimeError(Some(MoveLocation { module: ModuleId { address: 0000000000000000000000000000000000000002, name: Identifier(\"tx_context\") }, function: 4, instruction: 0, function_name: Some(\"derive_id\") }))",

Any advice on this, please? What may I be missing here? Also I noticed that gas is still wasted despite transaction failed - is this expected behavior? P.S. the custom coin is defined in different module but that one is almost a copy of coin.move example from github repo, just with additional function to expose treasury for use in other functions.

UPD: most of code was removed as the mistake is extremely silly :slight_smile:

    while (i < n) {
      let rec = vector::borrow(& mgr.records, i);
      let c = coin::mint(mytoken::treasury(adm), rec.due, ctx);
      transfer::transfer(c, rec.wallet)

Sorry, Friends, false alarm!

I obviously have forgotten increment of the index in the while loop and such error seemingly may be manifestation of the endless loop!


Also, I believe the reduction of gas for failed transactions is valid. Nodes are payed through incentives (i.e. gas) and they are still processing your transaction even if the contract has an exception.


Yep, retrospectively I agree :slight_smile: especially since the bug is due to contract creator/caller, node owners shouldn’t be bereft of the wages because of the other’s mistakes