mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-17 21:51:06 +00:00
[contracts] Add integrity checks by pallet hook (#12993)
* integrity test for MaxCodeLen and CallStack::len() * integrity test for MaxDebugBufferLen * addressed review comments * fix append_debug_buffer() * ci fix * updated code_len_limit formula after further discussion * enlarged mem safe margin after discussion * +doc to Config trait associated types * Apply suggestions from code review Co-authored-by: Alexander Theißen <alex.theissen@me.com> * more lil fixes from code review feedback * lowered max call depth to satisfy mem limits * fix node runtime pallet params to satisfy integrity check * fix max call depth value calc Co-authored-by: Alexander Theißen <alex.theissen@me.com>
This commit is contained in:
@@ -1336,7 +1336,18 @@ where
|
||||
|
||||
fn append_debug_buffer(&mut self, msg: &str) -> bool {
|
||||
if let Some(buffer) = &mut self.debug_message {
|
||||
let mut msg = msg.bytes();
|
||||
let err_msg = scale_info::prelude::format!(
|
||||
"Debug message too big (size={}) for debug buffer (bound={})",
|
||||
msg.len(),
|
||||
DebugBufferVec::<T>::bound(),
|
||||
);
|
||||
|
||||
let mut msg = if msg.len() > DebugBufferVec::<T>::bound() {
|
||||
err_msg.bytes()
|
||||
} else {
|
||||
msg.bytes()
|
||||
};
|
||||
|
||||
let num_drain = {
|
||||
let capacity = DebugBufferVec::<T>::bound().checked_sub(buffer.len()).expect(
|
||||
"
|
||||
@@ -1349,16 +1360,7 @@ where
|
||||
msg.len().saturating_sub(capacity).min(buffer.len())
|
||||
};
|
||||
buffer.drain(0..num_drain);
|
||||
buffer
|
||||
.try_extend(&mut msg)
|
||||
.map_err(|_| {
|
||||
log::debug!(
|
||||
target: "runtime::contracts",
|
||||
"Debug message to big (size={}) for debug buffer (bound={})",
|
||||
msg.len(), DebugBufferVec::<T>::bound(),
|
||||
);
|
||||
})
|
||||
.ok();
|
||||
buffer.try_extend(&mut msg).ok();
|
||||
true
|
||||
} else {
|
||||
false
|
||||
|
||||
Reference in New Issue
Block a user