Skip to content
This repository has been archived by the owner on Nov 23, 2023. It is now read-only.

Commit

Permalink
update attestation hashing
Browse files Browse the repository at this point in the history
  • Loading branch information
brech1 committed Oct 26, 2023
1 parent 847e364 commit 08d392c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 36 deletions.
15 changes: 3 additions & 12 deletions eigentrust-cli/assets/attestations.csv
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
about,domain,value,message,sig_r,sig_s,rec_id
0x70997970c51812dc3a010c7d01b50e0d17dc79c8,0x0000000000000000000000000000000000000000,10,0x0000000000000000000000000000000000000000000000000000000000000000,0x8e67f1bdc7439ec2735ce065b87a29d29bfdf00142e4088c530ebfdf0fbb4391,0xade39d16e9a63de3978d8df99d59b3854c06137236a56023aea4dd2ed401f37e,0
0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc,0x0000000000000000000000000000000000000000,10,0x0000000000000000000000000000000000000000000000000000000000000000,0xb803c8701ae14483f2064718ff9b9cd8b55f027e3e6d6520c4a119c16bedf50c,0xfe6db58e6023fdf8ec5fb5cfd2a686c04b869910d9082e8527e4253002b05163,1
0x90f79bf6eb2c4f870365e785982e1f101e93b906,0x0000000000000000000000000000000000000000,10,0x0000000000000000000000000000000000000000000000000000000000000000,0x536e4a1f5fe72ce2906e10a0c54d608d42b60762553f7d2f1cde1138f445ffca,0x0fe76ab81d9e91b56f9401ba3c437e84c15510a7a5d0058b7652e9dc68fd245f,1
0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266,0x0000000000000000000000000000000000000000,10,0x0000000000000000000000000000000000000000000000000000000000000000,0x95eff8f2e4577e64f3b4b2e0c02057bc39f721240a9360a25a7050823c8c97ba,0x9862b84b25265c3fee19a3a336eb9a9471636a22be3e8990732584929f1c6354,1
0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc,0x0000000000000000000000000000000000000000,10,0x0000000000000000000000000000000000000000000000000000000000000000,0xf90327849dc3db9a17b792d4f7068b1d6aa4ad0d3237f6c44da093c1cf36875f,0x7533e469e4404334da32101489e665b2a6fb57d5a3366977cb5754b029456d3c,0
0x90f79bf6eb2c4f870365e785982e1f101e93b906,0x0000000000000000000000000000000000000000,10,0x0000000000000000000000000000000000000000000000000000000000000000,0x3c0df0beafc0f3c8dee13557a57c08cda7e33bba41d3e04e1f86462e8d4e92f1,0xd2d96606421d231c7c54431ff415a22e8c155d7de2232d55ecb09df625008d79,1
0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266,0x0000000000000000000000000000000000000000,10,0x0000000000000000000000000000000000000000000000000000000000000000,0x0666416188935fdac3719f82e20b46493774eb44600f7a520dc4a31a9fbfbb72,0xbef8357971406bf6d266f6af61e9088dbc56b771f87e4ed13ca4faafff904c5c,1
0x70997970c51812dc3a010c7d01b50e0d17dc79c8,0x0000000000000000000000000000000000000000,10,0x0000000000000000000000000000000000000000000000000000000000000000,0x320f1479410bca8bd6833e10b3bf4d0866ffc571bc203e863964b2e12adf46a4,0xc0a458ca4aeae8a0bed594610c783c3f5861878d4f89953bd4200d63457fdb1c,0
0x90f79bf6eb2c4f870365e785982e1f101e93b906,0x0000000000000000000000000000000000000000,10,0x0000000000000000000000000000000000000000000000000000000000000000,0xe5de6486e9298cf21a2d98813a0e0fe43b500d1b5b780f1f0ce232e5b4ed6438,0x8f89b487fb8ab46b28c59d6dabe13fa4a5b5dd25ca9053711b6e8ac9e470375f,0
0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266,0x0000000000000000000000000000000000000000,10,0x0000000000000000000000000000000000000000000000000000000000000000,0x7f8236b764c7718e1773339f2176596a3f5673dbc71019aa0ddfe0423c0f0259,0x377071019f912ceefa152992ba01a8fa749ca489c8346620ef3bf9a6a4054134,0
0x70997970c51812dc3a010c7d01b50e0d17dc79c8,0x0000000000000000000000000000000000000000,10,0x0000000000000000000000000000000000000000000000000000000000000000,0xc800c349a178d7530b225bf84c91acf2a7d9f85cae2acf483cb02bb32d62d7fe,0x154232c0260e63dc1b75c44f05683258842a55d9c03d308116db0ada6bbcd548,1
0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc,0x0000000000000000000000000000000000000000,10,0x0000000000000000000000000000000000000000000000000000000000000000,0x1e04379dc9a778df93512f585d4935bd70044d14e8b8f8decd70c66b56fcabd1,0x50ae9622163fec532ccf9a70861b618862aa7488b8e0755eacf72eb23ed23f5b,1
0x70997970c51812dc3a010c7d01b50e0d17dc79c8,0x0000000000000000000000000000000000000000,10,0x0000000000000000000000000000000000000000000000000000000000000000,0x7b3b793e00cb1a77133d312c9fcde2c66f8be34d5e29bc3baa2f02171efc23ee,0xe14dfb9eb659a724b89b6dced033e8566c962ae7d9100b1a58210dd749edc111,0
0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc,0x0000000000000000000000000000000000000000,10,0x0000000000000000000000000000000000000000000000000000000000000000,0x10322a574494aaaf7fce0a38b54ecd2d80874ddec67c1f7020a5070b41ea9346,0x8ad0e7ae98bf7c3250e67de12111bdc30b1ef5f7a37dd2d9658dfcd4e8e54a70,0
0x90f79bf6eb2c4f870365e785982e1f101e93b906,0x0000000000000000000000000000000000000000,10,0x0000000000000000000000000000000000000000000000000000000000000000,0xf2b80ba476f705989e8cc00b884bf16ba41a83abd4a1a8c99fa5a4e4d9656f19,0x2a3312da3142b6dad3fcb2c305d456a8d272f1a09634ebc1f570389f3b0c1122,1
21 changes: 7 additions & 14 deletions eigentrust/src/attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ use crate::{
use eigentrust_zk::{
circuits::{
dynamic_sets::native::{Attestation, SignedAttestation},
ECDSAKeypair, ECDSAPublicKey, ECDSASignature, HASHER_WIDTH, NUM_BITS, NUM_LIMBS,
ECDSAKeypair, ECDSAPublicKey, ECDSASignature, PoseidonNativeHasher, HASHER_WIDTH, NUM_BITS,
NUM_LIMBS,
},
halo2::halo2curves::{ff::FromUniformBytes, secp256k1::Secp256k1Affine},
integer::native::Integer,
params::{hasher::poseidon_bn254_5x5::Params, rns::secp256k1::Secp256k1_4_68},
poseidon::native::Poseidon,
params::rns::secp256k1::Secp256k1_4_68,
};
use ethers::types::{Address, Bytes, Uint8, H160, H256};

Expand Down Expand Up @@ -220,8 +220,7 @@ impl SignedAttestationEth {
let signature = ECDSASignature::from(signature_raw);

// Recover signed attestation hash
let att_hash =
attestation.hash::<HASHER_WIDTH, Poseidon<Scalar, HASHER_WIDTH, Params>>().to_bytes();
let att_hash = attestation.hash::<HASHER_WIDTH, PoseidonNativeHasher>().to_bytes();
let scalar_opt = SecpScalar::from_bytes(&att_hash);
let secp_scalar_att_hash = match scalar_opt.is_some().into() {
true => scalar_opt.unwrap(),
Expand Down Expand Up @@ -616,9 +615,7 @@ mod tests {
let attestation_raw: AttestationRaw = attestation_eth.clone().into();
let attestation_fr = attestation_eth.to_attestation_fr().unwrap();

let message = attestation_fr
.hash::<HASHER_WIDTH, Poseidon<Scalar, HASHER_WIDTH, Params>>()
.to_bytes();
let message = attestation_fr.hash::<HASHER_WIDTH, PoseidonNativeHasher>().to_bytes();
let message_fq = SecpScalar::from_bytes(&message).unwrap();

let signature = keypair.sign(message_fq, rng);
Expand All @@ -645,9 +642,7 @@ mod tests {
let attestation_eth = AttestationEth::default();
let attestation_fr = attestation_eth.to_attestation_fr().unwrap();

let message = attestation_fr
.hash::<HASHER_WIDTH, Poseidon<Scalar, HASHER_WIDTH, Params>>()
.to_bytes();
let message = attestation_fr.hash::<HASHER_WIDTH, PoseidonNativeHasher>().to_bytes();
let message_fq = SecpScalar::from_bytes(&message).unwrap();

let signature = keypair.sign(message_fq, rng);
Expand Down Expand Up @@ -698,9 +693,7 @@ mod tests {

let attestation_fr = attestation_eth.to_attestation_fr().unwrap();

let message = attestation_fr
.hash::<HASHER_WIDTH, Poseidon<Scalar, HASHER_WIDTH, Params>>()
.to_bytes();
let message = attestation_fr.hash::<HASHER_WIDTH, PoseidonNativeHasher>().to_bytes();
let message_fq = SecpScalar::from_bytes(&message).unwrap();

let signature = keypair.sign(message_fq, rng);
Expand Down
16 changes: 6 additions & 10 deletions eigentrust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ use circuit::{Circuit, ETReport, ETSetup, ThPublicInputs, ThReport, ThSetup};
use eigentrust_zk::{
circuits::{
threshold::native::Threshold, ECDSAPublicKey, EigenTrust4, KZGParams, NativeAggregator4,
NativeEigenTrust4, NativeThreshold4, Opinion4, PoseidonNativeSponge, Threshold4,
HASHER_WIDTH, MIN_PEER_COUNT, NUM_DECIMAL_LIMBS, NUM_NEIGHBOURS, POWER_OF_TEN,
NativeEigenTrust4, NativeThreshold4, Opinion4, PoseidonNativeHasher, PoseidonNativeSponge,
Threshold4, HASHER_WIDTH, MIN_PEER_COUNT, NUM_DECIMAL_LIMBS, NUM_NEIGHBOURS, POWER_OF_TEN,
},
halo2::{
arithmetic::Field,
Expand All @@ -79,9 +79,7 @@ use eigentrust_zk::{
poly::commitment::{CommitmentScheme, Params},
SerdeFormat,
},
params::hasher::poseidon_bn254_5x5::Params as PoseidonParams,
poseidon::native::Poseidon,
utils::{big_to_fe_rat, keygen, prove, verify},
utils::{big_to_fe, big_to_fe_rat, fe_to_big, keygen, prove, verify},
verifier::aggregator::native::Snark,
};
use error::EigenError;
Expand Down Expand Up @@ -157,13 +155,11 @@ impl Client {
let attestation_fr = attestation_eth.to_attestation_fr()?;

// Format for signature
let att_hash = attestation_fr
.hash::<HASHER_WIDTH, Poseidon<Scalar, HASHER_WIDTH, PoseidonParams>>()
.to_bytes();
let attestation_fq = SecpScalar::from_bytes(&att_hash).unwrap();
let att_hash_scalar = attestation_fr.hash::<HASHER_WIDTH, PoseidonNativeHasher>();
let att_hash_secp_scalar = big_to_fe(fe_to_big(att_hash_scalar));

// Sign
let signature = keypairs[0].sign(attestation_fq, rng);
let signature = keypairs[0].sign(att_hash_secp_scalar, rng);

let signature_raw = SignatureRaw::from(signature);
let signature_eth = SignatureEth::from(signature_raw);
Expand Down

0 comments on commit 08d392c

Please sign in to comment.