Skip to content

Commit b5f5e9f

Browse files
authored
remove max payload check (#137)
1 parent 1afc7f3 commit b5f5e9f

File tree

6 files changed

+2
-188
lines changed

6 files changed

+2
-188
lines changed

programs/gateway/src/errors.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ pub enum Errors {
1313
DepositToAddressMismatch,
1414
#[msg("MessageHashMismatch")]
1515
MessageHashMismatch,
16-
#[msg("MemoLengthExceeded")]
17-
MemoLengthExceeded,
1816
#[msg("DepositPaused")]
1917
DepositPaused,
2018
#[msg("SPLAtaAndMintAddressMismatch")]

programs/gateway/src/instructions/deposit.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::{
22
contexts::{Call, Deposit, DepositSplToken},
33
errors::Errors,
44
state::RevertOptions,
5-
utils::verify_payload_size,
65
};
76

87
use anchor_lang::prelude::*;
@@ -18,8 +17,6 @@ pub fn handle_sol(
1817
revert_options: Option<RevertOptions>,
1918
deposit_fee: u64,
2019
) -> Result<()> {
21-
verify_payload_size(None, &revert_options)?;
22-
2320
let pda = &mut ctx.accounts.pda;
2421
require!(!pda.deposit_paused, Errors::DepositPaused);
2522
require!(receiver != [0u8; 20], Errors::EmptyReceiver);
@@ -55,8 +52,6 @@ pub fn handle_sol_with_call(
5552
revert_options: Option<RevertOptions>,
5653
deposit_fee: u64,
5754
) -> Result<()> {
58-
verify_payload_size(Some(&message), &revert_options)?;
59-
6055
handle_sol(ctx, amount, receiver, revert_options, deposit_fee)?;
6156

6257
msg!("Deposit and call executed with message = {:?}", message);
@@ -72,7 +67,6 @@ pub fn handle_spl(
7267
revert_options: Option<RevertOptions>,
7368
deposit_fee: u64,
7469
) -> Result<()> {
75-
verify_payload_size(None, &revert_options)?;
7670
let token = &ctx.accounts.token_program;
7771
let from = &ctx.accounts.from;
7872

@@ -127,8 +121,6 @@ pub fn handle_spl_with_call(
127121
revert_options: Option<RevertOptions>,
128122
deposit_fee: u64,
129123
) -> Result<()> {
130-
verify_payload_size(Some(&message), &revert_options)?;
131-
132124
handle_spl(ctx, amount, receiver, revert_options, deposit_fee)?;
133125

134126
msg!("Deposit SPL and call executed with message = {:?}", message);
@@ -144,7 +136,6 @@ pub fn handle_call(
144136
revert_options: Option<RevertOptions>,
145137
) -> Result<()> {
146138
require!(receiver != [0u8; 20], Errors::EmptyReceiver);
147-
verify_payload_size(Some(&message), &revert_options)?;
148139

149140
msg!(
150141
"Call executed: receiver = {:?}, message = {:?}, revert options = {:?}",

programs/gateway/src/utils/constants.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,5 @@ pub const ZETACHAIN_PREFIX: &[u8] = b"ZETACHAIN";
44
/// Default gas cost in lamports for SPL token operations
55
pub const DEFAULT_GAS_COST: u64 = 5000;
66

7-
// Maximum size of a message payload in bytes
8-
pub const MAX_DEPOSIT_PAYLOAD_SIZE: usize = 745;
9-
107
/// Deposit fee used when depositing SOL or SPL tokens.
118
pub const DEPOSIT_FEE: u64 = 2_000_000;

programs/gateway/src/utils/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ pub mod validate_message_hash;
66
pub mod verify_and_update_nonce;
77
pub mod verify_ata_match;
88
pub mod verify_authority;
9-
pub mod verify_payload_size;
109

1110
pub use constants::*;
1211
pub use prepare_account_metas::*;
@@ -16,4 +15,3 @@ pub use validate_message_hash::*;
1615
pub use verify_and_update_nonce::*;
1716
pub use verify_ata_match::*;
1817
pub use verify_authority::*;
19-
pub use verify_payload_size::*;

programs/gateway/src/utils/verify_payload_size.rs

Lines changed: 0 additions & 28 deletions
This file was deleted.

tests/gateway.ts

Lines changed: 2 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ const revertOptions = {
4444
const usdcDecimals = 6;
4545
const chain_id = 111111;
4646
const chain_id_bn = new anchor.BN(chain_id);
47-
const maxPayloadSize = 745;
4847

4948
async function mintSPLToken(
5049
conn: anchor.web3.Connection,
@@ -286,82 +285,6 @@ describe("Gateway", () => {
286285
}
287286
});
288287

289-
it("Deposit 1_000_000 USDC with above max payload size should fail", async () => {
290-
const pda_ata = await getOrCreateAssociatedTokenAccount(
291-
conn,
292-
wallet,
293-
mint.publicKey,
294-
pdaAccount,
295-
true
296-
);
297-
const tokenAccount = await getOrCreateAssociatedTokenAccount(
298-
conn,
299-
wallet,
300-
mint.publicKey,
301-
wallet.publicKey
302-
);
303-
try {
304-
await gatewayProgram.methods
305-
.depositSplTokenAndCall(
306-
new anchor.BN(2_000_000),
307-
Array.from(address),
308-
Buffer.from(Array(maxPayloadSize + 1).fill(1)),
309-
null
310-
)
311-
.accounts({
312-
from: tokenAccount.address,
313-
to: pda_ata.address,
314-
mintAccount: mint.publicKey,
315-
})
316-
.preInstructions([
317-
ComputeBudgetProgram.setComputeUnitLimit({ units: 400000 }),
318-
])
319-
.rpc({ commitment: "processed" });
320-
throw new Error("Expected error not thrown");
321-
} catch (err) {
322-
expect(err).to.be.instanceof(anchor.AnchorError);
323-
expect(err.message).to.include("MemoLengthExceeded");
324-
}
325-
});
326-
327-
it("Deposit 1_000_000 USDC with with max payload size", async () => {
328-
const pda_ata = await getOrCreateAssociatedTokenAccount(
329-
conn,
330-
wallet,
331-
mint.publicKey,
332-
pdaAccount,
333-
true
334-
);
335-
const tokenAccount = await getOrCreateAssociatedTokenAccount(
336-
conn,
337-
wallet,
338-
mint.publicKey,
339-
wallet.publicKey
340-
);
341-
let acct = await spl.getAccount(conn, pda_ata.address);
342-
const bal1 = acct.amount;
343-
344-
await gatewayProgram.methods
345-
.depositSplTokenAndCall(
346-
new anchor.BN(2_000_000),
347-
Array.from(address),
348-
Buffer.from(Array(maxPayloadSize).fill(1)),
349-
null
350-
)
351-
.accounts({
352-
from: tokenAccount.address,
353-
to: pda_ata.address,
354-
mintAccount: mint.publicKey,
355-
})
356-
.preInstructions([
357-
ComputeBudgetProgram.setComputeUnitLimit({ units: 400000 }),
358-
])
359-
.rpc({ commitment: "processed" });
360-
acct = await spl.getAccount(conn, pda_ata.address);
361-
const bal2 = acct.amount;
362-
expect(bal2 - bal1).to.be.eq(2_000_000n);
363-
});
364-
365288
it("Deposit 1_000_000 USDC to Gateway", async () => {
366289
let pda_ata = await getOrCreateAssociatedTokenAccount(
367290
conn,
@@ -541,7 +464,7 @@ describe("Gateway", () => {
541464
expect(err).to.be.instanceof(anchor.AnchorError);
542465
expect(err.message).to.include("NonceMismatch");
543466
const account4 = await spl.getAccount(conn, pda_ata);
544-
expect(account4.amount).to.be.eq(4_500_000n);
467+
expect(account4.amount).to.be.eq(2_500_000n);
545468
}
546469

547470
try {
@@ -583,7 +506,7 @@ describe("Gateway", () => {
583506
expect(err).to.be.instanceof(anchor.AnchorError);
584507
expect(err.message).to.include("ConstraintAssociated");
585508
const account4 = await spl.getAccount(conn, pda_ata);
586-
expect(account4.amount).to.be.eq(4_500_000n);
509+
expect(account4.amount).to.be.eq(2_500_000n);
587510
}
588511
});
589512

@@ -3694,23 +3617,6 @@ describe("Gateway", () => {
36943617
}
36953618
});
36963619

3697-
it("Deposit and call with above max payload size should fail", async () => {
3698-
try {
3699-
await gatewayProgram.methods
3700-
.depositAndCall(
3701-
new anchor.BN(1_000_000_000),
3702-
Array.from(address),
3703-
Buffer.from(Array(maxPayloadSize + 1).fill(1)),
3704-
revertOptions
3705-
)
3706-
.rpc();
3707-
throw new Error("Expected error not thrown");
3708-
} catch (err) {
3709-
expect(err).to.be.instanceof(anchor.AnchorError);
3710-
expect(err.message).to.include("MemoLengthExceeded");
3711-
}
3712-
});
3713-
37143620
it("Call with empty address receiver should fail", async () => {
37153621
try {
37163622
await gatewayProgram.methods
@@ -3723,54 +3629,6 @@ describe("Gateway", () => {
37233629
}
37243630
});
37253631

3726-
it("Call with above max payload size should fail", async () => {
3727-
try {
3728-
await gatewayProgram.methods
3729-
.call(
3730-
Array.from(address),
3731-
Buffer.from(Array(maxPayloadSize + 1).fill(1)),
3732-
revertOptions
3733-
)
3734-
.rpc();
3735-
throw new Error("Expected error not thrown");
3736-
} catch (err) {
3737-
expect(err).to.be.instanceof(anchor.AnchorError);
3738-
expect(err.message).to.include("MemoLengthExceeded");
3739-
}
3740-
});
3741-
3742-
it("Call with max payload size", async () => {
3743-
const txsig = await gatewayProgram.methods
3744-
.call(
3745-
Array.from(address),
3746-
Buffer.from(Array(maxPayloadSize).fill(1)),
3747-
revertOptions
3748-
)
3749-
.preInstructions([
3750-
ComputeBudgetProgram.setComputeUnitLimit({ units: 400000 }),
3751-
])
3752-
.rpc({ commitment: "processed" });
3753-
await conn.getParsedTransaction(txsig, "confirmed");
3754-
});
3755-
3756-
it("Deposit and call with max payload size", async () => {
3757-
const bal1 = await conn.getBalance(pdaAccount);
3758-
const txsig = await gatewayProgram.methods
3759-
.depositAndCall(
3760-
new anchor.BN(1_000_000_000),
3761-
Array.from(address),
3762-
Buffer.from(Array(maxPayloadSize).fill(1)),
3763-
revertOptions
3764-
)
3765-
.preInstructions([
3766-
ComputeBudgetProgram.setComputeUnitLimit({ units: 400000 }),
3767-
])
3768-
.rpc({ commitment: "processed" });
3769-
await conn.getParsedTransaction(txsig, "confirmed");
3770-
const bal2 = await conn.getBalance(pdaAccount);
3771-
expect(bal2 - bal1).to.be.gte(1_000_000_000);
3772-
});
3773-
37743632
it("Deposit and call", async () => {
37753633
let bal1 = await conn.getBalance(pdaAccount);
37763634
const txsig = await gatewayProgram.methods

0 commit comments

Comments
 (0)