Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
3081dfc
Update docs/README.md with status updates
johnwhitton May 25, 2022
fb40064
update docs/README.md
johnwhitton May 25, 2022
8f56192
Update docs/README.md with additional deployment and testing notes an…
johnwhitton May 25, 2022
99e7707
Update docs/README.md with Developer Setup and Testing guide
johnwhitton May 25, 2022
1c923c1
Update docs/README.md with Developer Setup and Testing guide
johnwhitton May 25, 2022
ff304dd
Merge upstream master
johnwhitton Jun 8, 2022
1dc5a45
Pull latest main, remove hardhat.config.js, update DEVELOPER.md with …
johnwhitton Jun 10, 2022
e041a19
Update configuration to reflect each network and environment specific…
johnwhitton Jun 10, 2022
0417d76
Generation of DAG for block 0 Hardhat, and addition of smart contract…
johnwhitton Jun 11, 2022
715eed9
Add results from relaying blocks locally
johnwhitton Jun 11, 2022
f0d37e7
Merge remote-tracking branch 'upstream/main' into refactorV2
johnwhitton Jun 12, 2022
2b5c82e
Redeploy on local networks and update deploy-localnet to remove deplo…
johnwhitton Jun 13, 2022
f79f1bc
Add additional notes on ethash local wrong error
johnwhitton Jun 13, 2022
81d4321
Add testnet deployments
johnwhitton Jun 13, 2022
d585064
Add in build for localget and deployment config for localgeth and devnet
johnwhitton Jun 14, 2022
75b2ecd
Test refresh from initData and update docs
johnwhitton Jun 15, 2022
836c213
Fix problem with RLPReader erroring on LightClient Deploys and add in…
johnwhitton Jun 15, 2022
af63011
Modify localgeth to use londonfork and update data and dag information
johnwhitton Jun 17, 2022
07ce334
Update DEVELOPER.md with links to new initData for localgeth london fork
johnwhitton Jun 17, 2022
14b43ce
Update DEVELOPER cheatsheat with localgeth and init-chain
johnwhitton Jun 17, 2022
6b561a4
Update DEVELOPER cheatsheat with localgeth and init-chain
johnwhitton Jun 17, 2022
f4392e5
Working Local Relayer
johnwhitton Jun 17, 2022
57006c1
Update the Localgeth block number for deploy
johnwhitton Jun 17, 2022
9550cfe
Update funding for local accounts, fix faucetToken, update private ke…
johnwhitton Jun 18, 2022
51baf22
Fix minting in FaucetTokens, Add setting of LightClients for TokenLoc…
johnwhitton Jun 19, 2022
af06831
Consolidate abi definitions to consistently use the build directory
johnwhitton Jun 19, 2022
26e2e02
Add in config and Logger.debug
johnwhitton Jun 20, 2022
a5f0cc5
Consolidate dag files under data directory move readable abi's from d…
johnwhitton Jun 20, 2022
bdb6997
Include lightclient dependency for TokenLocker on Deploy
johnwhitton Jun 21, 2022
f62b366
Update tasks.md
johnwhitton Jun 21, 2022
2baf88b
Update deployment to use Proxies remove deployment scripts from lib m…
johnwhitton Jun 21, 2022
0730c6c
Move Developer guide to docs/README.md replacing the outdated README.md
johnwhitton Jun 21, 2022
ea1db67
Get tests running - additional test coverage still needed
johnwhitton Jun 21, 2022
d8a42ed
Update deployment parameterization task
johnwhitton Jun 21, 2022
a00d580
Improve Bridge functionality and refactor to use ethers instead of we…
johnwhitton Jun 24, 2022
2b8901a
Add in test for Harmony TokenLocker validateAndExecuteProof to enviro…
johnwhitton Jun 24, 2022
88844c6
Begin rework to support harmony validateAndExecuteProof, input fields…
johnwhitton Jun 26, 2022
6d1d659
Include overview in Tasks.md
johnwhitton Jun 27, 2022
fc52f30
Add in updates on Sepolia deployment and placeholder for tasks by fun…
johnwhitton Jun 27, 2022
e557373
Add sepolia testnet, update initData and update README.md to reflect …
johnwhitton Jun 27, 2022
746f5a1
add in some Functionality Tasks
johnwhitton Jun 27, 2022
5d44de0
Update tasks for improving relayer performance
johnwhitton Jun 27, 2022
929956a
Review Ethereum 2.0 and multichain approach
johnwhitton Oct 11, 2022
ef18a7a
Update Horizon Design Docs to include ETH 2.0 support with Rainbow Br…
johnwhitton Oct 13, 2022
ab567af
PlaceHolder for ETH 2.0 Light Client Support
johnwhitton Oct 14, 2022
efa8759
Add in Review of Ethereum 2.0 Light Client Specification
johnwhitton Oct 15, 2022
97dca21
Add in Review of Ethereum 2.0 Light Client Specification
johnwhitton Oct 15, 2022
fc0eb6d
Add in Relay Overview for NEAR Rainbow Bridge
johnwhitton Oct 18, 2022
ec32633
Update Relay Overview for Near Bridge to include ETH2 Client overview…
johnwhitton Oct 18, 2022
a2fc34d
Update Relay Overview for Near Bridge to include Cryptographic Primit…
johnwhitton Oct 18, 2022
099e627
Add in NEAR Rainbow Bridge Token Transfer Flow
johnwhitton Oct 19, 2022
d657a2b
Add in NEAR Rainbow Bridge Token Transfer Components and copy Solidit…
johnwhitton Oct 19, 2022
42cc87c
Add in NEAR Rainbow Bridge NEAR to Ethereum Flow
johnwhitton Oct 23, 2022
b8a2304
Minor updates to NEAR Rainbow Bridge NEAR to Ethereum Flow
johnwhitton Oct 23, 2022
fb8c916
Minor updates to NEAR Rainbow Bridge NEAR to Ethereum Flow
johnwhitton Oct 23, 2022
8e222c7
Add propogation and watchdog logic to NEAR Rainbow Bridge NEAR to Et…
johnwhitton Oct 25, 2022
18f71a7
Add propagation and watchdog logic to NEAR Rainbow Bridge NEAR to Et…
johnwhitton Oct 25, 2022
6198b1d
Add eth_rpc_client to ETH 2_0 doc
johnwhitton Oct 26, 2022
1b7c439
Add eth2-contract-init to ETH 2_0 doc
johnwhitton Oct 26, 2022
bd9c048
Add in DESIGNV2.md
johnwhitton Oct 26, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
ETHERSCAN_API_KEY=ABC123ABC123ABC123ABC123ABC123ABC1
ROPSTEN_URL=https://eth-ropsten.alchemyapi.io/v2/<YOUR ALCHEMY KEY>
PRIVATE_KEY=0xabc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc1
LOCALNET_PRIVATE_KEY=1f84c95ac16e6a50f08d44c7bde7aff8742212fda6e4321fde48bf83bef266dc
LOCALGETH_PRIVATE_KEY=ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
HARDHAT_PRIVATE_KEY=ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
HARDHAT_URL=http://localhost:8545
LOCALNET_URL=http://localhost:9500
DEVNET_URL=https://api.s0.ps.hmny.io/
TESTNET_URL=https://api.s0.b.hmny.io
MAINNET_URL=https://api.harmony.one
LOCALGETH_URL=http://localhost:8645
ROPSTEN_URL =https://ropsten.infura.io/v3/32c32c32c32c32c32c32c32c32c32c32
SEPOLIA_URL=https://rpc.sepolia.dev
ETHEREUM_URL=https://mainnet.infura.io/v3/32c32c32c32c32c32c32c32c32c32c32
ETHERSCAN_API_KEY=R8N14TD8CJ5NJ1BAGBJ23E718K9CWHUHEM
PRIVATE_KEY=1f84c95ac16e6a50f08d44c7bde7aff8742212fda6e4321fde48bf83bef266dc
HMY_URL=http://localhost:9500
ETH_URL=http://localhost:8645
GAS_LIMIT=6000000
GAS_PRICE=20000000000
ERC20=0x876dEfe099Ff0C2E13b0c7B4b9101859e52c07c6
HMY_TOKEN_LOCKER=0x017f8C7d1Cb04dE974B8aC1a6B8d3d74bC74E7E1
ETH_TOKEN_LOCKER=0x017f8C7d1Cb04dE974B8aC1a6B8d3d74bC74E7E1
VERBOSE=true
HLC_INITIAL_BLOCK=1
RELAYERS=["0x0B585F8DaEfBC68a311FbD4cB20d9174aD174016"]
THRESHOLD=1
ELC_INIITAL_BLOCK=55
18 changes: 14 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@
*/.env
.env
*/node_modules
.nvmrc
/old_contracts
/back
build
cache

# Ignore dag and data ffiles
data
*/.dag
*/dag*
*/*/.dag/*
*/*/dag/
.openzeppelin
#.openzeppelin

node_modules
build/contracts
yarn-error.log
coverage
coverage.json
Expand All @@ -32,10 +35,17 @@ dist/**/*
# Ignore solidity documentation until code has been documented
docs/solidity

data/abi
# Ignore solidity files used for analysis
docs/slither

# Ignore generated easy to read abi definitions
docs/abi

# Ignore generated typescript definitions
typechain

# webstorm
.idea
.idea

# Local Network data
localgeth/data
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ Horizon - a trustless harmony to ethereum bridge
<img src="docs/assets/hmy2eth.png" alt="drawing" width="600"/>

## Additional Reading
1. [Developer Guide ](./docs/DEVELOPER.md)
1. [Developer Guide ](./docs/README.md)
2. [Solidity Approach](./docs/SOLIDITY.md)
3. [Solidity generated documentation](./docs/solidity/)
32 changes: 32 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require('dotenv').config()

module.exports = {
localnetPrivateKey: process.env.LOCALNET_PRIVATE_KEY,
localgethPrivateKey: process.env.LOCALGETH_PRIVATE_KEY,
hardhatPrivateKey: process.env.HARDHAT_PRIVATE_KEY,
hardhatURL: process.env.HARDHAT_URL,
localnetURL: process.env.LOCALNET_URL,
devnetURL: process.env.DEVNET_URL,
testnetURL: process.env.TESTNET_URL,
mainnetURL: process.env.MAINNET_URL,
localgethURL: process.env.LOCALGETH_URL,
ropstenURL: process.env.ROPSTEN_URL,
sepoliaURL: process.env.SEPOLIA_URL,
ethereumURL: process.env.ETHEREUM_URL,
etherscanAPI: process.env.ETHERSCAN_API_KEY,
privateKey: process.env.PRIVATE_KEY,
hmyURL: process.env.HMY_URL,
ethURL: process.env.ETH_URL,
gasLimit: process.env.GAS_LIMIT,
gasPrice: process.env.GAS_PRICE,
erc20: process.env.ERC20,
hmyTokenLocker: process.env.HMY_TOKEN_LOCKER,
ethTokenLocker: process.env.ETH_TOKEN_LOCKER,
verbose: process.env.VERBOSE === 'true' || process.env.VERBOSE === '1',
reportGas: false,
hlcInitialBlock: process.env.HLC_INITIAL_BLOCK,
// use JSON.parse to parse the array of relayers
relayers: JSON.parse(process.env.RELAYERS),
threshold: process.env.THRESHOLD,
elcInitialBlock: process.env.ELC_INIITAL_BLOCK
}
52 changes: 42 additions & 10 deletions contracts/FaucetToken.sol
Original file line number Diff line number Diff line change
@@ -1,23 +1,55 @@
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.0;
pragma experimental ABIEncoderV2;
pragma solidity ^0.8.4;

import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20BurnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

contract FaucetToken is
Initializable,
ERC20Upgradeable,
ERC20BurnableUpgradeable,
PausableUpgradeable,
OwnableUpgradeable
{
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}

contract FaucetToken is ERC20Upgradeable {
function initialize(
string memory name,
string memory symbol
// uint8 decimals
) external initializer {
string memory symbol,
uint256 supply
) public initializer {
__ERC20_init(name, symbol);
// _setupDecimals(decimals);
__ERC20Burnable_init();
__Pausable_init();
__Ownable_init();
mint(owner(), supply);
}

function pause() public onlyOwner {
_pause();
}

function mint() public returns (bool) {
function unpause() public onlyOwner {
_unpause();
}

function mint(address to, uint256 amount) public onlyOwner {
uint256 UNIT = 10**uint256(decimals());
_mint(msg.sender, 10000 * UNIT);
return true;
_mint(to, amount * UNIT);
}

function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal override whenNotPaused {
super._beforeTokenTransfer(from, to, amount);
}
}
28 changes: 10 additions & 18 deletions contracts/TokenRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,18 @@ contract TokenRegistry {
return (TxTokens.length, RxTokens.length);
}

function issueTokenMapReq(ERC20Upgradeable thisSideToken)
external
{
function issueTokenMapReq(ERC20Upgradeable thisSideToken) external {
require(
TxMapped[address(thisSideToken)] == address(0),
"token is already mapped"
);
ERC20Upgradeable tokenDetail = thisSideToken;
emit TokenMapReq(
address(thisSideToken),
tokenDetail.decimals(),
tokenDetail.name(),
tokenDetail.symbol()
);
// ERC20Upgradeable tokenDetail = thisSideToken;
// emit TokenMapReq(
// address(thisSideToken),
// tokenDetail.decimals(),
// tokenDetail.name(),
// tokenDetail.symbol()
// );
}

function onTokenMapReqEvent(bytes32[] memory topics, bytes memory data)
Expand All @@ -77,20 +75,14 @@ contract TokenRegistry {
);
bytes32 salt = bytes32(uint256(uint160(tokenReq)));
BridgedToken mintAddress = new BridgedToken{salt: salt}();
mintAddress.initialize(
name,
symbol,
decimals
);
mintAddress.initialize(name, symbol, decimals);
RxMappedInv[address(mintAddress)] = tokenReq;
RxMapped[tokenReq] = mintAddress;
RxTokens.push(mintAddress);
emit TokenMapAck(tokenReq, address(mintAddress));
}

function onTokenMapAckEvent(bytes32[] memory topics)
internal
{
function onTokenMapAckEvent(bytes32[] memory topics) internal {
address tokenReq = address(uint160(uint256(topics[1])));
address tokenAck = address(uint160(uint256(topics[2])));
require(
Expand Down
33 changes: 21 additions & 12 deletions contracts/ethash/MerkelRoot.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,26 @@ pragma solidity ^0.8.0;
pragma experimental ABIEncoderV2;

contract MerkelRoots {
uint64 constant epochStart = 411;
uint64 constant epochEnd = 411;
bytes constant ROOTS = "\xf8\x7d\x60\x5d\xd4\xbd\xaf\xc3\x9b\x13\xb4\x5b\x6a\xbf\x6b\x92\x11\x96\xb0\xf3\xb5\xd7\xc5\x1b\x31\x82\x06\x64\x10\x4a\x69\x7d";
// Ropsten DAG and epoch information
// uint64 constant epochStart = 411;
// uint64 constant epochEnd = 411;
// bytes constant ROOTS = "\xf8\x7d\x60\x5d\xd4\xbd\xaf\xc3\x9b\x13\xb4\x5b\x6a\xbf\x6b\x92\x11\x96\xb0\xf3\xb5\xd7\xc5\x1b\x31\x82\x06\x64\x10\x4a\x69\x7d";

function getRootHash(uint64 epoch) internal pure returns(bytes32 hash) {
bytes memory roots = ROOTS;
require(epoch >= epochStart && epoch <= epochEnd, "epoch out of range!");
uint256 index = epoch - epochStart + 1; // skip length
assembly{
hash := mload(add(roots, mul(index, 0x20)))
}
}
}
// LocalGeth DAG and epoch information
uint64 constant epochStart = 0;
uint64 constant epochEnd = 0;
bytes constant ROOTS =
"\x2c\x2f\xcc\x07\x35\xc1\x71\xe5\x7f\x5f\xa4\x9f\x0d\x3b\x30\xf7\x77\xfa\x2e\xea\x35\x31\xf4\x18\x79\x7a\xf1\x4b\x1a\x98\xd9\xb8";

function getRootHash(uint64 epoch) internal pure returns (bytes32 hash) {
bytes memory roots = ROOTS;
require(
epoch >= epochStart && epoch <= epochEnd,
"epoch out of range!"
);
uint256 index = epoch - epochStart + 1; // skip length
assembly {
hash := mload(add(roots, mul(index, 0x20)))
}
}
}
4 changes: 3 additions & 1 deletion contracts/ethash/ethash.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ contract Ethash is MerkelRoots {
// the full 32-bit input, in contrast with the FNV-1 spec which multiplies the
// prime with one byte (octet) in turn.
function fnv(uint32 a, uint32 b) internal pure returns (uint32) {
return (a * 0x01000193) ^ b;
unchecked {
return (a * 0x01000193) ^ b;
}
}

// fnvHash mixes in data into mix using the ethash fnv method.
Expand Down
37 changes: 25 additions & 12 deletions contracts/lib/RLPReader.sol
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,15 @@ library RLPReader {
return result;
}

function toRlpBytesHash(RLPItem memory item) internal pure returns (bytes32 _hash) {
function toRlpBytesHash(RLPItem memory item)
internal
pure
returns (bytes32 _hash)
{
require(item.len > 0);
uint256 len = item.len;
uint256 ptr = item.memPtr;
assembly{
assembly {
_hash := keccak256(ptr, len)
}
}
Expand Down Expand Up @@ -333,11 +337,16 @@ library RLPReader {
}

// left over bytes. Mask is used to remove unwanted bytes from the word
uint256 mask = 256**(WORD_SIZE - len) - 1;
assembly {
let srcpart := and(mload(src), not(mask)) // zero out src
let destpart := and(mload(dest), mask) // retrieve the bytes
mstore(dest, or(destpart, srcpart))
if (len > 0) {
if (len >= WORD_SIZE) {
len = WORD_SIZE - 1;
}
uint256 mask = 256**(WORD_SIZE - len) - 1;
assembly {
let srcpart := and(mload(src), not(mask)) // zero out src
let destpart := and(mload(dest), mask) // retrieve the bytes
mstore(dest, or(destpart, srcpart))
}
}
}

Expand All @@ -360,14 +369,18 @@ library RLPReader {
/*
* @param get the RLP item by index. save gas.
*/
function safeGetItemByIndex(RLPItem memory item, uint idx) internal pure returns (RLPItem memory) {
function safeGetItemByIndex(RLPItem memory item, uint256 idx)
internal
pure
returns (RLPItem memory)
{
require(isList(item), "RLPDecoder iterator is not a list");

uint endPtr = item.memPtr + item.len;
uint256 endPtr = item.memPtr + item.len;

uint memPtr = item.memPtr + _payloadOffset(item.memPtr);
uint dataLen;
for (uint i = 0; i < idx; i++) {
uint256 memPtr = item.memPtr + _payloadOffset(item.memPtr);
uint256 dataLen;
for (uint256 i = 0; i < idx; i++) {
dataLen = _itemLength(memPtr);
memPtr = memPtr + dataLen;
}
Expand Down
47 changes: 47 additions & 0 deletions deploy/000_fund_deployer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { HardhatRuntimeEnvironment } from 'hardhat/types'
import { DeployFunction } from 'hardhat-deploy/types'
import { ethers } from 'hardhat'

const config = require('../config.js')

// Fund deployer acounts for local networks localgeth and localnet
const deployFunction: DeployFunction = async function (
hre: HardhatRuntimeEnvironment
) {
const { getNamedAccounts, getChainId } = hre
const { deployer } = await getNamedAccounts()
const chainId = await getChainId()

console.log(`chainId: ${chainId}`)
let funder
switch (chainId) {
// localgeth
case '8788':{
funder = new ethers.Wallet(config.localgethPrivateKey, ethers.provider)
break
}
// localnet
case '1666700000': {
funder = new ethers.Wallet(config.localnetPrivateKey, ethers.provider)
break
}
// hardhatNode
case '31337': {
funder = new ethers.Wallet(config.hardhatPrivateKey, ethers.provider)
break
}
}
if (funder !== undefined) {
const tx = await funder.sendTransaction({
to: deployer,
value: ethers.utils.parseEther('100')
})
await ethers.provider.waitForTransaction(tx.hash)
}
const balance = await ethers.provider.getBalance(deployer)
console.log(`deployer: ${deployer}, balance: ${ethers.utils.formatEther(balance)}`)
}

deployFunction.dependencies = []
deployFunction.tags = ['Funding', 'Ethereum', 'Harmony']
export default deployFunction
Loading