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

Add debug method for constructing valid consignments #221

Closed
wants to merge 3 commits into from

Conversation

dr-orlovsky
Copy link
Member

Closes #211

@dr-orlovsky dr-orlovsky added the enhancement New feature or request label Jun 18, 2024
@dr-orlovsky dr-orlovsky added this to the v0.11.0 milestone Jun 18, 2024
@dr-orlovsky dr-orlovsky requested review from nicbus and zoedberg June 18, 2024 19:59
@dr-orlovsky dr-orlovsky self-assigned this Jun 18, 2024
Copy link
Contributor

@nicbus nicbus left a comment

Choose a reason for hiding this comment

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

I see the method is documented as "for debug purposes". I don't think this should be a "debug" method, as it's going to be used in "production" code, like accepting the consignment for a funding transaction when opening an RGB LN channel. Having it documented as "debug" makes me think it can be easily dropped in the future without worrying about code that might use it, similar to what happened to the force parameter in accept_transfer. I think this needs to be documented as a method that's intended for special cases and should not be used if you don't know what you're doing, not a debug one.

The method is defined as unsafe, but it doesn't seem unsafe in the rust sense, so I think it should be named unsafe (e.g. assume_valid_unsafe) but not defined as rust unsafe, as that's not the case and it forces users to wrap calls into an unneeded unsafe block.

The comment says this violates type safety. I get the general idea, but what do you mean exactly?

I'm not sure about the custom validation failure. Having a custom warning or info makes sense to me, but a failure feels wrong, as the whole purpose of the method is to render the consignment valid, while a failure indicates validation failed.

@dr-orlovsky
Copy link
Member Author

dr-orlovsky commented Jun 19, 2024

What you say makes perfect sense if this method is required for normal lightning functioning. But I do not see the scenario whether it is required. Can you please give me more information why a node must accept consignment for lightning channel funding without a validation?

The type safety is the fact that given type provides certain guarantees on its data at runtime which are ensured by the compiler at compile-time (here it is the concept of the validation) - meaning that the method is unsafe in pure rust sense, since it allows to bypass such validation and breaks compile-time type guarantees. Thus, unsafe is required to notify a user about that happening at compile-time.

@nicbus
Copy link
Contributor

nicbus commented Jun 20, 2024

What you say makes perfect sense if this method is required for normal lightning functioning. But I do not see the scenario whether it is required. Can you please give me more information why a node must accept consignment for lightning channel funding without a validation?

A node needs to accept the funding transaction consignment (which allocates RGB assets to the multisig output) before it's broadcast, in order to generate the first pair of commitment transactions (spending the funding and allocating the RGB assets to the local and remote outputs).

To be precise, the requirement is not that the consignment is not validated. It just needs to be accepted even if the witness transaction is still missing from the blockchain, as that's expected.

The type safety is the fact that given type provides certain guarantees on its data at runtime which are ensured by the compiler at compile-time (here it is the concept of the validation) - meaning that the method is unsafe in pure rust sense, since it allows to bypass such validation and breaks compile-time type guarantees. Thus, unsafe is required to notify a user about that happening at compile-time.

I'm not sure I follow you here. There doesn't seem to be anything that the compiler is checking that would fail if validation is skipped. Instead, it's business logic that's not run when validation is not executed, but this is not at the rust compiler level. To prove that to myself, I dropped the unsafe keyword from the assume_valid method definition and it still compiles fine.

I get your point, you're trying to protect users from unwanted behavior and risks, and I support that, but I don't see the need to use a rust feature in an improper way to drive the point home. Naming and documentation are in my opinion the correct choice here.

Moreover, as said above, it's not even the case that this method should do anything "wrong". The need here is to be able to accept a (valid) consignment before the witness transaction has been broadcast. In the context of a funding transaction and a pair of commitment transactions there is no issue, as there's no point in broadcasting a commitment if the funding has never been broadcast itself. On the other hand, broadcasting the funding before constructing the first pair of commitments would be a serious issue.

@dr-orlovsky
Copy link
Member Author

To be precise, the requirement is not that the consignment is not validated. It just needs to be accepted even if the witness transaction is still missing from the blockchain, as that's expected.

Well, we have discussed that: you just need to report the witness transaction as valid: this is the task which must be handled by the lightning node resolver. No need in force-converting anything.

There doesn't seem to be anything that the compiler is checking that would fail if validation is skipped. <...> To prove that to myself, I dropped the unsafe keyword from the assume_valid method definition and it still compiles fine.

Sorry, now I can't understand what you are saying. Of course if you remove unsafe it will compile fine, that's why unsafe keyword is needed to ensure that compiler notifies about type safety violation!

For the history record, I am strongly against having and using this method, since it violates the security model.

Details: #211 (comment)

Strong conceptual NACK on merging this PR
@dr-orlovsky
Copy link
Member Author

For the history record, I am strongly against having and using this method, since it violates the security model.

Details: #211 (comment)

Strong conceptual NACK on merging this PR

@nicbus
Copy link
Contributor

nicbus commented Jun 28, 2024

@dr-orlovsky I have pushed a commit on top of yours, to rephrase the docstring and add stronger warnings against the usage of this method. Please let me know if you think this is enough or, if you think even stronger language should be used, what you would add, so I can further improve it.

Copy link
Member Author

@dr-orlovsky dr-orlovsky left a comment

Choose a reason for hiding this comment

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

Strong NACK

@@ -389,14 +389,14 @@ impl<const TRANSFER: bool> Consignment<TRANSFER> {
}
}

/// Method to construct valid consignment which can be consumed by a stash
/// for debug purposes.
/// Method to forcefully construct a valid consignment, which can be consumed by a stash.
///
Copy link
Member Author

@dr-orlovsky dr-orlovsky Jun 28, 2024

Choose a reason for hiding this comment

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

Sorry, I strictly disagree with this. It has no - and must not has (!) any other use than the debug purposes, since any other use is literally a security leak. My opinion is so strong, that until the public audit conclusion on this issue I will just fork this repository and will contribute to the fork not having this security issue.

Comment on lines +397 to +398
/// used improperly this could lead to loss of funds. The method must be used only for special
/// purposes where it's necessary to consume a consignment even though standard rules prevent
Copy link
Member Author

Choose a reason for hiding this comment

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

There are no other "special purposes" than debugging!

@nicbus
Copy link
Contributor

nicbus commented Jul 5, 2024

We had a misunderstanding. I took you giving me permission to merge as an ACK but it's then become clear that that was not the case. It was never my intention to merge this against your will and reasoning. Quite the opposite, the idea was to cooperate to find the best solution.

Since then, we had discussions elsewhere and it has all been clarified. This solution is not good for production code, so it's not what we desire either.

A better alternative has been found in #233, which makes this PR no more needed, so I'm closing it.

@nicbus nicbus closed this Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

no more possible to force accepting a transfer
2 participants