-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from bob-collective/feat/proof-checking
feat: proof checking and relay init
- Loading branch information
Showing
17 changed files
with
204 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* eslint @typescript-eslint/no-var-requires: "off" */ | ||
|
||
import { DefaultElectrsClient } from "../src/electrs"; | ||
const yargs = require("yargs/yargs"); | ||
const { hideBin } = require("yargs/helpers"); | ||
const { exec } = require('child_process'); | ||
|
||
const args = yargs(hideBin(process.argv)) | ||
.option("init-height", { | ||
description: "Height of the bitcoin chain to initialize the relay at", | ||
type: "number", | ||
demandOption: true, | ||
}) | ||
.option("private-key", { | ||
description: "Private key to submit with", | ||
type: "string", | ||
demandOption: true, | ||
}).argv; | ||
main().catch((err) => { | ||
console.log("Error thrown by script:"); | ||
console.log(err); | ||
}); | ||
|
||
|
||
async function main(): Promise<void> { | ||
const electrs = new DefaultElectrsClient("testnet"); | ||
// args["parachain-endpoint"] | ||
|
||
const initHeight = args["init-height"]; | ||
const privateKey = args["private-key"]; | ||
if ((initHeight % 2016) != 0) { | ||
throw new Error("Invalid genesis height: must be multiple of 2016"); | ||
} | ||
|
||
const genesis = await electrs.getBlockHeaderAt(initHeight); | ||
|
||
const beforeRetarget = await electrs.getBlockHeaderAt(initHeight + 2015); | ||
const afterRetarget = await electrs.getBlockHeaderAt(initHeight + 2016); | ||
|
||
console.log(`Genesis: ${genesis}`); | ||
console.log(`beforeRetarget: ${beforeRetarget}`); | ||
console.log(`afterRetarget: ${afterRetarget}`); | ||
|
||
|
||
exec(`GENESIS_HEIGHT=${initHeight} GENESIS_HEADER=${genesis} RETARGET_HEADERS=${beforeRetarget}${afterRetarget} PRIVATE_KEY=${privateKey} forge script script/Bridge.s.sol:BridgeScript --rpc-url 'https://l2-fluffy-bob-7mjgi9pmtg.t.conduit.xyz' --chain 901 --verify --verifier blockscout --verifier-url 'https://explorerl2-fluffy-bob-7mjgi9pmtg.t.conduit.xyz/api?' --broadcast`, | ||
(err: any, stdout: any, stderr: any) => { | ||
if (err) { | ||
throw new Error(`Failed to run command: ${err}`); | ||
} | ||
|
||
// the *entire* stdout and stderr (buffered) | ||
console.log(`stdout: ${stdout}`); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
// Forked from https://github.com/keep-network/tbtc-v2 | ||
|
||
pragma solidity 0.8.17; | ||
|
||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
|
||
import {BytesLib} from "@bob-collective/bitcoin-spv/BytesLib.sol"; | ||
import {BTCUtils} from "@bob-collective/bitcoin-spv/BTCUtils.sol"; | ||
import {ValidateSPV} from "@bob-collective/bitcoin-spv/ValidateSPV.sol"; | ||
|
||
import "../bridge/IRelay.sol"; | ||
|
||
/// @dev DEV-only! | ||
contract DummyRelay is IRelay { | ||
function getCurrentEpochDifficulty() external view returns (uint256) { | ||
return 0; | ||
} | ||
|
||
function getPrevEpochDifficulty() external view returns (uint256) { | ||
return 0; | ||
} | ||
|
||
function difficultyCheckEnabled() external view returns (bool) { | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.