-
Notifications
You must be signed in to change notification settings - Fork 307
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
feat: #[derive(Packable)]
#11531
feat: #[derive(Packable)]
#11531
Conversation
address::AztecAddress, | ||
constants::GENERATOR_INDEX__NOTE_NULLIFIER, | ||
hash::poseidon2_hash_with_separator, | ||
traits::{Packable, Serialize}, |
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.
All the files with notes now generally need to import Packable
as because of the change in noir-projects/noir-protocol-circuits/crates/types/src/meta/mod.nr
.
See comment in that file for details.
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.
As mentioned in the serialize pr, it'd be good for derive to not require extra imports from the caller. We can either autoimport, or just use fully qualified paths in the derived impl.
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.
@@ -1,38 +1,9 @@ | |||
use dep::aztec::{macros::aztec, protocol_types::traits::{Deserialize, Packable, Serialize}}; | |||
|
|||
// I tried using #[derive(Serialize, Deserialize)] macro here but for whatever reason it fails to compile. |
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.
Moved the note to a separate file because then the derivation works.
I find it quite weird to have the note defined in the same file as the contract.
Do we find this bug worthy of trying to fix?
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.
Yes, definitely
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.
@@ -104,8 +104,8 @@ pub comptime fn generate_deserialize_from_fields<N>( | |||
} | |||
let packed_fields = packed_fields_quotes.join(quote {,}); | |||
|
|||
// No we call unpack on the type | |||
result = quote { aztec::protocol_types::traits::Packable::unpack([ $packed_fields ]) }; |
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.
This is the reason why the Packable needs to be imported now.
Having the full path here was a mistake since the dep could be called differently than aztec
and this might also be used inside the protocol circuits where there is no aztec dep.
We probably could figure the correct import at comptime but would do that in a separate PR if we find this desirable.
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.
Ahh, I see. Can't we have the full path to proto_types::traits so that it'd work both here, in aztec, and in the user's code?
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.
You would then need to figure out whether you are in the types crate or not as in the types crate you would not use dep::aztec::protocol_types
but just crate
.
Jake promised me he will send a PR such that I can quote a Type directly and get a correct path. This would then make this straighforward. Until that is done I've created this issue to track it.
quote {_} | ||
} else { | ||
token | ||
}; |
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.
This was a bug and it got triggered by me using Serialize
derivation in noir-projects/noir-contracts/contracts/card_game_contract/src/game.nr
Changes to public function bytecode sizes
🧾 Summary (100% most significant diffs)
Full diff report 👇
|
31ce3f7
to
787e700
Compare
9f5f05a
to
12261b5
Compare
787e700
to
f7e3d93
Compare
12261b5
to
7b76054
Compare
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.
Looks great, have some tiny qns but will approve to unblock ! 🙏
noir-projects/noir-protocol-circuits/crates/types/src/meta/mod.nr
Outdated
Show resolved
Hide resolved
noir-projects/noir-contracts/contracts/test_contract/src/test_note.nr
Outdated
Show resolved
Hide resolved
f7e3d93
to
612e2e8
Compare
7b76054
to
0883f93
Compare
44c5bb7
to
3800e92
Compare
In this PR I implement auto-derivation of
Packable
trait.It uses the same underlying functionality as derivation of
Serialize
but it calls thegenerate_serialize_to_fields
andgenerate_deserialize_from_fields
with packing enabled. This means that if some of the struct members has thePackable
trait implemented it gets used instead of the intrinsic Noir serialization.