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
Conversation
…s need to be added in the unchecked version
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
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.
Handles the following two cases when checking pending coinbases in blockchain snark