Skip to content

Commit

Permalink
feat: contract code validation (#730)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael1011 authored Nov 9, 2024
1 parent 3eff8d3 commit f62ef91
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
14 changes: 14 additions & 0 deletions src/context/Web3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,22 @@ const Web3SignerProvider = (props: {

const useWeb3Signer = () => useContext(Web3SignerContext);

const etherSwapCodeHash = () => {
switch (config.network) {
case "mainnet":
return "0x4d6894da95269c76528b81c6d25425a2f6bba70156cfaf7725064f919647d955";

case "testnet":
return "0xd9a282305f30590b3df70c3c1f9338b042a97dff12736794e9de2cdabf8542c1";

default:
return undefined;
}
};

export {
useWeb3Signer,
etherSwapCodeHash,
Web3SignerProvider,
EtherSwapAbi,
customDerivationPathRdns,
Expand Down
20 changes: 10 additions & 10 deletions src/utils/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import {
} from "boltz-core";
import { default as BufferBrowser } from "buffer";
import { ECPairInterface } from "ecpair";
import { BaseContract } from "ethers";
import { BaseContract, ethers } from "ethers";
import log from "loglevel";

import { LBTC, RBTC } from "../consts/Assets";
import { Denomination, Side, SwapType } from "../consts/Enums";
import { etherSwapCodeHash } from "../context/Web3";
import { ChainSwapDetails } from "./boltzClient";
import { decodeAddress } from "./compat";
import { formatAmountDenomination } from "./denomination";
Expand All @@ -28,15 +29,14 @@ import { createMusig, tweakMusig } from "./taproot/musig";

type ContractGetter = () => BaseContract;

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const validateContract = (getEtherSwap: ContractGetter) => {
/*
const code = await (await getEtherSwap()).getDeployedCode();
const codeMatches = code === EtherSwapBytecode.object;
*/
// TODO: actually verify the code match
// This check is currently disabled, because it mismatches on RSK, because it was compiled for a different EVM target
return true;
const validateContract = async (getEtherSwap: ContractGetter) => {
const codeHash = etherSwapCodeHash();
if (codeHash === undefined) {
return true;
}

const code = await getEtherSwap().getDeployedCode();
return codeHash === ethers.keccak256(code);
};

const validateAddress = async (
Expand Down

0 comments on commit f62ef91

Please sign in to comment.