Browse Source

Revert "lang: Make Anchor use fallback function instead of panicking if ix data.len() is < `8` (#1721)" (#1748)

Paul 3 năm trước cách đây
mục cha
commit
3d0560db2c

+ 0 - 1
CHANGELOG.md

@@ -31,7 +31,6 @@ The minor version will be incremented upon a breaking change and the patch versi
 * avm: `avm install` switches to the newly installed version after installation finishes ([#1670](https://github.com/project-serum/anchor/pull/1670)).
 * spl: Re-export the `spl_token` crate ([#1665](https://github.com/project-serum/anchor/pull/1665)).
 * lang, cli, spl: Update solana toolchain to v1.9.13 ([#1653](https://github.com/project-serum/anchor/pull/1653)).
-* lang: Use fallback function if ix data length smaller than `8` instead of panicking ([#1721](https://github.com/project-serum/anchor/pull/1721)).
 * lang: `Program` type now deserializes `programdata_address` only on demand ([#1723](https://github.com/project-serum/anchor/pull/1723)).
 
 ## [0.23.0] - 2022-03-20

+ 17 - 27
lang/syn/src/codegen/program/dispatch.rs

@@ -143,43 +143,33 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
             // Split the instruction data into the first 8 byte method
             // identifier (sighash) and the serialized instruction data.
             let mut ix_data: &[u8] = data;
-            let sighash: Option<[u8; 8]> = {
+            let sighash: [u8; 8] = {
                 let mut sighash: [u8; 8] = [0; 8];
-                if ix_data.len() < 8 {
-                    None
-                } else {
-                    sighash.copy_from_slice(&ix_data[..8]);
-                    ix_data = &ix_data[8..];
-                    Some(sighash)
-                }
+                sighash.copy_from_slice(&ix_data[..8]);
+                ix_data = &ix_data[8..];
+                sighash
             };
 
             // If the method identifier is the IDL tag, then execute an IDL
             // instruction, injected into all Anchor programs.
             if cfg!(not(feature = "no-idl")) {
-                if let Some(sighash) = sighash {
-                    if sighash == anchor_lang::idl::IDL_IX_TAG.to_le_bytes() {
-                        return __private::__idl::__idl_dispatch(
-                            program_id,
-                            accounts,
-                            &ix_data,
-                        );
-                    }
+                if sighash == anchor_lang::idl::IDL_IX_TAG.to_le_bytes() {
+                    return __private::__idl::__idl_dispatch(
+                        program_id,
+                        accounts,
+                        &ix_data,
+                    );
                 }
             }
+
             match sighash {
-                Some(sighash) => {
-                    match sighash {
-                        #ctor_state_dispatch_arm
-                        #(#state_dispatch_arms)*
-                        #(#trait_dispatch_arms)*
-                        #(#global_dispatch_arms)*
-                        _ => {
-                            #fallback_fn
-                        }
-                    }
+                #ctor_state_dispatch_arm
+                #(#state_dispatch_arms)*
+                #(#trait_dispatch_arms)*
+                #(#global_dispatch_arms)*
+                _ => {
+                    #fallback_fn
                 }
-                None => #fallback_fn
             }
         }
     }

+ 1 - 1
tests/misc/tests/misc.ts

@@ -160,7 +160,7 @@ describe("misc", () => {
       "Program data: jvbowsvlmkcJAAAA",
       "Program data: zxM5neEnS1kBAgMEBQYHCAkK",
       "Program data: g06Ei2GL1gIBAgMEBQYHCAkKCw==",
-      "Program 3TEqcc8xhrhdspwbvoamUJe2borm4Nr72JxL66k6rgrh consumed 5418 of 1400000 compute units",
+      "Program 3TEqcc8xhrhdspwbvoamUJe2borm4Nr72JxL66k6rgrh consumed 5395 of 1400000 compute units",
       "Program 3TEqcc8xhrhdspwbvoamUJe2borm4Nr72JxL66k6rgrh success",
     ];
 

+ 1 - 1
tests/zero-copy/programs/zero-copy/tests/compute_unit_test.rs

@@ -38,7 +38,7 @@ async fn update_foo() {
 
     let mut pt = ProgramTest::new("zero_copy", zero_copy::id(), None);
     pt.add_account(foo_pubkey, foo_account);
-    pt.set_compute_max_units(3174);
+    pt.set_compute_max_units(3157);
     let (mut banks_client, payer, recent_blockhash) = pt.start().await;
 
     let client = Client::new_with_options(