Skip to content
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

Deserialize function in a Serde trait #264

Merged
merged 15 commits into from
May 10, 2024
Merged

Deserialize function in a Serde trait #264

merged 15 commits into from
May 10, 2024

Conversation

LogvinovLeon
Copy link
Collaborator

@LogvinovLeon LogvinovLeon commented May 9, 2024

This PR is on top of #263

This PR adds a deserialize function in a Serde trait alongsize the serialize counterparty.

This allows us to pass complex values through oracle without hitting: noir-lang/noir#4561

Without it - I wasn't able to return our StorageWithinBlock struct from an Oracle

@LogvinovLeon LogvinovLeon changed the base branch from main to leo/storage-fixtures May 9, 2024 11:50
ethereum_history_api/circuits/lib/src/lib.nr Show resolved Hide resolved
ethereum_history_api/circuits/lib/src/serde.nr Outdated Show resolved Hide resolved

fn deserialize(data: [Field; ACCOUNT_WITHIN_BLOCK_SERIALIZED_LEN]) -> Self {
let mut fragment = Fragment::new_focused(data);
let account: Account = Account::deserialize(fragment.pop_front_array());
Copy link
Contributor

Choose a reason for hiding this comment

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

It's worth explaining somewhere in the file why we need to call deserialise with type here (as opposite to case with BYTES32) and probably make an issue to noir out of it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

noir-lang/noir#5005
Preparing repro for another one now


impl Serde<ACCOUNT_WITHIN_BLOCK_SERIALIZED_LEN> for AccountWithinBlock {
fn serialize(self) -> [Field; ACCOUNT_WITHIN_BLOCK_SERIALIZED_LEN] {
let mut data: Fragment<ACCOUNT_WITHIN_BLOCK_SERIALIZED_LEN, Field> = Fragment::empty();
Copy link
Contributor

@marekkirejczyk marekkirejczyk May 10, 2024

Choose a reason for hiding this comment

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

I think for serialization you can use BoundedVec, no need for Fragment. #BoundedVec

Base automatically changed from leo/storage-fixtures to main May 10, 2024 07:31
@LogvinovLeon LogvinovLeon merged commit a004a53 into main May 10, 2024
6 checks passed
@LogvinovLeon LogvinovLeon deleted the leo/deserialize branch May 10, 2024 11:10
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.

3 participants