Race condition possibility in asynchronous NEAR cross contract calls

137 views Asked by At

Let's say:

  1. I have two smart contracts X and Y. The cross-contract (XSS) flow is Alice -> X -> Y.
  2. Y transfers some tokens to X. The XSS to Y does not return how many tokens were transferred, so X needs to check its balance using ft_balance_of().
  3. The tokens have to be transferred back to Alice.

Is it safe to transfer the entire token balance of X, as returned by ft_balance_of()? Say that Bob calls X around the same time as Alice. Since XSS on NEAR is async,can Alice get credited with Bob's funds?

Additional context

My contract X is calling ft_transfer_call() on Ref exchange (instant swap). Apparently the promise returns how many tokens were consumed, not how many returned.

0

There are 0 answers