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

fix: Gateway Enforce Routing Fees #4412

Merged
merged 1 commit into from
Mar 6, 2024

Conversation

m1sterc001guy
Copy link
Contributor

In debugging #4350 I realized that the gateway is not independently verifying that the client attached routing fees to the contract. We check if the contract is underfunded, but only against the invoice amount, not invoice amount + gateway fee.

This PR adds gateway enforcement of fees and adds a test that verifies clients cannot cheat and not pay fees.

@elsirion
Copy link
Contributor

Iirc we don't check that fees were paid but only allow the LN node to pay as much in fees as the user. We don't have a guarantee of making money anyway rn (could introduce a fee margin that's guaranteed to go to the gateway to fix this).

@m1sterc001guy
Copy link
Contributor Author

Right now the only check we have is if a contract is "underfunded", which essentially just compares the amount in the contract to the amount that the client tells the gateway to pay. The issue is that, if the gateway is charging a routing fee, we do not currently independently compute that fee. So malicious clients could create a contract that pays exactly the amount that the invoice is, and the gateway won't enforce that their fee is included.

This is hard to exploit currently since it requires a malicious client to not attach fees for the gateway. In practice though this probably can occur if a gateway changes their advertised fees, since it might not re-register with the federation for another ~10mins.

@m1sterc001guy
Copy link
Contributor Author

@elsirion let me know if you think this is still necessary, I think we're on the same page. This essentially just turns the under-funding of a contract (without fees) into an explicit error, whereas before the gateway would rely on routing on the LN to make a profit

@m1sterc001guy m1sterc001guy marked this pull request as ready for review February 28, 2024 21:26
@m1sterc001guy m1sterc001guy requested review from a team as code owners February 28, 2024 21:26
@m1sterc001guy m1sterc001guy marked this pull request as draft February 28, 2024 21:51
@m1sterc001guy m1sterc001guy marked this pull request as ready for review February 29, 2024 16:54
Copy link
Contributor

@elsirion elsirion left a comment

Choose a reason for hiding this comment

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

I don't think it's super useful rn, but it's well-tested and might become useful if we ever want to enforce profit for gateways.

@justinmoon justinmoon added this pull request to the merge queue Mar 5, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 5, 2024
@justinmoon justinmoon added this pull request to the merge queue Mar 5, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 5, 2024
@m1sterc001guy m1sterc001guy added this pull request to the merge queue Mar 6, 2024
Merged via the queue into fedimint:master with commit 348c4d3 Mar 6, 2024
20 checks passed
@m1sterc001guy m1sterc001guy deleted the enforce_fees branch March 6, 2024 06:08
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

3 participants