#Sending Mina to zkApp

1 messages · Page 1 of 1 (latest)

south cargo
#

Gives error:
WalletZkApp › send Mina › should able to send Mina

Invalid fee excess.
This means that balance changes in your transaction do not sum up to the amount of fees needed.
Here's the list of balance changes:

Account update #1) -3.00 MINA
Account update #2) 2.00 MINA

Total change: -1.00 MINA

If there are no new accounts created in your transaction, then this sum should be equal to 0.00 MINA.
If you are creating new accounts -- by updating accounts that didn't exist yet --
then keep in mind the 1.00 MINA account creation fee, and make sure that the sum equals
-1.00 times the number of newly created accounts.

Raw list of errors: [[],[["Cancelled"]],[["Invalid_fee_excess"],["Update_not_permitted_access"]]]
describe('send Mina', () => {
    it('should able to send Mina', async () => {
      await localDeploy();

      const amount = 2_000_000_000;
      const transactionFee = 100_000_000;

      const tx = await Mina.transaction({sender: senderAccount, fee: transactionFee}, () => {
        let accountUpdate: AccountUpdate =
          AccountUpdate.fundNewAccount(senderAccount);
        accountUpdate.send({ to: zkAppAddress, amount: amount });
      });
      await tx.prove();
      await tx.sign([senderKey]).send();

      const updatedBalance = Mina.getBalance(zkApp.address);
      expect(updatedBalance).toEqual(UInt64.from(1e9 * 2));
    });
  });
#

Sender: ({ privateKey: senderKey, publicKey: senderAccount } = Local.testAccounts[5]);

#

I've change the code, because zkApp doens't need to get fund first, but still gerring error:

        let accountUpdate: AccountUpdate = AccountUpdate.createSigned(senderAccount);
        accountUpdate.send({ to: zkAppAddress, amount: amount });
      });
      await tx.prove();
      await tx.sign([senderKey]).send();```

 WalletZkApp › send Mina › should able to send Mina

    [[],[["Cancelled"]],[["Update_not_permitted_access"]]]


**Permissions:**

init() {
super.init();
this.account.permissions.set({
...Permissions.default(),
access: Permissions.proofOrSignature(),
editActionState: Permissions.proofOrSignature(),
editState: Permissions.proofOrSignature(),
send: Permissions.proofOrSignature(),
receive: Permissions.none(),
});
this.committedPasswords.set(Field(0));
this.committedGuardians.set(Field(0));
this.committedNominees.set(Field(0));
}```

umbral wraith
#

Hey @south cargo . Have you found the cause of this? I am also facing this error.

stiff swallow
#

You can see explanations in #1183684692113903647 message

#

It seems like you send MINA to an already existing account and do not need to add an account creation fee:

Example of how to check if account exists:

const zkApp = new MinaNFTNameServiceContract(nameService.address);
const tokenId = zkApp.token.id;
await fetchAccount({ publicKey: address, tokenId });
const hasAccount = Mina.hasAccount(address, tokenId);

const transaction = await Mina.transaction(
      { sender, fee: await MinaNFT.fee(), memo: "minanft.io", nonce },
      () => {
        if (!hasAccount) AccountUpdate.fundNewAccount(sender);
        zkApp.mint(mintData);
      }
    );
scarlet imp
stiff swallow
scarlet imp
stiff swallow
# scarlet imp By "stateless" I think you mean SmartContract with no state variables, just meth...

You are right; stateless means the contract without state variables. Still, the contract can have non-state variables. For example, I have a public key written to the contract state that is used to verify signatures. The value of this public key is not being changed by the usual transactions, so it can be considered quasi-constant:
https://github.com/dfstio/minanft-lib/blob/master/src/contract/names.ts#L71

scarlet imp
#

I see. So you can have methods in that contract that use that public key but do not change state in any other way. I mean, the public key is set only once, and then you can dispatch many transactions on the same block using the other "stateless" methods. Very good ! Thanks

scarlet imp
#

To put many transactions in the same block I use a set of running workers (dispatchers) each one running with its own deployer/sender account. And my "custom" sequencer coordinates the workers and manages the transactions queue. But this has the limitation that you can put at most one transaction per worker. On the other side it does not need stateless contracts. But your solution is quite awesome really !

#

I mean workers and sequencer are running as a service (not in the browser)

stiff swallow
scarlet imp
#

Mmm. This I don't get " I put nonce into the code to be able to upgrade the system and use the same private key for minting several NFTs at the same time". But minting an NFT does not imply doing state changes ?

stiff swallow
scarlet imp
#

Ok. Will look in more detail at your code. Don't want to waste more of your time . Thanks a lot !

stiff swallow
vocal atlas
#

@scarlet imp if you're already struggling with concurency and/or race conditions, you should give our docs a read as well 🙂

scarlet imp
vocal atlas
#

what is a dispatcher in your model?

scarlet imp
vocal atlas
#

all you have to do is use sequence state as a mempool if you'd like data availability

#

how did you solve data availability in your custom sequencer?

scarlet imp
vocal atlas
#

who pays the fee?

scarlet imp
#

Socialcap accounts for now pay the fee

vocal atlas
#

that really isnt data availability unless its replicated and attested to by e.g, a comittee

#
scarlet imp
#

Well, it works for the app now. It is centralized (I suppose just like in Protokit) but can be changed to a decentralized solution in the future.

vocal atlas
stiff swallow
#

KYC cost is definitely higher than the transaction cost))

scarlet imp
vocal atlas
#

and how did you solve the concurency issues steming from working with merkle trees? do you use sequence state?

scarlet imp
#

The UI sends a RPC call to the API, wich then posts a transaction to the Sequencer, using a named queue. So transactions are dispatched in sequence, but using multiple workers. So changes to the tree are done in sequence and persisted every time

vocal atlas
#

i get that, we do it the other way around, the sequencer exposes an endpoint for a mempool, and workers come into play only when a block is produced and you need paralelism

scarlet imp
scarlet imp
vocal atlas
#

@scarlet imp can you please point me to a place in your code where you consume the witnesses and the data from your merkle storage?

scarlet imp
#
    let claimNullifier = await getJSON<ClaimElectorNullifier>(`claim-${claimUid}`, 
      new ClaimElectorNullifier()
    ) as ClaimElectorNullifier;
    const claimRoot = claimNullifier.root();
    const claimWitness = claimNullifier.witness(ClaimElectorNullifierLeaf.key(
      electorPuk, claimUidf
    ));
#

The nullifiers are created in different moments, when assigning electors to a claim for example.

vocal atlas
#

do you have a spec for the system from a high level perspective?

#

or at least a tl;dr; on the supported user flows? i want to rewrite it in protokit to show you what you're missing on

#

@scarlet imp what happens in your system if someone frontruns your sequencer by providing an L1 transaction with a higher fee?

#

i mean under the assumption that your sequencer is proving L1 smart contract transactions before sending them to the L1 mempool?

scarlet imp
#

This is the general voting process. Would love to have an idea of how to do this on Protokit 🙂 Some details are not included here and maybe some arrows are a little outdated but in general this is the process

scarlet imp
vocal atlas
#

i mean users do generate the nullifiers themselves and may choose to publish them

#

or a malicious user may use their nullifier to frontrun the sequencer and re-cast their vote in a different manner

scarlet imp
vocal atlas
#

i also assume none of the voting is private, is it? as in private as in users creating the proofs of voting on their devices

#

doesnt the nullifier have to be generated by a wallet, and then verified in circuit? in my understanding nullifiers are bound to a message & public key

scarlet imp
scarlet imp
#

In the contrats there are examples of how are they being used

#

@vocal atlas , thanks for your comments. Don't want to use more of your time 🙂 As I said, would love to have a better idea of how to use Protokit for Socialcap 🙏🏻 As soon as we release in testnet will give it a serious try !

vocal atlas
#

i’ll try to use the diagram you’ve shared to implement a sample runtime that supports a basic user journey through socialcap

vocal atlas
#

do you want a livestream in the zkapp hangout while i do it? if you have 20mins of time

scarlet imp
vocal atlas
#

im streaming in zkapp hangouts if anyone is interested 🙂

vocal atlas