Skip to content

Commit

Permalink
Merge pull request #19 from QEDK/bugfix
Browse files Browse the repository at this point in the history
Fix RLPReader overflow and add verification commands in deployment script
  • Loading branch information
jdkanani authored Oct 13, 2021
2 parents 4b07231 + 3ed8189 commit 09a7399
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
5 changes: 4 additions & 1 deletion contracts/lib/RLPReader.sol
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,15 @@ library RLPReader {
dest += WORD_SIZE;
}

if (len == 0) return;

// left over bytes. Mask is used to remove unwanted bytes from the word
uint 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))
}
}
}
}
38 changes: 16 additions & 22 deletions scripts/deploychild.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,46 @@ const config = require('../config/config.json')
const hre = require('hardhat')

async function main () {
let fxChild
let fxChild, erc20Token, erc721Token, erc1155Token

const network = await hre.ethers.provider.getNetwork()

if (network.chainId === 137) { // Polygon Mainnet
fxChild = config.mainnet.fxChild.address
erc20Token = config.mainnet.fxERC20.address
erc721Token = config.mainnet.fxERC721.address
erc1155Token = config.mainnet.fxERC1155.address
} else if (network.chainId === 80001) { // Mumbai Testnet
fxChild = config.testnet.fxChild.address
erc20Token = config.testnet.fxERC20.address
erc721Token = config.testnet.fxERC721.address
erc1155Token = config.testnet.fxERC1155.address
} else {
fxChild = process.env.FX_CHILD
erc20Token = process.env.FX_ERC20
erc721Token = process.env.FX_ERC721
erc1155Token = process.env.FX_ERC1155
}

const ERC20Token = await hre.ethers.getContractFactory('FxERC20')
const erc20Token = await ERC20Token.deploy()
console.log(erc20Token.deployTransaction)
await erc20Token.deployTransaction.wait()
console.log('FxERC20 deployed to:', erc20Token.address)

const ERC20 = await hre.ethers.getContractFactory('FxERC20ChildTunnel')
const erc20 = await ERC20.deploy(fxChild, erc20Token.address)
const erc20 = await ERC20.deploy(fxChild, erc20Token)
await erc20.deployTransaction.wait()
console.log('ERC20ChildTunnel deployed to:', erc20.address)

const ERC721Token = await hre.ethers.getContractFactory('FxERC721')
const erc721Token = await ERC721Token.deploy()
console.log(erc721Token.deployTransaction)
await erc721Token.deployTransaction.wait()
console.log('FxERC721 deployed to:', erc721Token.address)
console.log('npx hardhat verify --network mumbai', erc20.address, fxChild, erc20Token)

const ERC721 = await hre.ethers.getContractFactory('FxERC721ChildTunnel')
const erc721 = await ERC721.deploy(fxChild, erc721Token.address)
const erc721 = await ERC721.deploy(fxChild, erc721Token)
console.log(erc721.deployTransaction)
await erc721.deployTransaction.wait()
console.log('ERC721ChildTunnel deployed to:', erc721.address)

const ERC1155Token = await hre.ethers.getContractFactory('FxERC1155')
const erc1155Token = await ERC1155Token.deploy()
console.log(erc1155Token.deployTransaction)
await erc1155Token.deployTransaction.wait()
console.log('FxERC1155 deployed to:', erc1155Token.address)
console.log('npx hardhat verify --network mumbai', erc721.address, fxChild, erc721Token)

const ERC1155 = await hre.ethers.getContractFactory('FxERC1155ChildTunnel')
const erc1155 = await ERC1155.deploy(fxChild, erc1155Token.address)
const erc1155 = await ERC1155.deploy(fxChild, erc1155Token)
console.log(erc1155.deployTransaction)
await erc1155.deployTransaction.wait()
console.log('ERC1155ChildTunnel deployed to:', erc1155.address)
console.log('npx hardhat verify --network mumbai', erc1155.address, fxChild, erc1155Token)
}

main()
Expand Down
9 changes: 6 additions & 3 deletions scripts/deployroot.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ const config = require('../config/config.json')
const hre = require('hardhat')

// Use your own deployed child tunnel addresses here instead!
const fxERC20ChildTunnel = '0x918cc10cf2393bb9803f9d9D3219539a1e736dd9'
const fxERC721ChildTunnel = '0xdC335C19868d49aCa554AA64d5ae8524A093De5b'
const fxERC1155ChildTunnel = '0x46d40260e48A6164bbF24206D3AB9426a41D8664'
const fxERC20ChildTunnel = '0x587C9FF1c528C7aeE2804Bf5301Dc2ec057A75a8'
const fxERC721ChildTunnel = '0x96d26FCA4cB14e14CABc28eF8bc8Aba0E03702A8'
const fxERC1155ChildTunnel = '0x24a16Db524d342968A11b9E1aD75b6D5eD002db7'

async function main () {
let fxRoot, checkpointManager, fxERC20, fxERC721, fxERC1155
Expand Down Expand Up @@ -38,6 +38,7 @@ async function main () {
console.log(erc20.deployTransaction)
await erc20.deployTransaction.wait()
console.log('ERC20RootTunnel deployed to:', erc20.address)
console.log('npx hardhat verify --network goerli', erc20.address, checkpointManager, fxRoot, fxERC20)

const setERC20Child = await erc20.setFxChildTunnel(fxERC20ChildTunnel)
console.log(setERC20Child)
Expand All @@ -49,6 +50,7 @@ async function main () {
console.log(erc721.deployTransaction)
await erc721.deployTransaction.wait()
console.log('ERC721RootTunnel deployed to:', erc721.address)
console.log('npx hardhat verify --network goerli', erc721.address, checkpointManager, fxRoot, fxERC721)

const setERC721Child = await erc721.setFxChildTunnel(fxERC721ChildTunnel)
console.log(setERC721Child)
Expand All @@ -60,6 +62,7 @@ async function main () {
console.log(erc1155.deployTransaction)
await erc1155.deployTransaction.wait()
console.log('ERC1155RootTunnel deployed to:', erc1155.address)
console.log('npx hardhat verify --network goerli', erc1155.address, checkpointManager, fxRoot, fxERC1155)

const setERC1155Child = await erc1155.setFxChildTunnel(fxERC1155ChildTunnel)
console.log(setERC1155Child)
Expand Down

0 comments on commit 09a7399

Please sign in to comment.