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 refundOnFraud #73

Merged
merged 16 commits into from
Dec 15, 2021
Merged

Add refundOnFraud #73

merged 16 commits into from
Dec 15, 2021

Conversation

kerzhner
Copy link
Contributor

@kerzhner kerzhner commented Dec 15, 2021

Fixes #59.

There are 2 cases of fraud:

  1. A ticket t is created on deposit. The ticket is authorized as part of a batch. The liquidity provider (LP) also signs another batch that contains a ticket with the same index as t but different data.
    2. Same as above but t is never authorized.

In the second case, a new batch is created on fraud proof. The batch includes all tickets from the last authorized ticket (exclusive) to the ticket that is being "cheated" (inclusive).

On more thought, it doesn't seem like we need to take care of the second case. The customer can:

  • prove fraud if the ticket is authorized before the auth window expires.
  • get their funds back after the auth window expires if the ticket is never authorized.

import { L2, L2DepositStruct } from "../contract-types/L2";
import { TicketsWithIndex } from "../src/types";
import { hashTickets, signData } from "../src/utils";

const gasLimit = 30_000_000;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit but we could throw this in a common file shared between tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, let's do that once we have more than one test file.

Copy link
Contributor

@lalexgap lalexgap left a comment

Choose a reason for hiding this comment

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

LGTM 🌋

Co-authored-by: Alex Gap <[email protected]>
@kerzhner kerzhner merged commit e0fddce into main Dec 15, 2021
@kerzhner kerzhner deleted the fraud branch December 15, 2021 23:25
Comment on lines +157 to +159
bytes32 message = keccak256(
abi.encode(TicketsWithIndex(fraudStartNonce, fraudTickets))
);
Copy link
Contributor

Choose a reason for hiding this comment

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

This ought to be factored into some common utils library contract, since the exact same computation needs to be computed in both L1 and L2.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Filed #77

(bool sent, ) = tickets[i].l1Recipient.call{
value: tickets[i].value
}("");
require(sent, "Failed to send Ether");
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI this is a critical security vulnerability. Alice can submit a ticket with a contract address that rejects all incoming eth transfers. This prevents everyone from calling refundOnFraud.

Copy link
Contributor Author

@kerzhner kerzhner Dec 16, 2021

Choose a reason for hiding this comment

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

That's a good call. Contract fund distribution needs to be refactored to:

  • Factor out this logic.
  • FIx the security concern
  • Add erc20 support

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Filed #78

This was referenced Dec 16, 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.

Add fraud proofs to the prototype
3 participants