OpenPay (1 crate, 1801 LOC, 57 tests)
op-bin BIN/IIN database + range matching + card-network
classification. 8-digit normalized prefix Bin +
BinRange. Sorted-vec interval tree with O(log N) point
lookup + overlap rejection. CardNetwork classify()
with structural rules (Visa 4, MC 51-55/2221-2720,
Amex 34/37, Discover, JCB, Diners, UnionPay, RuPay,
Mir, Troy, Maestro, Elo). Static prefix tables +
build_default_tree(). ISO/IEC 7812-1 Annex B Luhn
(validate / is_valid / check_digit). Card-type +
issuer-country + Durbin regulated-debit. PCI-safe:
8-digit cap, no full-PAN APIs.
Smart Byte (1 crate, ~1500 LOC, 20 tests)
smart-byte-tendermint BFT consensus. Step enum + Round + propose/prevote/
precommit/commit FSM with voting-power tallies.
ValidatorSet with 2/3+1 quorum, 1/3+1 trust
threshold, round-robin proposer. Block / Header /
Commit / CommitSig with Blake3 hashing. Light client
(sequential + skipping). ABCI Application trait +
EchoApp. DuplicateVoteEvidence + LightClientAttackEvidence.
IBC ClientState + ConsensusState + light-client
update.
EOC (1 crate, 2084 LOC, 23 tests)
eoc-safety AI safety primitives. RegexSet over 16 prompt-injection
signatures. 13-family jailbreak detector (DAN/DUDE/
Grandma/STAN/AIM/dev-mode/etc.). Presidio-style PII
redactor with Luhn-validated CC. Toxicity / bias /
NSFW classifier traits + heuristic baselines (5-axis
bias, 4-category NSFW with hard-reject for minors).
Constitutional AI critique→revise loop. Composable
InputGuard / OutputGuard pipelines. JSON-Schema-subset
output validator. Token-bucket rate limiter +
abuse-window detection. Red-team replay harness.
Co-Authored-By: Claude Opus 4.7 <[email protected]>
101 lines
2.9 KiB
Rust
101 lines
2.9 KiB
Rust
use smart_byte_tendermint::evidence::{DuplicateVoteEvidence, Evidence, LightClientAttackEvidence};
|
|
use smart_byte_tendermint::block::{Commit, CommitSig};
|
|
use smart_byte_tendermint::validator::ValidatorId;
|
|
use smart_byte_tendermint::vote::{Signature, Vote, VoteType};
|
|
|
|
fn vid(b: u8) -> ValidatorId {
|
|
ValidatorId::from_bytes([b; 32])
|
|
}
|
|
|
|
fn empty_sig() -> Signature {
|
|
Signature::from_bytes([0u8; 64])
|
|
}
|
|
|
|
fn mk_vote(v: ValidatorId, h: u64, r: u32, block: Option<[u8; 32]>) -> Vote {
|
|
Vote {
|
|
kind: VoteType::Precommit,
|
|
height: h,
|
|
round: r,
|
|
block_hash: block,
|
|
validator: v,
|
|
signature: empty_sig(),
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn duplicate_vote_detected_when_two_different_block_hashes_at_same_height_round() {
|
|
let ev = DuplicateVoteEvidence {
|
|
vote_a: mk_vote(vid(7), 100, 0, Some([0xAA; 32])),
|
|
vote_b: mk_vote(vid(7), 100, 0, Some([0xBB; 32])),
|
|
};
|
|
ev.verify().unwrap();
|
|
assert_eq!(ev.offender(), vid(7));
|
|
}
|
|
|
|
#[test]
|
|
fn matching_votes_not_evidence() {
|
|
let ev = DuplicateVoteEvidence {
|
|
vote_a: mk_vote(vid(7), 100, 0, Some([0xAA; 32])),
|
|
vote_b: mk_vote(vid(7), 100, 0, Some([0xAA; 32])),
|
|
};
|
|
assert!(ev.verify().is_err());
|
|
}
|
|
|
|
#[test]
|
|
fn different_validators_not_evidence() {
|
|
let ev = DuplicateVoteEvidence {
|
|
vote_a: mk_vote(vid(7), 100, 0, Some([0xAA; 32])),
|
|
vote_b: mk_vote(vid(8), 100, 0, Some([0xBB; 32])),
|
|
};
|
|
assert!(ev.verify().is_err());
|
|
}
|
|
|
|
#[test]
|
|
fn different_heights_not_evidence() {
|
|
let ev = DuplicateVoteEvidence {
|
|
vote_a: mk_vote(vid(7), 100, 0, Some([0xAA; 32])),
|
|
vote_b: mk_vote(vid(7), 101, 0, Some([0xBB; 32])),
|
|
};
|
|
assert!(ev.verify().is_err());
|
|
}
|
|
|
|
#[test]
|
|
fn evidence_enum_dispatches_verify() {
|
|
let dv = Evidence::DuplicateVote(DuplicateVoteEvidence {
|
|
vote_a: mk_vote(vid(1), 5, 0, Some([1; 32])),
|
|
vote_b: mk_vote(vid(1), 5, 0, Some([2; 32])),
|
|
});
|
|
dv.verify().unwrap();
|
|
}
|
|
|
|
#[test]
|
|
fn light_client_attack_offenders_are_intersection_of_signers() {
|
|
let sigs_a = vec![
|
|
CommitSig { validator: vid(1), signature: empty_sig() },
|
|
CommitSig { validator: vid(2), signature: empty_sig() },
|
|
CommitSig { validator: vid(3), signature: empty_sig() },
|
|
];
|
|
let sigs_b = vec![
|
|
CommitSig { validator: vid(2), signature: empty_sig() },
|
|
CommitSig { validator: vid(3), signature: empty_sig() },
|
|
CommitSig { validator: vid(4), signature: empty_sig() },
|
|
];
|
|
let ev = LightClientAttackEvidence {
|
|
canonical: Commit {
|
|
height: 42,
|
|
round: 0,
|
|
block_hash: [0xAA; 32],
|
|
signatures: sigs_a,
|
|
},
|
|
conflicting: Commit {
|
|
height: 42,
|
|
round: 0,
|
|
block_hash: [0xBB; 32],
|
|
signatures: sigs_b,
|
|
},
|
|
};
|
|
ev.verify().unwrap();
|
|
let mut off = ev.offenders();
|
|
off.sort_by_key(|v| v.0[0]);
|
|
assert_eq!(off, vec![vid(2), vid(3)]);
|
|
}
|