Skip to content

Protobuf derive PoC - #3794

Draft
Mirko-von-Leipzig wants to merge 51 commits into
nextfrom
mirko/protobuf-conversion-derive-poc
Draft

Protobuf derive PoC#3794
Mirko-von-Leipzig wants to merge 51 commits into
nextfrom
mirko/protobuf-conversion-derive-poc

Conversation

@Mirko-von-Leipzig

@Mirko-von-Leipzig Mirko-von-Leipzig commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

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-protobuf crate, with a miden-protobuf-derive child crate. The latter is not used directly, the sole entry-points are via the miden-protobuf crate. The intention is that both miden-objects and 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 ProtocolConfig type, so the bulk of the "savings" aren't actually visible. There are some minor fluff diffs which are because ConversionError was moved to miden-protobuf.

Note that we also enforce optional markings i.e. the policy is that fields are required unless they are marked by optional in the schema.

The benefits are:

  • error handling and mapping are automated i.e. context etc doesn't have to be made manually
  • much less hand written code, you just define the constructor mapping
  • consistency
  • automatic optional handling

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)?;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@Mirko-von-Leipzig Mirko-von-Leipzig added the no changelog This PR does not require an entry in the `CHANGELOG.md` file label Sep 2, 2026
@kkovaacs
kkovaacs force-pushed the krisztian/protobuf-transaction-inputs branch 4 times, most recently from bf5d468 to b4dcecb Compare September 3, 2026 11:44
Base automatically changed from krisztian/protobuf-transaction-inputs to next September 3, 2026 12:00
@Mirko-von-Leipzig
Mirko-von-Leipzig force-pushed the mirko/protobuf-conversion-derive-poc branch from 6abf38d to a0b4a3f Compare September 3, 2026 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no changelog This PR does not require an entry in the `CHANGELOG.md` file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant