Skip to content

Fix the deserialization from JSON for I256 and U256 types with custom endianness#28

Merged
nlordell merged 1 commit into
nlordell:mainfrom
stanislav-tkach:ui-256-deserialization-from-json-fix
Aug 29, 2023
Merged

Fix the deserialization from JSON for I256 and U256 types with custom endianness#28
nlordell merged 1 commit into
nlordell:mainfrom
stanislav-tkach:ui-256-deserialization-from-json-fix

Conversation

@stanislav-tkach

Copy link
Copy Markdown
Contributor

Closes #27.

@nlordell

Copy link
Copy Markdown
Owner

Sorry for taking so long to look at this - for some reason I must have missed the notification.

Comment thread Cargo.toml
Comment on lines +34 to +38

[dev-dependencies]
serde = { version = "1", features = ["derive"] }
serde_json = "1"
bincode = "1"

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to keep these dependencies out of the test (my motivation is mostly to make building and cargo test-ing ethnum crate as lean as possible). Especially since the serde_json with pre-compiled binary fiasco, I would prefer to keep it out.

You should be able to use Vec<u8> as IntoDeserializer to check the visit_seq implementation.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to take a stab at this (otherwise, I don't mind doing it myself on top of these changes).

Comment thread src/serde.rs
bytes[i] = seq
.next_element()?
.ok_or(de::Error::invalid_length(i, &self))?;
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to check that the seq has no elements after the for loop - otherwise a 33 byte long sequence would deserialize as well.

@nlordell

Copy link
Copy Markdown
Owner

In general changes look good, just a couple of comments.

@nlordell

Copy link
Copy Markdown
Owner

Merging as is, will do the test refactoring in a follow up.

@nlordell nlordell merged commit e072b41 into nlordell:main Aug 29, 2023
@stanislav-tkach stanislav-tkach deleted the ui-256-deserialization-from-json-fix branch August 29, 2023 14:19
@stanislav-tkach

Copy link
Copy Markdown
Contributor Author

@nlordell Sorry, I wanted to apply your comments, but was distracted. Thank you for merging this!

@nlordell

Copy link
Copy Markdown
Owner

No need to apologize, I took a while to answer too. Should be released in 1.4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to deserialize U256 with custom endianness in JSON

2 participants