-
Notifications
You must be signed in to change notification settings - Fork 105
Add Proof of Work #75
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
Open
tsunrise
wants to merge
12
commits into
arkworks-rs:main
Choose a base branch
from
tsunrise:poW
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8ea942c
add poW interface
tsunrise f2f55aa
update api
tsunrise be56bac
poW interface
tsunrise 5b3fc5d
proof of work native code
tsunrise 8e8049b
fix CI bug
tsunrise e342f9d
PoW constraints midway
tsunrise 1e596df
update constraints and tests
tsunrise 6e80af2
add CHANGELOG
tsunrise 291a9b6
fix no-std, reduce pow difficulty in test a little bit
tsunrise f98fac5
fmt
tsunrise b65ef73
Merge branch 'main' into poW
Pratyush 21b6de5
Merge branch 'main' into poW
ValarDragon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ on: | |
pull_request: | ||
push: | ||
branches: | ||
- master | ||
- main | ||
env: | ||
RUST_BACKTRACE: 1 | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
pub mod poseidon; | ||
|
||
use ark_ff::PrimeField; | ||
use ark_r1cs_std::{alloc::AllocVar, boolean::Boolean}; | ||
use ark_relations::r1cs::{ConstraintSystemRef, SynthesisError}; | ||
use ark_std::borrow::Borrow; | ||
|
||
use super::{CryptoHash, PoW}; | ||
|
||
/// R1CS Gadget for Crypto Hash. | ||
pub trait CryptoHashGadget<CF: PrimeField> { | ||
type Parameters; | ||
/// Input of the hash | ||
type InputVar: ?Sized; | ||
/// Outout of the Hash | ||
type OutputVar; | ||
|
||
/// Given the input var and parameters, compute the output var. | ||
fn digest<T: Borrow<Self::InputVar>>( | ||
cs: ConstraintSystemRef<CF>, | ||
param: &Self::Parameters, | ||
input: T, | ||
) -> Result<Self::OutputVar, SynthesisError>; | ||
} | ||
|
||
/// R1CS Gadget for Proof of Work | ||
pub trait PoWGadget<CF: PrimeField>: CryptoHashGadget<CF> { | ||
type NonceVar; | ||
/// Given input var and nonce var, check whether `H(input||nonce)` is a | ||
/// valid proof of work under certain difficulty. | ||
fn verify( | ||
cs: ConstraintSystemRef<CF>, | ||
param: &Self::Parameters, | ||
input: &Self::InputVar, | ||
nonce: &Self::NonceVar, | ||
difficulty: usize, | ||
) -> Result<Boolean<CF>, SynthesisError>; | ||
} | ||
|
||
/// Extension trait for crypto hash to get the gadget. | ||
pub trait CryptoHashWithGadget<CF: PrimeField>: CryptoHash | ||
where | ||
<Self::Gadget as CryptoHashGadget<CF>>::OutputVar: AllocVar<Self::Output, CF>, | ||
{ | ||
type Gadget: CryptoHashGadget<CF, Parameters = Self::Parameters>; | ||
} | ||
|
||
/// Extension trait for PoW to get the gadget. | ||
pub trait PoWWithGadget<CF: PrimeField>: PoW | ||
where | ||
<Self::Gadget as CryptoHashGadget<CF>>::OutputVar: AllocVar<Self::Output, CF>, | ||
{ | ||
type Gadget: PoWGadget<CF, Parameters = Self::Parameters>; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.