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

fix: withdraw spl without receiver ata #65

Closed
wants to merge 1 commit into from

Conversation

skosito
Copy link
Contributor

@skosito skosito commented Nov 30, 2024

Remove rent payer logic with withdraw spl and add log but still succeed tx so it can be parsed on zetaclient

@skosito skosito changed the title withdraw spl without receiver ata fix: withdraw spl without receiver ata Nov 30, 2024
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 0% with 13 lines in your changes missing coverage. Please review.

Project coverage is 7.32%. Comparing base (2c18683) to head (623fdf8).

Files with missing lines Patch % Lines
programs/protocol-contracts-solana/src/lib.rs 0.00% 13 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##            main     #65      +/-   ##
========================================
+ Coverage   6.53%   7.32%   +0.79%     
========================================
  Files          1       1              
  Lines        398     355      -43     
========================================
  Hits          26      26              
+ Misses       372     329      -43     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -367,73 +364,30 @@ pub mod gateway {
Errors::SPLAtaAndMintAddressMismatch,
);

// test whether the recipient_ata is created or not; if not, create it
// test whether the recipient_ata is created or not; if not log and exit successfully
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we explain why we log and exit successfully instead of making the tx fails

Copy link
Contributor

@brewmaster012 brewmaster012 Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lumtis the core issue here is the possibility of a "legitimate authorized failed withdraw tx" (for a lack of better word) which means the withdraw cannot be accomplished and we tried, as opposed to other "illegitimate unauthorized failed withdraw" which may include: wrong/fake TSS signature, replay using a wrong nonce).

For "authorized failed withdraw tx", zetaclient should report as "revert" like in Ethereum case so the solana nonce on zetacore will increment and we move on. However if the Solana tx actually failed/reverted, the program nonce will not increment. In this case we need to allow the solana tx to succeed, but without transfering SPL tokens and indicate in logs that it "reverted".

For "unauthorized failed withdraw", the correct behavior is that zetaclients would ignore such tx as they are not authorized. The solana program simply fail them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I think still make sense to precise this in the comment

@lumtis lumtis marked this pull request as draft December 2, 2024 17:12

let rentPayerPdaBal1 = await conn.getBalance(rentPayerPda);
expect(rentPayerPdaBal0-rentPayerPdaBal1).to.be.eq(to_ata_bal); // rentPayer pays rent
expect(to_ata_bal).to.be.eq(0); // still 0 balance
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps verify the log here
zetaclient will need to the same

msg!(
"Refunding the rent paid by the signer {:?}",
ctx.accounts.signer.to_account_info().key
msg!("recipient ATA account does not exist");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thinking about how zetaclient should parse and validate this--
grep the log?
can it be tricked? (for example, the user included two intructions in the same tx, one is from their attack program which emits the same log above, and the second instruction is the withdraw spl that actually points to a valid ata address so transfer actually succeeds)

@skosito
Copy link
Contributor Author

skosito commented Dec 3, 2024

solved in: #67

@skosito skosito closed this Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants