Skip to content

Commit

Permalink
fixup tool generating fuzz corpus: update the signature of bls_verify…
Browse files Browse the repository at this point in the history
… and bls_pairing_identity
  • Loading branch information
arvidn committed May 12, 2023
1 parent 101ad85 commit 0a09d2f
Showing 1 changed file with 33 additions and 15 deletions.
48 changes: 33 additions & 15 deletions tools/src/bin/generate-fuzz-corpus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ enum Type {
Program,
Tree,
List,
PointList,
PointPair,
Bool,
Int64,
Expand Down Expand Up @@ -50,7 +49,7 @@ const fn op(opcode: u8, operands: &'static [Type], result: Type) -> OperatorInfo
}
}

const OPERATORS: [OperatorInfo; 48] = [
const OPERATORS: [OperatorInfo; 76] = [
// apply
op(2, &[Type::Program, Type::Tree], Type::AnyAtom),
// if
Expand All @@ -62,8 +61,6 @@ const OPERATORS: [OperatorInfo; 48] = [
// cons
op(4, &[Type::AnyAtom, Type::List], Type::List),
op(4, &[Type::Bytes48, Type::Bytes96], Type::PointPair),
op(4, &[Type::PointPair, Type::PointList], Type::PointList),
op(4, &[Type::PointPair, Type::Zero], Type::PointList),
// first
op(5, &[Type::List], Type::AnyAtom),
// rest
Expand Down Expand Up @@ -93,10 +90,17 @@ const OPERATORS: [OperatorInfo; 48] = [
op(13, &[Type::AnyAtom], Type::Int32),
// concat
op(14, &[Type::AnyAtom, Type::AnyAtom], Type::AnyAtom),
op(14, &[Type::AnyAtom, Type::AnyAtom, Type::AnyAtom], Type::AnyAtom),
// add
op(16, &[], Type::Int64),
op(16, &[Type::Int64], Type::Int64),
op(16, &[Type::Int64, Type::Int64], Type::Int64),
op(16, &[Type::Int64, Type::Int64, Type::Int64], Type::Int64),
// subtract
op(17, &[], Type::Int64),
op(17, &[Type::Int64], Type::Int64),
op(17, &[Type::Int64, Type::Int64], Type::Int64),
op(17, &[Type::Int64, Type::Int64, Type::Int64], Type::Int64),
// multiply
op(18, &[Type::Int64, Type::Int64], Type::Int64),
// div
Expand All @@ -110,15 +114,27 @@ const OPERATORS: [OperatorInfo; 48] = [
// lsh
op(23, &[Type::Int64, Type::Int32], Type::Int64),
// logand
op(24, &[], Type::AnyAtom),
op(24, &[Type::AnyAtom], Type::AnyAtom),
op(24, &[Type::AnyAtom, Type::AnyAtom], Type::AnyAtom),
op(24, &[Type::AnyAtom, Type::AnyAtom, Type::AnyAtom], Type::AnyAtom),
// logior
op(25, &[], Type::AnyAtom),
op(25, &[Type::AnyAtom], Type::AnyAtom),
op(25, &[Type::AnyAtom, Type::AnyAtom], Type::AnyAtom),
op(25, &[Type::AnyAtom, Type::AnyAtom, Type::AnyAtom], Type::AnyAtom),
// logxor
op(26, &[], Type::AnyAtom),
op(26, &[Type::AnyAtom], Type::AnyAtom),
op(26, &[Type::AnyAtom, Type::AnyAtom], Type::AnyAtom),
op(26, &[Type::AnyAtom, Type::AnyAtom, Type::AnyAtom], Type::AnyAtom),
// lognot
op(27, &[Type::AnyAtom], Type::AnyAtom),
// point_add
op(29, &[], Type::Bytes48),
op(29, &[Type::Bytes48], Type::Bytes48),
op(29, &[Type::Bytes48, Type::Bytes48], Type::Bytes48),
op(29, &[Type::Bytes48, Type::Bytes48, Type::Bytes48], Type::Bytes48),
// pubkey for exp
op(30, &[Type::AnyAtom], Type::Bytes48),
// not
Expand Down Expand Up @@ -153,6 +169,9 @@ const OPERATORS: [OperatorInfo; 48] = [
op(53, &[Type::Bytes96, Type::Bytes96], Type::Bytes96),
// bls_g2_multiply
op(54, &[Type::Bytes96, Type::Int64], Type::Bytes96),
op(54, &[Type::Bytes96, Type::Bytes32], Type::Bytes96),
op(54, &[Type::Bytes96, Type::Bytes48], Type::Bytes96),
op(54, &[Type::Bytes96, Type::Bytes96], Type::Bytes96),
// bls_g2_negate
op(55, &[Type::Bytes96], Type::Bytes96),
// bls_map_to_g1
Expand All @@ -161,9 +180,17 @@ const OPERATORS: [OperatorInfo; 48] = [
op(57, &[Type::AnyAtom, Type::AnyAtom], Type::Bytes96),
op(57, &[Type::AnyAtom], Type::Bytes96),
// bls_pairing_identity
op(58, &[Type::PointList], Type::Bool),
op(58, &[Type::PointPair], Type::Bool),
op(58, &[Type::PointPair, Type::PointPair], Type::Bool),
op(58, &[Type::PointPair, Type::PointPair, Type::PointPair], Type::Bool),
op(58, &[Type::PointPair, Type::PointPair, Type::PointPair, Type::PointPair], Type::Bool),
op(58, &[Type::PointPair, Type::PointPair, Type::PointPair, Type::PointPair, Type::PointPair], Type::Bool),
// bls_verify
op(59, &[Type::PointList, Type::Bytes96], Type::Bool),
op(59, &[Type::Bytes96], Type::Bool),
op(59, &[Type::Bytes96, Type::PointPair], Type::Bool),
op(59, &[Type::Bytes96, Type::PointPair, Type::PointPair], Type::Bool),
op(59, &[Type::Bytes96, Type::PointPair, Type::PointPair, Type::PointPair], Type::Bool),
op(59, &[Type::Bytes96, Type::PointPair, Type::PointPair, Type::PointPair, Type::PointPair], Type::Bool),
];

const ZEROS: [u8; 96] = [0; 96];
Expand Down Expand Up @@ -203,7 +230,6 @@ fn type_convertible(from: Type, to: Type) -> bool {
from == to
|| to == Type::AnyAtom && ATOMS.contains(&from)
|| to == Type::Tree && from == Type::List
|| to == Type::List && from == Type::PointList
|| to == Type::Zero && from == Type::Int32
|| to == Type::Cost && from == Type::Int64
}
Expand Down Expand Up @@ -273,14 +299,6 @@ fn generate<R: Rng>(t: Type, rng: &mut R, buffer: &mut Vec<u8>) {
}
buffer.push(0x80); // NIL
}
Type::PointList => {
let len = rng.gen_range(0..10);
for _i in 0..len {
buffer.push(0xff); // cons
generate(Type::PointPair, rng, buffer);
}
buffer.push(0x80); // NIL
}
Type::PointPair => {
buffer.push(0xff); // cons
generate(Type::Bytes48, rng, buffer);
Expand Down

0 comments on commit 0a09d2f

Please sign in to comment.