Protobuf derive PoC - #3794
Draft
Mirko-von-Leipzig wants to merge 51 commits into
Draft
Conversation
Comment on lines
+32
to
+70
| let mut prost = prost_build::Config::new(); | ||
| prost.out_dir(out_dir); | ||
| miden_protobuf::configure_proto_decodes! { | ||
| prost: &mut prost, | ||
| descriptors: &descriptors, | ||
| ".protocol_config.KernelConfig" => { | ||
| target: ::miden_protocol::protocol_config::KernelConfig, | ||
| try_constructor: ::miden_protocol::protocol_config::KernelConfig::new( | ||
| main_proc, | ||
| kernel_procs, | ||
| ), | ||
| }, | ||
| ".protocol_config.ProofSecurityPolicy" => { | ||
| target: ::miden_protocol::protocol_config::ProofSecurityPolicy, | ||
| try_constructor: ::miden_protocol::protocol_config::ProofSecurityPolicy::new( | ||
| security_estimator_root, | ||
| minimum_bits, | ||
| ), | ||
| }, | ||
| ".protocol_config.ProofVerificationConfig" => { | ||
| target: ::miden_protocol::protocol_config::ProofVerificationConfig, | ||
| constructor: ::miden_protocol::protocol_config::ProofVerificationConfig::new( | ||
| vm_verifier_root, | ||
| precompile_verifier_root, | ||
| security_policy, | ||
| ), | ||
| }, | ||
| ".protocol_config.ProtocolConfig" => { | ||
| target: ::miden_protocol::protocol_config::ProtocolConfig, | ||
| try_constructor: ::miden_protocol::protocol_config::ProtocolConfig::new( | ||
| fee_asset_id, | ||
| tx_kernel, | ||
| batch_kernel, | ||
| block_kernel, | ||
| proof_verification, | ||
| ), | ||
| }, | ||
| }?; | ||
| prost.compile_fds(descriptors)?; |
Contributor
Author
There was a problem hiding this comment.
This demonstrates the primary API. Callers link the protobuf type to a domain type, and define the constructor ordering and T versus Result<T>.
This injects the proto derive macro which in turn automatically implements an appropriate TryFrom<proto::T> -> Result<domain::T, ConversionError>. We would similarly do this for encoding.
kkovaacs
force-pushed
the
krisztian/protobuf-transaction-inputs
branch
4 times, most recently
from
September 3, 2026 11:44
bf5d468 to
b4dcecb
Compare
Base automatically changed from
krisztian/protobuf-transaction-inputs
to
next
September 3, 2026 12:00
Mirko-von-Leipzig
force-pushed
the
mirko/protobuf-conversion-derive-poc
branch
from
September 3, 2026 12:40
6abf38d to
a0b4a3f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR demonstrates a derive style macro for our protobuf schema. This only implements it for the decoding half, but it can be trivially expanded to support encoding in a similar fashion.
This is implemented in a stand-alone fashion as a completely independent
miden-protobufcrate, with amiden-protobuf-derivechild crate. The latter is not used directly, the sole entry-points are via themiden-protobufcrate. The intention is that bothmiden-objectsand the node code can use this crate at build, and runtime, to align error formatting and remove the bulk of the (currently) manual implementation.This PoC demonstrates the usage on the
ProtocolConfigtype, so the bulk of the "savings" aren't actually visible. There are some minor fluff diffs which are becauseConversionErrorwas moved tomiden-protobuf.Note that we also enforce
optionalmarkings i.e. the policy is that fields are required unless they are marked byoptionalin the schema.The benefits are:
optionalhandling