Fail when decoding from storage and not all bytes consumed#1897
Fail when decoding from storage and not all bytes consumed#1897
Conversation
crates/engine/src/ext.rs
Outdated
|
|
||
| /// Returns the decoded contract storage at the key if any. | ||
| pub fn get_storage(&mut self, key: &[u8], output: &mut &mut [u8]) -> Result { | ||
| pub fn get_storage(&mut self, key: &[u8]) -> core::result::Result<&[u8], Error> { |
There was a problem hiding this comment.
Can't you just import the full path?
There was a problem hiding this comment.
There was a type alias here type Result = core::result::Result<(), Error>;. However I've just removed that and replaced its usages with the explicit type.
| if input.is_empty() { | ||
| Ok(res) | ||
| } else { | ||
| Err("Input buffer has still data left after decoding!".into()) |
There was a problem hiding this comment.
Perhaps would be useful to give the length of the remaining bytes left in a buffer for debugging purposes
There was a problem hiding this comment.
I'm not sure it is worth bringing in all the string formatting machinery in for that...we need to be mindful of code size.
It's possible to debug this without this information by fetching the data at the given key and attempting to decode it into the respective type.
🦑 📈 ink! Example Contracts ‒ Changes Report 📉 🦑These are the results when building the
Link to the run | Last update: Mon Oct 23 16:46:07 CEST 2023 |
Closes #1804.
If a contract previously relied on successful decoding which does not consume all bytes, then recompiling with a version of
ink!which includes this change will cause that contract to trap at runtime when attempting to decode.See the new
fn decode_allforStorableimpls. It just copies theDecodeAllimpl fromparity-scale-codecwhich is very simple.todo
integration-testfor possible migration pattern #1909)take_contract_storage