Skip to content

Commit

Permalink
fix ci check
Browse files Browse the repository at this point in the history
  • Loading branch information
XuyangSong committed Sep 18, 2023
1 parent bb3be6e commit 2a7a655
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 24 deletions.
2 changes: 1 addition & 1 deletion taiga_halo2/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use serde;
use borsh::{BorshDeserialize, BorshSerialize};

/// The action result used in transaction.
#[derive(Copy, Debug, Clone)]
#[derive(Debug, Clone)]
#[cfg_attr(feature = "nif", derive(NifStruct))]

Check failure on line 24 in taiga_halo2/src/action.rs

View workflow job for this annotation

GitHub Actions / Test on ubuntu-latest

the trait bound `ValidityPredicateCommitment: Encoder` is not satisfied

Check failure on line 24 in taiga_halo2/src/action.rs

View workflow job for this annotation

GitHub Actions / Clippy

the trait bound `vp_commitment::ValidityPredicateCommitment: rustler::Encoder` is not satisfied

error[E0277]: the trait bound `vp_commitment::ValidityPredicateCommitment: rustler::Encoder` is not satisfied --> taiga_halo2/src/action.rs:24:36 | 24 | #[cfg_attr(feature = "nif", derive(NifStruct))] | ^^^^^^^^^ the trait `rustler::Encoder` is not implemented for `vp_commitment::ValidityPredicateCommitment` | = help: the following other types implement trait `rustler::Encoder`: bool isize i8 i16 i32 i64 usize u8 and 55 others = note: this error originates in the derive macro `NifStruct` (in Nightly builds, run with -Z macro-backtrace for more info)

Check failure on line 24 in taiga_halo2/src/action.rs

View workflow job for this annotation

GitHub Actions / Clippy

the trait bound `vp_commitment::ValidityPredicateCommitment: rustler::Encoder` is not satisfied

error[E0277]: the trait bound `vp_commitment::ValidityPredicateCommitment: rustler::Encoder` is not satisfied --> taiga_halo2/src/action.rs:24:36 | 24 | #[cfg_attr(feature = "nif", derive(NifStruct))] | ^^^^^^^^^ the trait `rustler::Encoder` is not implemented for `vp_commitment::ValidityPredicateCommitment` | = help: the following other types implement trait `rustler::Encoder`: bool isize i8 i16 i32 i64 usize u8 and 55 others = note: this error originates in the derive macro `NifStruct` (in Nightly builds, run with -Z macro-backtrace for more info)
#[cfg_attr(feature = "nif", module = "Taiga.Action.Instance")]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
Expand Down
35 changes: 12 additions & 23 deletions taiga_halo2/src/vp_commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ use blake2s_simd::Params;
use byteorder::{ByteOrder, LittleEndian};
use ff::PrimeField;
#[cfg(feature = "nif")]
use rustler::{Decoder, Encoder, Env, NifResult, Term};
use rustler::NifTuple;
#[cfg(feature = "serde")]
use serde;

#[derive(Copy, Clone, Debug, Default)]
#[derive(Clone, Debug)]
#[cfg_attr(feature = "nif", derive(NifTuple))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ValidityPredicateCommitment([u8; 32]);
pub struct ValidityPredicateCommitment(Vec<u8>);

impl ValidityPredicateCommitment {
pub fn commit<F: PrimeField>(vp: &F, rcm: &F) -> Self {
Expand All @@ -20,22 +21,22 @@ impl ValidityPredicateCommitment {
.update(vp.to_repr().as_ref())
.update(rcm.to_repr().as_ref())
.finalize();
Self(hash.as_bytes().try_into().unwrap())
Self(hash.as_bytes().to_vec())
}

pub fn to_bytes(&self) -> [u8; 32] {
self.0
self.0.clone().try_into().unwrap()
}

pub fn from_bytes(bytes: [u8; 32]) -> Self {
Self(bytes)
Self(bytes.to_vec())
}

pub fn from_public_inputs<F: PrimeField>(public_inputs: &[F; 2]) -> Self {
let mut bytes: [u8; 32] = [0; 32];
bytes[0..16].copy_from_slice(&public_inputs[0].to_repr().as_ref()[0..16]);
bytes[16..].copy_from_slice(&public_inputs[1].to_repr().as_ref()[0..16]);
Self(bytes)
bytes[16..32].copy_from_slice(&public_inputs[1].to_repr().as_ref()[0..16]);
Self(bytes.to_vec())
}

pub fn to_public_inputs<F: PrimeField>(&self) -> [F; 2] {
Expand All @@ -45,20 +46,8 @@ impl ValidityPredicateCommitment {
}
}

#[cfg(feature = "nif")]
impl Encoder for ValidityPredicateCommitment {
fn encode<'a>(&self, env: Env<'a>) -> Term<'a> {
self.0.to_vec().encode(env)
}
}

#[cfg(feature = "nif")]
impl<'a> Decoder<'a> for ValidityPredicateCommitment {
fn decode(term: Term<'a>) -> NifResult<Self> {
let val: Vec<u8> = Decoder::decode(term)?;
let val_array = val
.try_into()
.map_err(|_e| rustler::Error::Atom("failure to decode"))?;
Ok(ValidityPredicateCommitment(val_array))
impl Default for ValidityPredicateCommitment {
fn default() -> ValidityPredicateCommitment {
ValidityPredicateCommitment([0u8; 32].to_vec())
}
}

0 comments on commit 2a7a655

Please sign in to comment.