From e2d7e9e858afd975a5c97c5cc4b6f6207bb57f17 Mon Sep 17 00:00:00 2001 From: Tokenwrap Date: Tue, 8 Oct 2024 11:12:08 +0200 Subject: [PATCH] solana: Validation of the new spl metadata account Problem: Attestation is failing for tokens that were created recently. Cause: Metaplex has resized the SPL token metadata account from 679 bytes to 607 bytes in the commit (6b2e869) However, the token-bridge is still using the older version of the SPL token metadata and validating the size based on the older constant. As a result, this check fails to attest tokens that are using the new metadata accounts. Solution: To resolve this, I have added an additional condition with the new metadata length constant, allowing the validation to pass if the SPL token has either of the two metadata account lengths. --- solana/modules/token_bridge/program/src/accounts.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/solana/modules/token_bridge/program/src/accounts.rs b/solana/modules/token_bridge/program/src/accounts.rs index 4dc55f43ee..11312c974c 100644 --- a/solana/modules/token_bridge/program/src/accounts.rs +++ b/solana/modules/token_bridge/program/src/accounts.rs @@ -106,6 +106,9 @@ impl<'b> Seeded<&SplTokenMetaDerivationData> for SplTokenMeta<'b> { } } +//New data length of spl token metadata account +pub const NEW_MAX_METADATA_LEN: usize = 607; + /// This method removes code duplication when checking token metadata. When metadata is read for /// attestation and transfers, Token Bridge does not invoke Metaplex's Token Metadata program, so /// it must validate the account the same way Token Metadata program does to ensure the correct @@ -128,7 +131,7 @@ pub fn deserialize_and_verify_metadata( } // Account must be the expected Metadata length. - if info.data_len() != spl_token_metadata::state::MAX_METADATA_LEN { + if info.data_len() != spl_token_metadata::state::MAX_METADATA_LEN && info.data_len() != NEW_MAX_METADATA_LEN { return Err(TokenBridgeError::InvalidMetadata.into()); }