Skip to content
FairblockPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

8 Commits

Folders and files

Repository files navigation

DeBid

In this tutorial, we provide step by step instructions to test our sealed bid auctions.

Requirements

First make sure you have both Rust and Go installed on your system.

Next, clone the following repositories and install them:

git clone https://github.com/Fairblock/GatewayContract.git
git clone -b feat/arbitrum https://github.com/Fairblock/fairyring.git
git clone https://github.com/Fairblock/fairyringclient.git
git clone https://github.com/Fairblock/ShareGenerationClient.git
git clone -b feat/evm-support --single-branch https://github.com/Fairblock/fairyport.git
git clone --recurse-submodules https://github.com/Fairblock/ArbitrumContracts.git

cd GatewayContract && forge build && cd ..
cd fairyringclient && go install && cd ..
cd ShareGenerationClient && go mod tidy && go install && cd ..
cd fairyring && make install && cd ..
cd fairyport && make install && cd ..
cd ArbitrumContracts && forge build && cd ..

Local Fairyring Setup

Run a local version of fairyring to provide encryption and decryption keys.

cd fairyring
make devnet-up
cd ..

Gateway Contract Deployment

Deploy the Gateway contract on Arbitrum Sepolia Testnet to facilitate the communication between Fairyring and Arbitrum.

cd GatewayContract
forge script script/Gateway.s.sol:GatewayScript --rpc-url $SEPOLIA_RPC_URL --private-key $DEPLOYER_KEY --broadcast
cd ..

Fairyport Setup

Next, set up and run Fairyport to connect Gateway contract and Fairyring. Replace ${GATEWAY_ADDRESS} with the address of Gateway contract deployed in the previous step and ${DEPLOYER_KEY} with the same private key as used for Gateway development.

CONFIG_FILE="$HOME/.fairyport/config.yml"

mkdir -p "$(dirname "$CONFIG_FILE")"

cat >"$CONFIG_FILE" <<YAML
cosmosrelayconfig:
    derivepath: m/44'/118'/0'/0/0
    destinationnode:
        accountprefix: fairy
        chainid: fairyring_devnet
        grpcport: 9090
        ip: 127.0.0.1
        port: 26657
        protocol: tcp
    metricsport: 2224
evmrelaytarget:
    chainrpc:  ${ARBITRUM_SEPOLIA_RPC}
    contractaddress: ${GATEWAY_ADDRESS}
fairyringnodews:
    ip: 127.0.0.1
    port: 26657
    protocol: tcp
YAML

cd fairyport
touch .env
cat > .env <<EOF
EVM_PKEY=${DEPLOYER_KEY}
COSMOS_MNEMONIC="rend powder seat defy design column life tape second zebra myth cousin tell gravity good trash joy report eyebrow woman uncle lounge describe clarify"
EOF
nohup fairyport start --config $HOME/.fairyport/config.yml > fairyport.log 2>&1 </dev/null &
cd ..

Decrypter Contract Deployment

In this step, we deploy the decrypter contracts on Arbitrum to later be used for decryption. Before running the below commands, make sure to set PRIVATE_KEY_1 and rpc_url in ArbitrumContracts/.env:

cd ArbitrumContracts
./deploy_decryption_contracts_verbose.sh
cd ..

After running the above script, you will have the address of the Decrypter contract on Arbitrum.

Creating and Testing an Auction

First deploy the MultiAuction contract which allows for creating several auctions. Replace $DEPLOYED_DECRYPTER_ADDRESS with the address of the deployed decrypter contract in the previous step.

source .env
forge create --broadcast --rpc-url $SEPOLIA_RPC_URL --private-key $AUCTIONEER_PRIVATE_KEY arbitrum/MultiAuctionV2.sol:MultiAuction --constructor-args $DEPLOYED_DECRYPTER_ADDRESS

Next, before creating an auction, get a new general ID (FAIRYRING_ID) from Fairyring to assign to our auction. ADDR is the :

  GATEWAY_ID=$(cast call $GATEWAY_ADDRESS "addressGeneralID(address)(uint256)" $AUCTIONEER_ADDR --rpc-url $SEPOLIA_RPC_URL)
  cast send $GATEWAY_ADDRESS "requestGeneralID()" --rpc-url $SEPOLIA_RPC_URL --private-key $AUCTIONEER_PRIVATE_KEY

  while true; do
    raw=$(cast call "$GATEWAY_ADDRESS" "fids(address,uint256)(string)" "$AUCTIONEER_ADDR" "$GATEWAY_ID" --rpc-url "$SEPOLIA_RPC_URL" 2>/dev/null || echo "")
    FAIRYRING_ID=$(echo "$raw" | tr -d '"[:space:]')
    [[ -n "${FAIRYRING_ID// }" ]] && { echo "✔️  Found FAIRYRING_ID: $FAIRYRING_ID"; break; }
    sleep 2
  done

Now, create a new auction using the createAuction function on the MutliAcution contract and pass GATEWAY_ID and FAIRYRING_ID.

In order to encrypt bids for the auction, first fetch the public key from Gateway contract and then use the encrypter tool for encryption:

cd ArbitrumContracts
PUBLIC_KEY=$(cast call $GATEWAY_ADDRESS "latestEncryptionKey()(bytes)" --rpc-url $SEPOLIA_RPC_URL)
PUBLIC_KEY=${PUBLIC_KEY#0x}

cd ./encrypter && go build && cd ../test-simple-auction-solidity
Encrypted=$(../encrypter/encrypter "$FAIRYRING_ID" "$PUBLIC_KEY" "$bid_value")
BID_DATA=$(python3 convert_to_array.py "$Encrypted")

Now, submit the BID_DATA as an encrypted bid to the auction using submitEncryptedBid function.

Once the auction deadline is reached, request and get the decryption key from Gateway contract:

  cast send --rpc-url $SEPOLIA_RPC_URL --private-key $AUCTIONEER_PRIVATE_KEY $GATEWAY_ADDRESS "requestGeneralDecryptionKey(uint256)" "$GATEWAY_ID"

  DECRYPTION_KEY=$(cast call "$GATEWAY_ADDRESS" "generalDecryptionKeys(address,uint256)(bytes)" $AUCTIONEER_ADDR $GATEWAY_ID --rpc-url "$SEPOLIA_RPC_URL")
  while [[ "$DECRYPTION_KEY" == 0x ]]; do
    echo "Decryption key not found, waiting..."
    sleep 2
    DECRYPTION_KEY=$(cast call "$GATEWAY_ADDRESS" "generalDecryptionKeys(address,uint256)(bytes)" $AUCTIONEER_ADDR $GATEWAY_ID --rpc-url "$SEPOLIA_RPC_URL")
  done

Having the DECRYPTION_KEY, repeately call revealBids to decrypt bids in batches of three and calculate the winner bid once all bids as decrypted.

Test Script

All above steps from cloning the repositories up to creating and bidding and finallizing auctions can be performed and tested with our end-to-end script (FullDeployScript.sh) Make sure to set required variables in .env.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages