Cyfrin / 2023-07-escrow

17 stars 12 forks source link

CodeHawks Escrow Contract

Contest Details

Project Overview

About

This project is meant to enable smart contract auditors (sellers) and smart contract protocols looking for audits (buyers) to connect using a credibly neutral option, with optional arbitration.

Actors

Create an Escrow

  1. Buyer approves the payment contract to be handled by EscrowFactory.
  2. Buyer calls EscrowFactory::newEscrow, inputs:
    1. The price.
    2. The payment token.
    3. The seller (auditor or person in charge of the audit).
    4. Arbiter.
    5. Arbiter fee: Fee to pay in case of a dispute is initialized.
    6. Salt: for create2 Escrow deployment.

Expected sucessful workflow

  1. The buyer creates an Escrow contract through EscrowFactory::newEscrow, depositing the funds.
  2. The seller sends the buyer the report (off-chain).
  3. The buyer acknowledges this report on-chain by calling Escrow::confirmReceipt. This sends the funds to the seller.

Expected dispute workflow

  1. The buyer creates an Escrow contract through EscrowFactory::newEscrow, depositing the funds.
  2. For any reason, the buyer or the seller can initiate a dispute through Escrow::initiateDispute.
  3. The arbiter confers with both parties offchain. Arbiter then calls Escrow::resolveDispute, reimbursing either side accordingly, emptying the Escrow.

Acknowledgements

In Scope

All contracts in src are in scope.

Note on script folder: The contracts in script are the scripts you can assume are going to be used to deploy and interact with the contracts. If they have an issue that will affect the overall security of the system, they are in scope. However, if they have a security issue that only affects the script and not the overall deployment of the escrow protocol, it is out of scope.

Known Issues

Getting Started

Requirements

Quickstart

git clone https://github.com/Cyfrin/2023-07-escrow 
cd escrow 
forge build

Usage

Testing

forge test

Test Coverage

forge coverage

and for coverage based testing:

forge coverage --report debug

Start a local node

make anvil

Deploy

This will default to your local node. You need to have it running in another terminal in order for it to deploy.

make deploy

Deploy - Other Network

See below

Deployment to a testnet or mainnet

  1. Setup environment variables

You'll want to set your SEPOLIA_RPC_URL and PRIVATE_KEY as environment variables. You can add them to a .env file, similar to what you see in .env.example.

Optionally, add your ETHERSCAN_API_KEY if you want to verify your contract on Etherscan.

  1. Get testnet ETH

Head over to faucets.chain.link and get some tesnet ETH. You should see the ETH show up in your metamask.

  1. Deploy
make deploy ARGS="--network sepolia"

Estimate gas

You can estimate how much gas things cost by running:

forge snapshot

And you'll see and output file called .gas-snapshot

Formatting

To run code formatting:

forge fmt