Skip to content

Commit

Permalink
Fix impl Absorb for SWAffine/TEAffine to not require `P::BaseField:…
Browse files Browse the repository at this point in the history
… PrimeField`

Co-authored-by: Pratyush Mishra <pratyushmishra@berkeley.edu>
  • Loading branch information
MercysJest and Pratyush authored Jan 9, 2024
1 parent 2ee4fd6 commit 6239629
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 19 deletions.
37 changes: 27 additions & 10 deletions .github/workflows/mdlinter.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,43 @@
name: Lint
on:
merge_group:
branches: [master, main]
push:
branches:
- master
paths:
- "**.md"
branches: [master, main]
pull_request:
paths:
- "**.md"
branches: [master, main]

###############
# Set the Job #
###############
jobs:
build:
name: Markdown linter
# Name the Job
name: Lint Code Base
# Set the agent to run on
runs-on: ubuntu-latest

##################
# Load all steps #
##################
steps:
- name: Checkout
uses: actions/checkout@v2
##########################
# Checkout the code base #
##########################
- name: Checkout Code
uses: actions/checkout@v4
with:
# Full git history is needed to get a proper list of changed files within `super-linter`
fetch-depth: 0

################################
# Run Linter against code base #
################################
- name: Lint Code Base
uses: github/super-linter/slim@v4
env:
VALIDATE_ALL_CODEBASE: false
DEFAULT_BRANCH: main
DEFAULT_BRANCH: master
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VALIDATE_PROTOBUF: false
VALIDATE_JSCPD: false
Expand Down
36 changes: 27 additions & 9 deletions src/sponge/absorb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use ark_ec::{
twisted_edwards::TECurveConfig as TEModelParameters,
};
use ark_ff::models::{Fp, FpConfig};
use ark_ff::{BigInteger, PrimeField, ToConstraintField};
use ark_ff::{BigInteger, Field, PrimeField, ToConstraintField};
use ark_serialize::CanonicalSerialize;
use ark_std::vec::Vec;

Expand Down Expand Up @@ -227,26 +227,44 @@ impl Absorb for isize {
}
}

impl<CF: PrimeField, P: TEModelParameters<BaseField = CF>> Absorb for TEAffine<P> {
impl<P: TEModelParameters> Absorb for TEAffine<P>
where
P::BaseField: ToConstraintField<<P::BaseField as Field>::BasePrimeField>,
{
fn to_sponge_bytes(&self, dest: &mut Vec<u8>) {
dest.append(&mut self.x.into_bigint().to_bytes_le());
dest.append(&mut self.y.into_bigint().to_bytes_le());
self.x
.to_field_elements()
.unwrap()
.into_iter()
.chain(self.y.to_field_elements().unwrap())
.for_each(|elem| {
dest.append(&mut elem.into_bigint().to_bytes_le());
});
}

fn to_sponge_field_elements<F: PrimeField>(&self, dest: &mut Vec<F>) {
field_cast::<P::BaseField, _>(&self.to_field_elements().unwrap(), dest).unwrap();
field_cast(&self.to_field_elements().unwrap(), dest).unwrap();
}
}

impl<CF: PrimeField, P: SWModelParameters<BaseField = CF>> Absorb for SWAffine<P> {
impl<P: SWModelParameters> Absorb for SWAffine<P>
where
P::BaseField: ToConstraintField<<P::BaseField as Field>::BasePrimeField>,
{
fn to_sponge_bytes(&self, dest: &mut Vec<u8>) {
dest.append(&mut self.x.into_bigint().to_bytes_le());
dest.append(&mut self.y.into_bigint().to_bytes_le());
self.x
.to_field_elements()
.unwrap()
.into_iter()
.chain(self.y.to_field_elements().unwrap())
.for_each(|elem| {
dest.append(&mut elem.into_bigint().to_bytes_le());
});
dest.push(self.infinity.into());
}

fn to_sponge_field_elements<F: PrimeField>(&self, dest: &mut Vec<F>) {
field_cast::<P::BaseField, _>(&self.to_field_elements().unwrap(), dest).unwrap();
field_cast(&self.to_field_elements().unwrap(), dest).unwrap();
}
}

Expand Down

0 comments on commit 6239629

Please sign in to comment.