-
Notifications
You must be signed in to change notification settings - Fork 428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fail when decoding from storage and not all bytes consumed #1897
Conversation
crates/engine/src/ext.rs
Outdated
@@ -241,32 +241,26 @@ impl Engine { | |||
} | |||
|
|||
/// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't you just import the full path?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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_all
forStorable
impls. It just copies theDecodeAll
impl fromparity-scale-codec
which is very simple.todo
integration-test
for possible migration pattern #1909)take_contract_storage