Fe Codec encodes your types as JSON, deterministic CBOR or a format you write, and hashes them as EIP-712 typed data. A generator written in Fe writes the serializers, and the same code runs in contracts, native programs and WebAssembly.
The generator reads your declarations and writes ordinary Fe that implements the codec traits. There is no runtime reflection and no plugin to load: the compiler checks the result like any other module.
01
Describe
Mark structs and enums #[serializable]. They stay ordinary Fe types.
// Generated by fe_codec_gen. Do not edit.impl fe_codec_core::Serialize for Order { fn serialize<CodecEncoder: fe_codec_core::Encoder>(self, _ encoder: mut CodecEncoder) -> fe_codec_core::CodecResult<()> { var present: usize = 4 if !CodecEncoder::OMIT_NONE || self.note.is_some() { present += 1 } var record = encoder.begin_record<Self>(present)? encoder.field<Self>(mut record, 0)? self.id.serialize(mut encoder)? // … one visit per field, in ID order encoder.end_record(record) }}
03
Use
Encode and decode with any format. Bindings choose the type and the buffer.
fn round_trip(_ order: Order) -> CodecResult<Order> { let bytes: BoundedBuffer<192> = fe_codec_json::encode(order)? let back: Order = fe_codec_json::decode(bytes)? Result::Ok(back)}
§03 · EIP-712
Typed data, hashed at compile time.
The generator computes each struct's encodeType and emits its type hash as acore::keccak constant. Hashing a struct is then one keccak_wordsover its members, as hand-written code would be.
#[serializable]pub struct Person { pub name: Text<16>, pub wallet: Address }#[serializable]#[eip712]pub struct Mail { pub from: Person, pub to: Person, pub contents: Text<32> }
Computed by fe_codec_eip712 when this page was built: the EIP's own example values, through the generated and the generic path. The tests also check them against an independent transcription of the specification and viem.
§04 · Evidence
Proved, property-tested, example-tested.
Three kinds of evidence, kept apart because they are not interchangeable.
Proved
femp prove, for every input, on the EVM, natively and in WebAssembly
UTF-8 validation of a character follows RFC 3629 §4 exactly
The CBOR encoder's head for any 64-bit argument is the only head the decoder accepts
The 8–64-bit range checks accept exactly the values of their width
Property-tested
femp prop, with generated inputs on all three targets
Every integer width round-trips in JSON, CBOR and the compact format
No input of up to 64 arbitrary bytes makes a decoder panic
The targets agree on every decode outcome and every encoded byte
Example-tested
Golden vectors, conformance and the generator's own suites
Vectors from an independent reference encoder, and RFC 8949 Appendix A
A conformance check every format runs, with exact error kinds and offsets
Random models checked against the reference encoders and the EIP-712 specification
What is not established, such as proofs for whole encoders, is listed in the design's guarantees.