From bdd19c09d1956f7adfc62aa3764c9b73d8ba5d7f Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 1 Feb 2021 14:26:31 -0800 Subject: [PATCH] More rich runtime logging (#14938) (#14967) --- programs/bpf_loader/src/syscalls.rs | 28 ++++++++++++++-------------- runtime/src/message_processor.rs | 26 ++++++++++++++++++-------- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/programs/bpf_loader/src/syscalls.rs b/programs/bpf_loader/src/syscalls.rs index 779632f532..2dc567b137 100644 --- a/programs/bpf_loader/src/syscalls.rs +++ b/programs/bpf_loader/src/syscalls.rs @@ -60,7 +60,7 @@ pub enum SyscallError { MalformedSignerSeed(Utf8Error, Vec), #[error("Could not create program address with signer seeds: {0}")] BadSeeds(PubkeyError), - #[error("Program {0} supported by inner instructions")] + #[error("Program {0} not supported by inner instructions")] ProgramNotSupported(Pubkey), #[error("{0}")] InstructionError(InstructionError), @@ -68,8 +68,8 @@ pub enum SyscallError { UnalignedPointer, #[error("Too many signers")] TooManySigners, - #[error("Instruction passed to inner instruction is too large")] - InstructionTooLarge, + #[error("Instruction passed to inner instruction is too large ({0} > {1})")] + InstructionTooLarge(usize, usize), #[error("Too many accounts passed to inner instruction")] TooManyAccounts, } @@ -1424,7 +1424,7 @@ where let account = invoke_context.get_account(&account_key).ok_or_else(|| { ic_msg!( invoke_context, - "Instruction references an unknown account {:?}", + "Instruction references an unknown account {}", account_key ); SyscallError::InstructionError(InstructionError::MissingAccount) @@ -1456,7 +1456,7 @@ where } else { ic_msg!( invoke_context, - "Instruction references an unknown account {:?}", + "Instruction references an unknown account {}", account_key ); return Err(SyscallError::InstructionError(InstructionError::MissingAccount).into()); @@ -1471,12 +1471,12 @@ fn check_instruction_size( data_len: usize, invoke_context: &Ref<&mut dyn InvokeContext>, ) -> Result<(), EbpfError> { - if invoke_context + let size = num_accounts * size_of::() + data_len; + let max_size = invoke_context .get_bpf_compute_budget() - .max_cpi_instruction_size - < num_accounts * size_of::() + data_len - { - return Err(SyscallError::InstructionTooLarge.into()); + .max_cpi_instruction_size; + if size > max_size { + return Err(SyscallError::InstructionTooLarge(size, max_size).into()); } Ok(()) } @@ -1528,7 +1528,7 @@ fn get_upgradeable_executable( } else { ic_msg!( invoke_context, - "Unknown upgradeable programdata account {:?}", + "Unknown upgradeable programdata account {}", programdata_address, ); Err(SyscallError::InstructionError(InstructionError::MissingAccount).into()) @@ -1537,7 +1537,7 @@ fn get_upgradeable_executable( _ => { ic_msg!( invoke_context, - "Invalid upgradeable program account {:?}", + "Invalid upgradeable program account {}", callee_program_id, ); Err(SyscallError::InstructionError(InstructionError::InvalidAccountData).into()) @@ -1625,7 +1625,7 @@ fn call<'a>( // Construct executables let program_account = (**accounts.get(callee_program_id_index).ok_or_else(|| { - ic_msg!(invoke_context, "Unknown program {:?}", callee_program_id,); + ic_msg!(invoke_context, "Unknown program {}", callee_program_id,); SyscallError::InstructionError(InstructionError::MissingAccount) })?) .clone(); @@ -1699,7 +1699,7 @@ fn call<'a>( { ic_msg!( invoke_context, - "SystemProgram::CreateAccount data size limited to {:?} in inner instructions", + "SystemProgram::CreateAccount data size limited to {} in inner instructions", MAX_PERMITTED_DATA_INCREASE ); return Err(SyscallError::InstructionError( diff --git a/runtime/src/message_processor.rs b/runtime/src/message_processor.rs index d7504fccbb..6bee2a8397 100644 --- a/runtime/src/message_processor.rs +++ b/runtime/src/message_processor.rs @@ -547,7 +547,7 @@ impl MessageProcessor { .ok_or_else(|| { ic_msg!( invoke_context, - "Instruction references an unknown account {:?}", + "Instruction references an unknown account {}", account.pubkey ); InstructionError::MissingAccount @@ -556,7 +556,7 @@ impl MessageProcessor { if account.is_writable && !keyed_account.is_writable() { ic_msg!( invoke_context, - "{:?}'s writable priviledge escalated ", + "{}'s writable privilege escalated", account.pubkey ); return Err(InstructionError::PrivilegeEscalation); @@ -569,7 +569,7 @@ impl MessageProcessor { ) { ic_msg!( invoke_context, - "{:?}'s signer priviledge escalated ", + "{}'s signer priviledge escalated", account.pubkey ); return Err(InstructionError::PrivilegeEscalation); @@ -584,11 +584,16 @@ impl MessageProcessor { { Some(keyed_account) => { if !keyed_account.executable()? { + ic_msg!( + invoke_context, + "Account {} is not executable", + keyed_account.unsigned_key() + ); return Err(InstructionError::AccountNotExecutable); } } None => { - ic_msg!(invoke_context, "Unknown program {:?}", program_id); + ic_msg!(invoke_context, "Unknown program {}", program_id); return Err(InstructionError::MissingAccount); } } @@ -638,7 +643,7 @@ impl MessageProcessor { } ic_msg!( invoke_context, - "Instruction references an unknown account {:?}", + "Instruction references an unknown account {}", account_key ); return Err(InstructionError::MissingAccount); @@ -652,10 +657,15 @@ impl MessageProcessor { invoke_context .get_account(&callee_program_id) .ok_or_else(|| { - ic_msg!(invoke_context, "Unknown program {:?}", callee_program_id); + ic_msg!(invoke_context, "Unknown program {}", callee_program_id); InstructionError::MissingAccount })?; if !program_account.borrow().executable { + ic_msg!( + invoke_context, + "Account {} is not executable", + callee_program_id + ); return Err(InstructionError::AccountNotExecutable); } let programdata_executable = @@ -669,7 +679,7 @@ impl MessageProcessor { } else { ic_msg!( invoke_context, - "Unknown upgradeable programdata account {:?}", + "Unknown upgradeable programdata account {}", programdata_address, ); return Err(InstructionError::MissingAccount); @@ -677,7 +687,7 @@ impl MessageProcessor { } else { ic_msg!( invoke_context, - "Upgradeable program account state not valid {:?}", + "Upgradeable program account state not valid {}", callee_program_id, ); return Err(InstructionError::MissingAccount);