Skip to content

Do not attempt to construct 0-amount TxOuts#58

Merged
luckysori merged 3 commits into
masterfrom
pesky-change-outputs
Aug 11, 2021
Merged

Do not attempt to construct 0-amount TxOuts#58
luckysori merged 3 commits into
masterfrom
pesky-change-outputs

Conversation

@luckysori
Copy link
Copy Markdown
Collaborator

@luckysori luckysori commented Aug 10, 2021

Fix #38.

On the way, I noticed that after replacing the blockchain-based testing with elements-consensus (PR #34) we were no longer verifying that our transactions were not printing (or destroying) money. That's the motivation for b005a04.

Please review patch by patch.

The test wallet creates UTXOs out of thin air during coin selection.
We use these UTXOs as inputs in our protocol transactions.

When verifying these transactions, the UTXOs that we created are
assumed to be correct: that is, their previous outputs are not
verified (which is why we're creating coins out of thin air).

Therefore, when creating these UTXOs the value of the nonexistent
previous outputs can be anything. We set it to zero to stress the fact
that money is being created.

Conversely, the explicit asset ID must be part of the list of
nonexistent previous outputs in order to produce a valid surjection
proof.
When moving away from blockchain-node based tests we unknowingly relaxed
the requirements on our transactions, which was a problem.
A transaction may correctly spend its inputs and still be invalid by
virtue of being inflationary (or deflationary).

We have now added checks to ensure that all transactions have correct
assets, amounts and proofs.
Comment thread src/loan.rs Outdated
Comment thread src/loan.rs Outdated
Comment thread tests/loan_protocol.rs
Comment thread tests/util.rs
///
/// The corresponding UTXOs are generated ad hoc and subsequently
/// stored in the internal state of the wallet.
pub fn coin_select(&mut self, amount: Amount, asset: AssetId) -> Result<Vec<Input>> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe this should be called mint instead then? :)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure about this one.

I think the fact that the coins didn't exist before the call is just an implementation detail and we really just care about selecting coins when calling this.

I only added the docstring because a previous version of this change introduced some other arguments which made the whole test API worth explaining. Without that I think the API doesn't need to be documented, but it can't hurt.

Copy link
Copy Markdown
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

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

Looks good!

If you find c34e568 too noisy, you can always extract functions for the shared code to reduce the duplication.

@luckysori
Copy link
Copy Markdown
Collaborator Author

Looks good!

If you find c34e568 too noisy, you can always extract functions for the shared code to reduce the duplication.

I'll pass this time because it's only duplicated once and a function which adds the outputs (if needed) to tx_outs and before_last_confidential_output_secrets would need to take in rng and secp as arguments, which is quite annoying.

Change outputs are now only added to the loan transaction if
necessary. This fixes bug
#38.

We therefore no longer need to always add a buffer to the amount we
select coins for. The original loan protocol tests now use the least
number of outputs possible (we still need to a collateral change
output for the loan transaction because we don't know the transaction
fee ahead of time. See:
#57).

To verify that we still allow the presence of change
outputs (principal change outputs in particular), we've added the test
`can_run_protocol_with_principal_change_outputs`.
@luckysori luckysori force-pushed the pesky-change-outputs branch from c34e568 to 7433efd Compare August 11, 2021 06:38
@luckysori luckysori merged commit a23f0e1 into master Aug 11, 2021
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.

Loan protocol assumes presence of change outputs

2 participants