Files
Zach Kelling 9513b3697f Import the Rust D-Chain and F-Chain
These were in luxfi/compute, a private repo whose licence is the same
BSD-3-Clause as luxfi/node's. Nothing here needed protecting, and keeping
it private broke the public Rust chain builds that reference it.

Sibling paths lose a level: the chains sat three deep in compute and sit
one deep here. The conformance generator loses a replace naming an
absolute path on one machine, and takes luxfi/chains from the proxy.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-10 21:36:01 -07:00

60 lines
2.2 KiB
Rust

// SPDX-License-Identifier: BSD-3-Clause-Eco
// Copyright (C) 2019-2026, Lux Industries Inc. All rights reserved.
//! Every F vector in the shared corpus, written back byte for byte.
//!
//! The corpus was generated by the Go chain, so a vector's hex is what Go
//! wrote. Reading one and writing it again has to reproduce it exactly: this
//! chain's writer and Go's are the same writer or they are not. That is what
//! makes the corpus a check on the WRITE path and not only on the read path —
//! a reader can agree about every field of bytes it could never have produced.
//!
//! This chain refuses a non-canonical encoding at PARSE — it re-serializes what
//! it read and compares — so a vector that parses has already been through the
//! writer once. Saying it again here is not redundant: that check compares the
//! writer to itself, and this one compares it to Go.
use std::path::PathBuf;
use lux_fhevm::wire;
fn corpus() -> String {
let p = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("../../../conformance/corpus/vectors.tsv");
std::fs::read_to_string(&p).unwrap_or_else(|e| panic!("{}: {e}", p.display()))
}
fn unhex(s: &str) -> Option<Vec<u8>> {
if s == "-" || s.len() % 2 != 0 {
return None;
}
(0..s.len() / 2)
.map(|i| u8::from_str_radix(&s[i * 2..i * 2 + 2], 16).ok())
.collect()
}
#[test]
fn every_f_vector_is_written_back_exactly_as_it_arrived() {
let text = corpus();
let mut txs = 0;
for line in text.lines() {
if line.is_empty() || line.starts_with('#') {
continue;
}
let f: Vec<&str> = line.split('\t').collect();
if f.len() < 5 || f[0] != "V" || f[2] != "F" || f[3] != "tx" {
continue;
}
let id = f[1];
let Some(bytes) = unhex(f[4]) else { continue };
let Ok(tx) = wire::parse_transaction(&bytes) else {
continue;
};
assert_eq!(wire::bytes(&tx), bytes, "{id}: transaction bytes moved");
txs += 1;
}
// A corpus that stopped naming F vectors would pass every assertion above.
assert!(txs > 0, "no F transaction vector was read back");
println!("{txs} F transactions written back byte for byte");
}