Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZK Email Test #20

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
members = [
"account"
"account",
]

[workspace.dependencies]
Expand Down
14 changes: 14 additions & 0 deletions account/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,17 @@ futures = "0.3.29"
async-trait = "0.1.74"
prost = {version = "0.11.2", default-features = false, features = ["prost-derive"]}
osmosis-std-derive = "0.13.2"
#num-bigint = "0.4.5"

# zk deps
ark-crypto-primitives = { version = "=0.4.0" }
ark-ec = { version = "=0.4.2", default-features = false }
ark-ff = { version = "=0.4.2", default-features = false, features = [ "asm"] }
ark-std = { version = "=0.4.0", default-features = false }
ark-bn254 = { version = "=0.4.0" }
ark-groth16 = { version = "=0.4.0", default-features = false }
ark-relations = { version = "=0.4.0", default-features = false }
ark-serialize = { version = "=0.4.2", default-features = false }
ark-poly = { version = "=0.4.2", default-features = false }
ark-circom = { git = "https://github.com/mvid/circom-compat" }
poseidon-ark = {git = "https://github.com/arnaucube/poseidon-ark"}
50 changes: 44 additions & 6 deletions account/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

mod eth_crypto;
mod groth16;
pub mod jwt;
pub mod passkey;
mod secp256r1;
mod sign_arb;
pub mod util;
pub(crate) mod zkemail;

#[derive(Serialize, Deserialize, Clone, JsonSchema, PartialEq, Debug)]
pub enum AddAuthenticator {
Expand Down Expand Up @@ -44,6 +46,13 @@ pub enum AddAuthenticator {
url: String,
credential: Binary,
},
ZKEmail {
id: u8,
vkey: Binary,
email_hash: Binary,
email_domain: String,
proof: Binary,
},
}

impl AddAuthenticator {
Expand All @@ -55,18 +64,38 @@ impl AddAuthenticator {
AddAuthenticator::Jwt { id, .. } => *id,
AddAuthenticator::Secp256R1 { id, .. } => *id,
AddAuthenticator::Passkey { id, .. } => *id,
AddAuthenticator::ZKEmail { id, .. } => *id,
}
}
}

#[derive(Serialize, Deserialize, Clone, JsonSchema, PartialEq, Debug)]
pub enum Authenticator {
Secp256K1 { pubkey: Binary },
Ed25519 { pubkey: Binary },
EthWallet { address: String },
Jwt { aud: String, sub: String },
Secp256R1 { pubkey: Binary },
Passkey { url: String, passkey: Binary },
Secp256K1 {
pubkey: Binary,
},
Ed25519 {
pubkey: Binary,
},
EthWallet {
address: String,
},
Jwt {
aud: String,
sub: String,
},
Secp256R1 {
pubkey: Binary,
},
Passkey {
url: String,
passkey: Binary,
},
ZKEmail {
vkey: Binary,
email_hash: Binary,
email_domain: String,
},
}

impl Authenticator {
Expand Down Expand Up @@ -134,6 +163,15 @@ impl Authenticator {

Ok(true)
}
Authenticator::ZKEmail {
vkey,
email_hash,
email_domain,
} => {
let verification =
zkemail::verify(deps, tx_bytes, sig_bytes, vkey, email_hash, email_domain)?;
Ok(verification)
}
}
}
}
35 changes: 35 additions & 0 deletions account/src/auth/groth16.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use ark_bn254::{Bn254, Config, FrConfig};
use ark_circom::CircomReduction;
use ark_ec::bn::Bn;
use ark_ff::Fp;
use ark_ff::MontBackend;
use ark_groth16::{Groth16, Proof, VerifyingKey};

pub type GrothBnVkey = VerifyingKey<Bn254>;
pub type GrothBnProof = Proof<Bn<Config>>;
pub type GrothBn = Groth16<Bn254, CircomReduction>;
pub type GrothFp = Fp<MontBackend<FrConfig, 4>, 4>;

// pub fn verify(
// sig_bytes: &Binary,
// vkey_bytes: &Binary,
// public_inputs: Vec<Binary>,
// ) -> ContractResult<bool> {
// // vkey serialization is checked on submission
// let vkey = GrothBnVkey::deserialize_compressed_unchecked(vkey_bytes.as_slice())?;
// // proof submission is from the tx, we can't be sure if it was properly serialized
// let proof = GrothBnProof::deserialize_compressed(sig_bytes.as_slice())?;
//
// // always set the hash of the msg as the first input
// let mut inputs : Vec<GrothFp> = Vec::with_capacity(public_inputs.len() + 1);
//
//
// for (i, input) in public_inputs.iter().enumerate() {
// let field = GrothFp::deserialize_compressed_unchecked(input.as_slice())?;
// inputs.insert(i + 1, field);
// }
//
// let verified = GrothBn::verify(&vkey, inputs.as_slice(), &proof)?;
//
// Ok(verified)
// }
28 changes: 28 additions & 0 deletions account/src/auth/tests/data/body/proof.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"pi_a": [
"9486340724577477249815467768769565374934710026736305109752163023373354578612",
"16595063117796305171760460016042328961018653193377585716583045844805071841599",
"1"
],
"pi_b": [
[
"15491264152825748590029447218148256248473988578817729538699311131440825393644",
"19462514041399683597482765086908960340353042180369716645718093611043705151012"
],
[
"20241959550617149821288911346280456034302280506079785522502994301819688107545",
"20644947903098290510063118194160281983863933085928585247885789968019211628597"
],
[
"1",
"0"
]
],
"pi_c": [
"18420280649391078563720004345449852444323762937315481448018256238127540442626",
"8856984219224857707116161878971000467554451367973593470894648547432366368070",
"1"
],
"protocol": "groth16",
"curve": "bn128"
}
5 changes: 5 additions & 0 deletions account/src/auth/tests/data/body/public.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
"21532090391056315603450239923154193952164369422267200983793686866358632420524",
"20222897760242655042591071331570003228637614099423116142933693104079157558229",
"6632353713085157925504008443078919716322386156160602218536961028046468237192"
]
104 changes: 104 additions & 0 deletions account/src/auth/tests/data/body/vkey.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{
"protocol": "groth16",
"curve": "bn128",
"nPublic": 3,
"vk_alpha_1": [
"20491192805390485299153009773594534940189261866228447918068658471970481763042",
"9383485363053290200918347156157836566562967994039712273449902621266178545958",
"1"
],
"vk_beta_2": [
[
"6375614351688725206403948262868962793625744043794305715222011528459656738731",
"4252822878758300859123897981450591353533073413197771768651442665752259397132"
],
[
"10505242626370262277552901082094356697409835680220590971873171140371331206856",
"21847035105528745403288232691147584728191162732299865338377159692350059136679"
],
[
"1",
"0"
]
],
"vk_gamma_2": [
[
"10857046999023057135944570762232829481370756359578518086990519993285655852781",
"11559732032986387107991004021392285783925812861821192530917403151452391805634"
],
[
"8495653923123431417604973247489272438418190587263600148770280649306958101930",
"4082367875863433681332203403145435568316851327593401208105741076214120093531"
],
[
"1",
"0"
]
],
"vk_delta_2": [
[
"14345992153582161880971865267913618523146957714694716213282131661562558491761",
"6733882406776158461127864452161262446285604514866075833544762678895926915330"
],
[
"15984385177079091217300145552460119836441615678900442211248593066956088589534",
"578071878629050791318217304141211096527475288286893424579973168667775996993"
],
[
"1",
"0"
]
],
"vk_alphabeta_12": [
[
[
"2029413683389138792403550203267699914886160938906632433982220835551125967885",
"21072700047562757817161031222997517981543347628379360635925549008442030252106"
],
[
"5940354580057074848093997050200682056184807770593307860589430076672439820312",
"12156638873931618554171829126792193045421052652279363021382169897324752428276"
],
[
"7898200236362823042373859371574133993780991612861777490112507062703164551277",
"7074218545237549455313236346927434013100842096812539264420499035217050630853"
]
],
[
[
"7077479683546002997211712695946002074877511277312570035766170199895071832130",
"10093483419865920389913245021038182291233451549023025229112148274109565435465"
],
[
"4595479056700221319381530156280926371456704509942304414423590385166031118820",
"19831328484489333784475432780421641293929726139240675179672856274388269393268"
],
[
"11934129596455521040620786944827826205713621633706285934057045369193958244500",
"8037395052364110730298837004334506829870972346962140206007064471173334027475"
]
]
],
"IC": [
[
"7951171114052058114210571456576315691065569141997029278491902468174165478965",
"20335962687331827421246322525435762889252382627585156964702009826257851264036",
"1"
],
[
"7330014821396148394236132127538750105962713811161715181957165645835481003125",
"12325348037179958709803910818343189562984687439723938848520994652485090354723",
"1"
],
[
"9721145950265492111388975673508542178053548698525174925389085154452032063972",
"13379203615323694528254447897475070437540248944610579390279851636480933624255",
"1"
],
[
"13387364329730302076536466322304460204720811884853423556199852720229049521654",
"20207602288794005773836486958735300779607791206988770430429334551450773640996",
"1"
]
]
}
28 changes: 28 additions & 0 deletions account/src/auth/tests/data/subject/proof.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"pi_a": [
"3744403570672639821789417402353271888469645983522554820114792135865678961319",
"20910735796870022455731066412680166498701031687570634350375585298974629258184",
"1"
],
"pi_b": [
[
"3103280587755055042639234876461407499305677804150579012080214381236944331783",
"12397599641172557561607120353966437739537754146619912524895930347724545663768"
],
[
"12445745361744452805418592735063499909355061793258849264058539757391135226798",
"3296966646938399932134645629604639355156162091891478991823494597820981759727"
],
[
"1",
"0"
]
],
"pi_c": [
"14590530280877902384246406957315030619305123587511663866831583498851586284568",
"17586447777466290939555473104287554842821230951980477297762774062950221143284",
"1"
],
"protocol": "groth16",
"curve": "bn128"
}
5 changes: 5 additions & 0 deletions account/src/auth/tests/data/subject/public.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
"21532090391056315603450239923154193952164369422267200983793686866358632420524",
"20222897760242655042591071331570003228637614099423116142933693104079157558229",
"6632353713085157925504008443078919716322386156160602218536961028046468237192"
]
Loading
Loading