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

Coinbase in snark: coinbase split and no coinbase cases #1936

Merged
merged 5 commits into from Mar 28, 2019

Conversation

deepthiskumar
Copy link
Member

Handles the following two cases when checking pending coinbases in blockchain snark

  1. when a coinbase is split into two parts
  2. No coinbase in a block

@deepthiskumar deepthiskumar changed the title handle coinbase split and no coinbase case Coinbase in snark: coinbase split and no coinbase cases Mar 19, 2019
Currency.Amount.var_of_t Protocols.Coda_praos.coinbase_amount
in
let%bind rem_amount, `Underflow underflowed =
Currency.Amount.Checked.sub_flagged total_coinbase_amount amount
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to use sub_flagged if you are going to assert there is no underflow.

let%bind amount2_equal_to_zero = equal_to_zero rem_amount in
let%bind stack_with_amount1 =
Coinbase_stack.Stack.Checked.push stack
(pk, Amount.Signed.Checked.of_unsigned amount)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an opportunity to save a lot of hashing here. Hashing a public key is about 1000 constraints and that could be shared between the two pushes. Maybe make an issue with an 'optimization' label

@deepthiskumar deepthiskumar merged commit 27938bc into fix/pending_coinbase Mar 28, 2019
@deepthiskumar deepthiskumar deleted the fix/cb-split branch March 28, 2019 18:25
deepthiskumar added a commit that referenced this pull request Mar 29, 2019
Implements in-SNARK check for coinbases. 
How:
1) A transaction snark now has a set of coinbases  (`Pending_coinbase.Stack`) that it includes.
2) Maintain a collection of coinbases included so far and subtract from it, the set of coinbases included in a ledger proof. This collection called `Pending coinbases` represents all the coinbases that are yet to be included in ledger proofs.
In blockchain snark, a new coinbase is added and the set of coinbases included in a ledger proof is subtracted. Also, handles the cases (#1936)
    1) when there is no coinbase included in the transition 
    2) when a coinbase is split into two parts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants