Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle errors when sending tokens within Aurora to NEAR #269

Open
mfornet opened this issue Sep 14, 2021 · 9 comments · Fixed by #311
Open

Handle errors when sending tokens within Aurora to NEAR #269

mfornet opened this issue Sep 14, 2021 · 9 comments · Fixed by #311
Assignees
Labels
A-connector Area: Issues that relate to the connector. A-precompiles Area: Issues that relate to the precompiles. C-incident Category: Issues that are related to or have caused an incident P-critical Priority: critical

Comments

@mfornet
Copy link
Contributor

mfornet commented Sep 14, 2021

Currently the way exit precompiles work, is that it:

  1. verifies the amount of tokens is owned by the user inside Aurora
  2. burns those tokens
  3. schedule a cross contract call to mint/create withdrawal event on NEAR

Currently if step 3) fails for some reason, tokens are burnt within aurora, and not minted on NEAR, so basically they are lost. We need to handle failures on step 3. This is, we schedule yet another call after the exit call where we see if the tx succeeded or not, in case it didn't succeed funds should be refunded.

This was first detected on this tx. Where ft_transfer failed because receiver account was not registered in the NEP-141 tokens. Currently this tokens are being held by aurora account, but they were not refunded to the user.

@mfornet mfornet added P-critical Priority: critical C-incident Category: Issues that are related to or have caused an incident A-precompiles Area: Issues that relate to the precompiles. A-connector Area: Issues that relate to the connector. labels Sep 14, 2021
@joshuajbouw
Copy link
Contributor

That is rather unfortunate. We will look into this.

@mrLSD mrLSD self-assigned this Sep 20, 2021
@sept-en
Copy link
Contributor

sept-en commented Sep 20, 2021

Update on this: the tokens were manually refunded to the user on this tx

@mrLSD
Copy link
Member

mrLSD commented Sep 22, 2021

This is, we schedule yet another call after the exit call where we see if the tx succeeded or not, in case it didn't succeed funds should be refunded.

Seems we can't do that. The main reason promises are async. Also, we can't analyze TX inside aurora contract. We should have some mechanism outside aurora contract that will check exit precompiles outcome and fire new call for a refund if something wrong.

Obvious solutions:

  1. less reliable but simple - we can do it via front-end action
  2. We can implement and run it as some service that can analyze exit precompiles incidents and fire-related actions to solve it.

@mfornet, @joshuajbouw let's choose the best solution for that.

@birchmd
Copy link
Member

birchmd commented Sep 22, 2021

@mrLSD I think you should be able to attach a callback to the promise (using the then API). That callback should check for success of the previous call and revert the transfer to the precompile on failure (it can do this because it should happen within the Aurora engine contract itself)

I.e. you should be able to do was @mfornet suggested in the issue description using a callback

(Sorry I did not intend to close this issue with my comment, so I reoopened it)

@birchmd birchmd closed this as completed Sep 22, 2021
@birchmd birchmd reopened this Sep 22, 2021
@mrLSD
Copy link
Member

mrLSD commented Sep 22, 2021

I investigated that, and still have questions.

So, the callback function for failing case for that promise looks really dangerous. It seems possible bugs, which are difficult to catch.

Anyway, we have promise schedule:

let promise: Vec<u8> = PromiseCreateArgs {

So I'll implement a dependent promise burn from aurora account and mint to the receiver account.

But do we really clear that the approach doesn't have pitfalls?
@sept-en @joshuajbouw

@birchmd
Copy link
Member

birchmd commented Sep 23, 2021

So I'll implement a dependent promise burn from aurora account and mint to the receiver account.

No, this is not what you should do. The transfer that needs to be reverted in the the engine itself. You need to transfer the tokens back from the precompile address to the user's address in the engine. The NEP-141 balances do not need to be changed because this flow only triggers when the NEP-141 transaction was unsuccessful.

So, the callback function for failing case for that promise looks really dangerous. It seems possible bugs, which are difficult to catch.

I'm not sure what you are worried about. Could you elaborate more about the danger here?

@birchmd
Copy link
Member

birchmd commented Sep 24, 2021

@mfornet Could you take a look at #284 (comment) ? Have you thought about the case where the exit precompile was invoked as part of a larger transaction?

@mfornet
Copy link
Contributor Author

mfornet commented Sep 29, 2021

@birchmd answered on this comment: #284 (comment)

@birchmd
Copy link
Member

birchmd commented Sep 29, 2021

@mfornet , I've replied #284 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-connector Area: Issues that relate to the connector. A-precompiles Area: Issues that relate to the precompiles. C-incident Category: Issues that are related to or have caused an incident P-critical Priority: critical
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants