Add test for flat error when encoding bls constant
This commit is contained in:
parent
c3af748b76
commit
4f1de2d3b5
|
@ -547,19 +547,19 @@ impl Encode for Constant {
|
||||||
|
|
||||||
cbor.encode(e)?;
|
cbor.encode(e)?;
|
||||||
}
|
}
|
||||||
Constant::Bls12_381G1Element(b) => {
|
Constant::Bls12_381G1Element(_) => {
|
||||||
encode_constant(&[9], e)?;
|
encode_constant(&[9], e)?;
|
||||||
|
|
||||||
let x = b.compress();
|
return Err(en::Error::Message(
|
||||||
|
"BLS12-381 G1 points are not supported for flat encoding".to_string(),
|
||||||
x.encode(e)?;
|
));
|
||||||
}
|
}
|
||||||
Constant::Bls12_381G2Element(b) => {
|
Constant::Bls12_381G2Element(_) => {
|
||||||
encode_constant(&[10], e)?;
|
encode_constant(&[10], e)?;
|
||||||
|
|
||||||
let x = b.compress();
|
return Err(en::Error::Message(
|
||||||
|
"BLS12-381 G2 points are not supported for flat encoding".to_string(),
|
||||||
x.encode(e)?;
|
));
|
||||||
}
|
}
|
||||||
Constant::Bls12_381MlResult(_) => {
|
Constant::Bls12_381MlResult(_) => {
|
||||||
encode_constant(&[11], e)?;
|
encode_constant(&[11], e)?;
|
||||||
|
@ -597,16 +597,12 @@ fn encode_constant_value(x: &Constant, e: &mut Encoder) -> Result<(), en::Error>
|
||||||
|
|
||||||
cbor.encode(e)
|
cbor.encode(e)
|
||||||
}
|
}
|
||||||
Constant::Bls12_381G1Element(b) => {
|
Constant::Bls12_381G1Element(_) => Err(en::Error::Message(
|
||||||
let x = b.compress();
|
"BLS12-381 G1 points are not supported for flat encoding".to_string(),
|
||||||
|
)),
|
||||||
x.encode(e)
|
Constant::Bls12_381G2Element(_) => Err(en::Error::Message(
|
||||||
}
|
"BLS12-381 G2 points are not supported for flat encoding".to_string(),
|
||||||
Constant::Bls12_381G2Element(b) => {
|
)),
|
||||||
let x = b.compress();
|
|
||||||
|
|
||||||
x.encode(e)
|
|
||||||
}
|
|
||||||
Constant::Bls12_381MlResult(_) => Err(en::Error::Message(
|
Constant::Bls12_381MlResult(_) => Err(en::Error::Message(
|
||||||
"BLS12-381 ML results are not supported for flat encoding".to_string(),
|
"BLS12-381 ML results are not supported for flat encoding".to_string(),
|
||||||
)),
|
)),
|
||||||
|
@ -676,21 +672,25 @@ impl<'b> Decode<'b> for Constant {
|
||||||
[9] => {
|
[9] => {
|
||||||
let p1 = Vec::<u8>::decode(d)?;
|
let p1 = Vec::<u8>::decode(d)?;
|
||||||
|
|
||||||
let p1 = blst::blst_p1::uncompress(&p1).map_err(|err| {
|
let _p1 = blst::blst_p1::uncompress(&p1).map_err(|err| {
|
||||||
de::Error::Message(format!("Failed to uncompress p1: {}", err))
|
de::Error::Message(format!("Failed to uncompress p1: {}", err))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
Ok(Constant::Bls12_381G1Element(p1.into()))
|
Err(de::Error::Message(format!(
|
||||||
|
"BLS12-381 G1 points are not supported for flat decoding."
|
||||||
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
[10] => {
|
[10] => {
|
||||||
let p2 = Vec::<u8>::decode(d)?;
|
let p2 = Vec::<u8>::decode(d)?;
|
||||||
|
|
||||||
let p2 = blst::blst_p2::uncompress(&p2).map_err(|err| {
|
let _p2 = blst::blst_p2::uncompress(&p2).map_err(|err| {
|
||||||
de::Error::Message(format!("Failed to uncompress p2: {}", err))
|
de::Error::Message(format!("Failed to uncompress p2: {}", err))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
Ok(Constant::Bls12_381G2Element(p2.into()))
|
Err(de::Error::Message(format!(
|
||||||
|
"BLS12-381 G2 points are not supported for flat decoding."
|
||||||
|
)))
|
||||||
}
|
}
|
||||||
[11] => Err(de::Error::Message(
|
[11] => Err(de::Error::Message(
|
||||||
"BLS12-381 ML results are not supported for flat decoding".to_string(),
|
"BLS12-381 ML results are not supported for flat decoding".to_string(),
|
||||||
|
@ -737,18 +737,22 @@ fn decode_constant_value(typ: Rc<Type>, d: &mut Decoder) -> Result<Constant, de:
|
||||||
Type::Bls12_381G1Element => {
|
Type::Bls12_381G1Element => {
|
||||||
let p1 = Vec::<u8>::decode(d)?;
|
let p1 = Vec::<u8>::decode(d)?;
|
||||||
|
|
||||||
let p1 = blst::blst_p1::uncompress(&p1)
|
let _p1 = blst::blst_p1::uncompress(&p1)
|
||||||
.map_err(|err| de::Error::Message(format!("Failed to uncompress p1: {}", err)))?;
|
.map_err(|err| de::Error::Message(format!("Failed to uncompress p1: {}", err)))?;
|
||||||
|
|
||||||
Ok(Constant::Bls12_381G1Element(p1.into()))
|
Err(de::Error::Message(format!(
|
||||||
|
"BLS12-381 G1 points are not supported for flat decoding."
|
||||||
|
)))
|
||||||
}
|
}
|
||||||
Type::Bls12_381G2Element => {
|
Type::Bls12_381G2Element => {
|
||||||
let p2 = Vec::<u8>::decode(d)?;
|
let p2 = Vec::<u8>::decode(d)?;
|
||||||
|
|
||||||
let p2 = blst::blst_p2::uncompress(&p2)
|
let _p2 = blst::blst_p2::uncompress(&p2)
|
||||||
.map_err(|err| de::Error::Message(format!("Failed to uncompress p2: {}", err)))?;
|
.map_err(|err| de::Error::Message(format!("Failed to uncompress p2: {}", err)))?;
|
||||||
|
|
||||||
Ok(Constant::Bls12_381G2Element(p2.into()))
|
Err(de::Error::Message(format!(
|
||||||
|
"BLS12-381 G2 points are not supported for flat decoding."
|
||||||
|
)))
|
||||||
}
|
}
|
||||||
Type::Bls12_381MlResult => Err(de::Error::Message(
|
Type::Bls12_381MlResult => Err(de::Error::Message(
|
||||||
"BLS12-381 ML results are not supported for flat decoding".to_string(),
|
"BLS12-381 ML results are not supported for flat decoding".to_string(),
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
name = "aiken-lang/acceptance_test_113"
|
||||||
|
version = "0.0.0"
|
||||||
|
license = "Apache-2.0"
|
||||||
|
description = "Aiken contracts for project 'aiken-lang/113'"
|
||||||
|
|
||||||
|
[repository]
|
||||||
|
user = "aiken-lang"
|
||||||
|
project = "113"
|
||||||
|
platform = "github"
|
|
@ -0,0 +1,21 @@
|
||||||
|
use aiken/builtin
|
||||||
|
|
||||||
|
pub const generator_g1: G1Element =
|
||||||
|
#<Bls12_381, G1>"97f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb"
|
||||||
|
|
||||||
|
pub const generator_g2: G2Element =
|
||||||
|
#<Bls12_381, G2>"93e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8"
|
||||||
|
|
||||||
|
validator here {
|
||||||
|
mint(_rdr, _policy_id, _tx) {
|
||||||
|
let g1 = builtin.bls12_381_g1_compress(generator_g1)
|
||||||
|
|
||||||
|
let g2 = builtin.bls12_381_g2_compress(generator_g2)
|
||||||
|
|
||||||
|
g1 != g2
|
||||||
|
}
|
||||||
|
|
||||||
|
else(_) {
|
||||||
|
fail
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue