* Make noop a real noop (#12196)
* Make noop a real noop
* nudge
(cherry picked from commit 555252f435)
* resolve conflicts
Co-authored-by: Jack May <jack@solana.com>
			
			
This commit is contained in:
		
							
								
								
									
										7
									
								
								programs/bpf/Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										7
									
								
								programs/bpf/Cargo.lock
									
									
									
										generated
									
									
									
								
							@@ -1815,6 +1815,13 @@ dependencies = [
 | 
				
			|||||||
 "solana-sdk",
 | 
					 "solana-sdk",
 | 
				
			||||||
]
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[[package]]
 | 
				
			||||||
 | 
					name = "solana-bpf-rust-sanity"
 | 
				
			||||||
 | 
					version = "1.4.0"
 | 
				
			||||||
 | 
					dependencies = [
 | 
				
			||||||
 | 
					 "solana-sdk",
 | 
				
			||||||
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[[package]]
 | 
					[[package]]
 | 
				
			||||||
name = "solana-bpf-rust-sysval"
 | 
					name = "solana-bpf-rust-sysval"
 | 
				
			||||||
version = "1.3.12"
 | 
					version = "1.3.12"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -50,6 +50,7 @@ members = [
 | 
				
			|||||||
    "rust/panic",
 | 
					    "rust/panic",
 | 
				
			||||||
    "rust/param_passing",
 | 
					    "rust/param_passing",
 | 
				
			||||||
    "rust/param_passing_dep",
 | 
					    "rust/param_passing_dep",
 | 
				
			||||||
 | 
					    "rust/sanity",
 | 
				
			||||||
    "rust/sysval",
 | 
					    "rust/sysval",
 | 
				
			||||||
]
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -79,6 +79,7 @@ fn main() {
 | 
				
			|||||||
            "noop",
 | 
					            "noop",
 | 
				
			||||||
            "panic",
 | 
					            "panic",
 | 
				
			||||||
            "param_passing",
 | 
					            "param_passing",
 | 
				
			||||||
 | 
					            "sanity",
 | 
				
			||||||
            "sysval",
 | 
					            "sysval",
 | 
				
			||||||
        ];
 | 
					        ];
 | 
				
			||||||
        for program in rust_programs.iter() {
 | 
					        for program in rust_programs.iter() {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,22 +1,13 @@
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * @brief Example C-based BPF program that prints out the parameters
 | 
					 * @brief Example C-based BPF noop program
 | 
				
			||||||
 * passed to it
 | 
					 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
#include <solana_sdk.h>
 | 
					#include <solana_sdk.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern uint64_t entrypoint(const uint8_t *input) {
 | 
					extern uint64_t entrypoint(const uint8_t *input) {
 | 
				
			||||||
  SolAccountInfo ka[1];
 | 
					  SolAccountInfo ka[1];
 | 
				
			||||||
  SolParameters params = (SolParameters) { .ka = ka };
 | 
					  SolParameters params = (SolParameters) { .ka = ka };
 | 
				
			||||||
 | 
					 | 
				
			||||||
  sol_log(__FILE__);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (!sol_deserialize(input, ¶ms, SOL_ARRAY_SIZE(ka))) {
 | 
					  if (!sol_deserialize(input, ¶ms, SOL_ARRAY_SIZE(ka))) {
 | 
				
			||||||
    return ERROR_INVALID_ARGUMENT;
 | 
					    return ERROR_INVALID_ARGUMENT;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					 | 
				
			||||||
  // Log the provided input parameters.  In the case of  the no-op
 | 
					 | 
				
			||||||
  // program, no account keys or input data are expected but real
 | 
					 | 
				
			||||||
  // programs will have specific requirements so they can do their work.
 | 
					 | 
				
			||||||
  sol_log_params(¶ms);
 | 
					 | 
				
			||||||
  return SUCCESS;
 | 
					  return SUCCESS;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										22
									
								
								programs/bpf/c/src/sanity/sanity.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								programs/bpf/c/src/sanity/sanity.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
				
			|||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * @brief Example C-based BPF sanity rogram that prints out the parameters
 | 
				
			||||||
 | 
					 * passed to it
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#include <solana_sdk.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern uint64_t entrypoint(const uint8_t *input) {
 | 
				
			||||||
 | 
					  SolAccountInfo ka[1];
 | 
				
			||||||
 | 
					  SolParameters params = (SolParameters) { .ka = ka };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  sol_log(__FILE__);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (!sol_deserialize(input, ¶ms, SOL_ARRAY_SIZE(ka))) {
 | 
				
			||||||
 | 
					    return ERROR_INVALID_ARGUMENT;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Log the provided input parameters.  In the case of  the no-op
 | 
				
			||||||
 | 
					  // program, no account keys or input data are expected but real
 | 
				
			||||||
 | 
					  // programs will have specific requirements so they can do their work.
 | 
				
			||||||
 | 
					  sol_log_params(¶ms);
 | 
				
			||||||
 | 
					  return SUCCESS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,77 +1,15 @@
 | 
				
			|||||||
//! @brief Example Rust-based BPF program that prints out the parameters passed to it
 | 
					//! @brief Example Rust-based BPF noop program
 | 
				
			||||||
 | 
					 | 
				
			||||||
#![allow(unreachable_code)]
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern crate solana_sdk;
 | 
					extern crate solana_sdk;
 | 
				
			||||||
use solana_sdk::{
 | 
					use solana_sdk::{
 | 
				
			||||||
    account_info::AccountInfo, bpf_loader, entrypoint, entrypoint::ProgramResult, info, log::*,
 | 
					    account_info::AccountInfo, entrypoint, entrypoint::ProgramResult, pubkey::Pubkey,
 | 
				
			||||||
    pubkey::Pubkey,
 | 
					 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Debug, PartialEq)]
 | 
					 | 
				
			||||||
struct SStruct {
 | 
					 | 
				
			||||||
    x: u64,
 | 
					 | 
				
			||||||
    y: u64,
 | 
					 | 
				
			||||||
    z: u64,
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#[inline(never)]
 | 
					 | 
				
			||||||
fn return_sstruct() -> SStruct {
 | 
					 | 
				
			||||||
    SStruct { x: 1, y: 2, z: 3 }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
entrypoint!(process_instruction);
 | 
					entrypoint!(process_instruction);
 | 
				
			||||||
fn process_instruction(
 | 
					fn process_instruction(
 | 
				
			||||||
    program_id: &Pubkey,
 | 
					    _program_id: &Pubkey,
 | 
				
			||||||
    accounts: &[AccountInfo],
 | 
					    _accounts: &[AccountInfo],
 | 
				
			||||||
    instruction_data: &[u8],
 | 
					    _instruction_data: &[u8],
 | 
				
			||||||
) -> ProgramResult {
 | 
					) -> ProgramResult {
 | 
				
			||||||
    info!("Program identifier:");
 | 
					 | 
				
			||||||
    program_id.log();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    assert!(!bpf_loader::check_id(program_id));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // Log the provided account keys and instruction input data.  In the case of
 | 
					 | 
				
			||||||
    // the no-op program, no account keys or input data are expected but real
 | 
					 | 
				
			||||||
    // programs will have specific requirements so they can do their work.
 | 
					 | 
				
			||||||
    info!("Account keys and instruction input data:");
 | 
					 | 
				
			||||||
    sol_log_params(accounts, instruction_data);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        // Test - use std methods, unwrap
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // valid bytes, in a stack-allocated array
 | 
					 | 
				
			||||||
        let sparkle_heart = [240, 159, 146, 150];
 | 
					 | 
				
			||||||
        let result_str = std::str::from_utf8(&sparkle_heart).unwrap();
 | 
					 | 
				
			||||||
        assert_eq!(4, result_str.len());
 | 
					 | 
				
			||||||
        assert_eq!("💖", result_str);
 | 
					 | 
				
			||||||
        info!(result_str);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        // Test - struct return
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        let s = return_sstruct();
 | 
					 | 
				
			||||||
        assert_eq!(s.x + s.y + s.z, 6);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        // Test - arch config
 | 
					 | 
				
			||||||
        #[cfg(not(target_arch = "bpf"))]
 | 
					 | 
				
			||||||
        panic!();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    Ok(())
 | 
					    Ok(())
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
#[cfg(test)]
 | 
					 | 
				
			||||||
mod test {
 | 
					 | 
				
			||||||
    use super::*;
 | 
					 | 
				
			||||||
    // Pull in syscall stubs when building for non-BPF targets
 | 
					 | 
				
			||||||
    solana_sdk::program_stubs!();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    #[test]
 | 
					 | 
				
			||||||
    fn test_return_sstruct() {
 | 
					 | 
				
			||||||
        assert_eq!(SStruct { x: 1, y: 2, z: 3 }, return_sstruct());
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										26
									
								
								programs/bpf/rust/sanity/Cargo.toml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								programs/bpf/rust/sanity/Cargo.toml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					# Note: This crate must be built using do.sh
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[package]
 | 
				
			||||||
 | 
					name = "solana-bpf-rust-sanity"
 | 
				
			||||||
 | 
					version = "1.4.0"
 | 
				
			||||||
 | 
					description = "Solana BPF test program written in Rust"
 | 
				
			||||||
 | 
					authors = ["Solana Maintainers <maintainers@solana.foundation>"]
 | 
				
			||||||
 | 
					repository = "https://github.com/solana-labs/solana"
 | 
				
			||||||
 | 
					license = "Apache-2.0"
 | 
				
			||||||
 | 
					homepage = "https://solana.com/"
 | 
				
			||||||
 | 
					edition = "2018"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[dependencies]
 | 
				
			||||||
 | 
					solana-sdk = { path = "../../../../sdk/", version = "1.3.12", default-features = false }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[features]
 | 
				
			||||||
 | 
					program = ["solana-sdk/program"]
 | 
				
			||||||
 | 
					default = ["program", "solana-sdk/default"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[lib]
 | 
				
			||||||
 | 
					name = "solana_bpf_rust_sanity"
 | 
				
			||||||
 | 
					crate-type = ["cdylib"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[package.metadata.docs.rs]
 | 
				
			||||||
 | 
					targets = ["x86_64-unknown-linux-gnu"]
 | 
				
			||||||
							
								
								
									
										2
									
								
								programs/bpf/rust/sanity/Xargo.toml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								programs/bpf/rust/sanity/Xargo.toml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,2 @@
 | 
				
			|||||||
 | 
					[target.bpfel-unknown-unknown.dependencies.std]
 | 
				
			||||||
 | 
					features = []
 | 
				
			||||||
							
								
								
									
										77
									
								
								programs/bpf/rust/sanity/src/lib.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										77
									
								
								programs/bpf/rust/sanity/src/lib.rs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,77 @@
 | 
				
			|||||||
 | 
					//! @brief Example Rust-based BPF sanity program that prints out the parameters passed to it
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#![allow(unreachable_code)]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern crate solana_sdk;
 | 
				
			||||||
 | 
					use solana_sdk::{
 | 
				
			||||||
 | 
					    account_info::AccountInfo, bpf_loader, entrypoint, entrypoint::ProgramResult, info, log::*,
 | 
				
			||||||
 | 
					    pubkey::Pubkey,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[derive(Debug, PartialEq)]
 | 
				
			||||||
 | 
					struct SStruct {
 | 
				
			||||||
 | 
					    x: u64,
 | 
				
			||||||
 | 
					    y: u64,
 | 
				
			||||||
 | 
					    z: u64,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[inline(never)]
 | 
				
			||||||
 | 
					fn return_sstruct() -> SStruct {
 | 
				
			||||||
 | 
					    SStruct { x: 1, y: 2, z: 3 }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					entrypoint!(process_instruction);
 | 
				
			||||||
 | 
					fn process_instruction(
 | 
				
			||||||
 | 
					    program_id: &Pubkey,
 | 
				
			||||||
 | 
					    accounts: &[AccountInfo],
 | 
				
			||||||
 | 
					    instruction_data: &[u8],
 | 
				
			||||||
 | 
					) -> ProgramResult {
 | 
				
			||||||
 | 
					    info!("Program identifier:");
 | 
				
			||||||
 | 
					    program_id.log();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    assert!(!bpf_loader::check_id(program_id));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Log the provided account keys and instruction input data.  In the case of
 | 
				
			||||||
 | 
					    // the no-op program, no account keys or input data are expected but real
 | 
				
			||||||
 | 
					    // programs will have specific requirements so they can do their work.
 | 
				
			||||||
 | 
					    info!("Account keys and instruction input data:");
 | 
				
			||||||
 | 
					    sol_log_params(accounts, instruction_data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        // Test - use std methods, unwrap
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // valid bytes, in a stack-allocated array
 | 
				
			||||||
 | 
					        let sparkle_heart = [240, 159, 146, 150];
 | 
				
			||||||
 | 
					        let result_str = std::str::from_utf8(&sparkle_heart).unwrap();
 | 
				
			||||||
 | 
					        assert_eq!(4, result_str.len());
 | 
				
			||||||
 | 
					        assert_eq!("💖", result_str);
 | 
				
			||||||
 | 
					        info!(result_str);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        // Test - struct return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        let s = return_sstruct();
 | 
				
			||||||
 | 
					        assert_eq!(s.x + s.y + s.z, 6);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        // Test - arch config
 | 
				
			||||||
 | 
					        #[cfg(not(target_arch = "bpf"))]
 | 
				
			||||||
 | 
					        panic!();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Ok(())
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[cfg(test)]
 | 
				
			||||||
 | 
					mod test {
 | 
				
			||||||
 | 
					    use super::*;
 | 
				
			||||||
 | 
					    // Pull in syscall stubs when building for non-BPF targets
 | 
				
			||||||
 | 
					    solana_sdk::program_stubs!();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[test]
 | 
				
			||||||
 | 
					    fn test_return_sstruct() {
 | 
				
			||||||
 | 
					        assert_eq!(SStruct { x: 1, y: 2, z: 3 }, return_sstruct());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user