Skip to content

Commit

Permalink
Merge branch 'bridge-design' of github.com-taiko:taikochain/taiko-mon…
Browse files Browse the repository at this point in the history
…o into bridge-design
  • Loading branch information
shadab-taiko committed Dec 2, 2022
2 parents 48f77c9 + 296b533 commit fe29c86
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 39 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@
"contributions": [
"doc"
]
},
{
"login": "omahs",
"name": "omahs",
"avatar_url": "https://avatars.githubusercontent.com/u/73983677?v=4",
"profile": "https://github.com/omahs",
"contributions": [
"doc"
]
}
],
"contributorsPerLine": 7,
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ If you are opening a new issue, try to be descriptive as possible. Also please c

### Source code comments

Follow the [NatSpec format](https://docs.soliditylang.org/en/v0.8.16/natspec-format.html) for documentating smart contract source code. Please adhere to a few additional standards:
Follow the [NatSpec format](https://docs.soliditylang.org/en/v0.8.16/natspec-format.html) for documenting smart contract source code. Please adhere to a few additional standards:

- Choose `/** */` over `///` for multi-line NatSpec comments, to save column space
- Omit the usage of `@notice`, this will be automatically picked up so it will save column space and improve readability
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center"><a href="https://github.com/shadab-taiko"><img src="https://avatars.githubusercontent.com/u/108871478?v=4?s=100" width="100px;" alt="shadab-taiko"/><br /><sub><b>shadab-taiko</b></sub></a><br /><a href="https://github.com/taikoxyz/taiko-mono/commits?author=shadab-taiko" title="Documentation">📖</a> <a href="https://github.com/taikoxyz/taiko-mono/commits?author=shadab-taiko" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/1xDeFi"><img src="https://avatars.githubusercontent.com/u/90858998?v=4?s=100" width="100px;" alt="1xDeFi"/><br /><sub><b>1xDeFi</b></sub></a><br /><a href="https://github.com/taikoxyz/taiko-mono/commits?author=1xDeFi" title="Documentation">📖</a></td>
<td align="center"><a href="https://github.com/odesium"><img src="https://avatars.githubusercontent.com/u/56487762?v=4?s=100" width="100px;" alt="Ben"/><br /><sub><b>Ben</b></sub></a><br /><a href="https://github.com/taikoxyz/taiko-mono/commits?author=odesium" title="Documentation">📖</a></td>
<td align="center"><a href="https://github.com/omahs"><img src="https://avatars.githubusercontent.com/u/73983677?v=4?s=100" width="100px;" alt="omahs"/><br /><sub><b>omahs</b></sub></a><br /><a href="https://github.com/taikoxyz/taiko-mono/commits?author=omahs" title="Documentation">📖</a></td>
</tr>
</tbody>
</table>
Expand Down
37 changes: 17 additions & 20 deletions packages/protocol/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import "./tasks/deploy_L1"
import "@nomiclabs/hardhat-etherscan"
import "@nomiclabs/hardhat-waffle"
import "@openzeppelin/hardhat-upgrades"
import "@typechain/hardhat"
import "hardhat-abi-exporter"
import "hardhat-gas-reporter"
import "hardhat-preprocessor"
import { HardhatUserConfig } from "hardhat/config"
import "solidity-coverage"
import "solidity-docgen"
import { HardhatUserConfig } from "hardhat/config"
import "./tasks/deploy_L1"

const hardhatMnemonic =
"test test test test test test test test test test test taik"
Expand Down Expand Up @@ -91,24 +91,21 @@ const config: HardhatUserConfig = {
preprocess: {
eachLine: () => ({
transform: (line) => {
if (
process.env.CHAIN_ID &&
line.includes("uint256 public constant TAIKO_CHAIN_ID")
) {
return `${line.slice(0, line.indexOf(" ="))} = ${
process.env.CHAIN_ID
};`
}

if (
process.env.COMMIT_DELAY_CONFIRMATIONS &&
line.includes(
"uint256 public constant TAIKO_COMMIT_DELAY_CONFIRMATIONS"
)
) {
return `${line.slice(0, line.indexOf(" ="))} = ${
process.env.COMMIT_DELAY_CONFIRMATIONS
};`
for (const constantName of [
"TAIKO_CHAIN_ID",
"K_COMMIT_DELAY_CONFIRMATIONS",
"TAIKO_BLOCK_MAX_TXS",
"TAIKO_TXLIST_MAX_BYTES",
"TAIKO_BLOCK_MAX_GAS_LIMIT",
]) {
if (
process.env[constantName] &&
line.includes(`uint256 public constant ${constantName}`)
) {
return `${line.slice(0, line.indexOf(" ="))} = ${
process.env[constantName]
};`
}
}

return line
Expand Down
6 changes: 6 additions & 0 deletions packages/protocol/test/genesis/generate_genesis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ action("Generate Genesis", function () {
const expectCode: string = alloc[address].code

expect(code.toLowerCase()).to.be.equal(expectCode.toLowerCase())

if (testConfig.contractAddresses[alloc[address].contractName]) {
expect(address).to.be.equal(
testConfig.contractAddresses[alloc[address].contractName]
)
}
}
})

Expand Down
42 changes: 41 additions & 1 deletion packages/protocol/test/genesis/test_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
{
"0xdD2FD4581271e230360230F9337D5c0430Bf44C0": 1024
},
{
"0xbDA5747bFD65F08deb54cb465eB87D40e51B197E": 1024
},
{
"0x2546BcD3c84621e976D8185a91A922aE77ECEc30": 1024
},
Expand All @@ -40,7 +43,44 @@
},
{
"0xBcd4042DE499D14e55001CcbB24a551F3b954096": 1024
},
{
"0xa0Ee7A142d267C1f36714E4a8F75612F20a79720": 1024
},
{
"0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f": 1024
},
{
"0x14dC79964da2C08b23698B3D3cc7Ca32193d9955": 1024
},
{
"0x976EA74026E726554dB657fA54763abd0C3a0aa9": 1024
},
{
"0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc": 1024
},
{
"0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65": 1024
},
{
"0x90F79bf6EB2c4f870365E785982E1f101E93b906": 1024
},
{
"0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC": 1024
},
{
"0x70997970C51812dc3A010C7d01b50e0d17dc79C8": 1024
},
{
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266": 1024
}
],
"contractAddresses": {
"V1TaikoL2": "0x0000777700000000000000000000000000000001",
"TokenVault": "0x0000777700000000000000000000000000000002",
"EtherVault": "0x0000777700000000000000000000000000000003",
"Bridge": "0x0000777700000000000000000000000000000004",
"TestERC20": "0x0000777700000000000000000000000000000005"
},
"predeployERC20": true
}
}
22 changes: 15 additions & 7 deletions packages/protocol/utils/generate_genesis/erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,21 @@ export async function deployERC20(
"./test/thirdparty/TestERC20.sol/TestERC20.json"
))

const address = ethers.utils.getCreate2Address(
contractOwner,
ethers.utils.keccak256(
ethers.utils.toUtf8Bytes(`${chainId}${artifact.contractName}`)
),
ethers.utils.keccak256(ethers.utils.toUtf8Bytes(artifact.bytecode))
)
let address: string
if (
config.contractAddresses &&
ethers.utils.isAddress(config.contractAddresses[artifact.contractName])
) {
address = config.contractAddresses[artifact.contractName]
} else {
address = ethers.utils.getCreate2Address(
contractOwner,
ethers.utils.keccak256(
ethers.utils.toUtf8Bytes(`${chainId}${artifact.contractName}`)
),
ethers.utils.keccak256(ethers.utils.toUtf8Bytes(artifact.bytecode))
)
}

const variables = {
_name: TOKEN_NAME,
Expand Down
1 change: 1 addition & 0 deletions packages/protocol/utils/generate_genesis/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface Config {
[key: string]: number
}>
predeployERC20: boolean
contractAddresses: Object
}

export interface Result {
Expand Down
27 changes: 18 additions & 9 deletions packages/protocol/utils/generate_genesis/v1TaikoL2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export async function deployV1TaikoL2(

const contractConfigs: any = await generateContractConfigs(
contractOwner,
chainId
chainId,
config.contractAddresses
)

const storageLayouts: any = {}
Expand Down Expand Up @@ -88,7 +89,8 @@ export async function deployV1TaikoL2(
// and initialized variables.
async function generateContractConfigs(
contractOwner: string,
chainId: number
chainId: number,
hardCodedAddresses: any
): Promise<any> {
const contractArtifacts: any = {
// Libraries
Expand Down Expand Up @@ -165,13 +167,20 @@ async function generateContractConfigs(
bytecode = linkContractLibs(contractArtifacts.Bridge, addressMap)
}

addressMap[contractName] = ethers.utils.getCreate2Address(
contractOwner,
ethers.utils.keccak256(
ethers.utils.toUtf8Bytes(`${chainId}${contractName}`)
),
ethers.utils.keccak256(ethers.utils.toUtf8Bytes(bytecode))
)
if (
hardCodedAddresses &&
ethers.utils.isAddress(hardCodedAddresses[contractName])
) {
addressMap[contractName] = hardCodedAddresses[contractName]
} else {
addressMap[contractName] = ethers.utils.getCreate2Address(
contractOwner,
ethers.utils.keccak256(
ethers.utils.toUtf8Bytes(`${chainId}${contractName}`)
),
ethers.utils.keccak256(ethers.utils.toUtf8Bytes(bytecode))
)
}
}

console.log("pre-computed addresses:")
Expand Down
2 changes: 1 addition & 1 deletion packages/whitepaper/main.tex
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ \subsubsection{Invalid Blocks} \label{sec:proving-invalid}

It's important to note that these throw-away blocks are never a part of the Taiko chain. The only purpose of the block is to be able reuse the EVM proving subsystem so that we can create proofs for blocks with unexpected transaction data.

\subsection{On-chain Finalization of Blocks}\label{sec:verifying}
\subsection{On-chain Verification of Blocks}\label{sec:verifying}

Assuming the $j$-th block is the last verified valid block. The $i$-th block ($i > j$) can be verified if 1) the $(i-1)$-th block has been verified, and 2) the $i$-th block has a Fork Choice $E$ whose parent block hash $E(H_p)$ equals the $j$-th block's hash.

Expand Down

0 comments on commit fe29c86

Please sign in to comment.