Skip to content

Commit

Permalink
chore(protocol): rename V1TaikoL2 to TaikoL2 to better match TaikoL1 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dantaik committed Dec 8, 2022
1 parent 2808b56 commit 1f63367
Show file tree
Hide file tree
Showing 12 changed files with 220 additions and 227 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import "../libs/LibConstants.sol";
import "../libs/LibTxDecoder.sol";

/// @author dantaik <dan@taiko.xyz>
contract V1TaikoL2 is AddressResolver, ReentrancyGuard, IHeaderSync {
contract TaikoL2 is AddressResolver, ReentrancyGuard, IHeaderSync {
using LibTxDecoder for bytes;

/**********************
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## V1TaikoL2
## TaikoL2

### l2Hashes

Expand Down
10 changes: 5 additions & 5 deletions packages/protocol/tasks/deploy_L1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ task("deploy_L1")
.addParam("daoVault", "The DAO vault address")
.addParam("teamVault", "The team vault address")
.addOptionalParam(
"v1TaikoL2",
"The V1TaikoL2 address",
"taikoL2",
"The TaikoL2 address",
ethers.constants.AddressZero
)
.addOptionalParam(
Expand Down Expand Up @@ -49,15 +49,15 @@ export async function deployContracts(hre: any) {
const daoVault = hre.args.daoVault
const teamVault = hre.args.teamVault
const l2GenesisBlockHash = hre.args.l2GenesisBlockHash
const v1TaikoL2Address = hre.args.v1TaikoL2
const taikoL2Address = hre.args.taikoL2
const l2ChainId = hre.args.l2ChainId

log.debug(`network: ${network}`)
log.debug(`chainId: ${chainId}`)
log.debug(`deployer: ${deployer}`)
log.debug(`daoVault: ${daoVault}`)
log.debug(`l2GenesisBlockHash: ${l2GenesisBlockHash}`)
log.debug(`v1TaikoL2Address: ${v1TaikoL2Address}`)
log.debug(`taikoL2Address: ${taikoL2Address}`)
log.debug(`l2ChainId: ${l2ChainId}`)
log.debug(`confirmations: ${hre.args.confirmations}`)
log.debug()
Expand All @@ -76,7 +76,7 @@ export async function deployContracts(hre: any) {
// Used by V1Proving
await utils.waitTx(
hre,
await AddressManager.setAddress(`${l2ChainId}.taiko`, v1TaikoL2Address)
await AddressManager.setAddress(`${l2ChainId}.taiko`, taikoL2Address)
)

// TkoToken
Expand Down
Original file line number Diff line number Diff line change
@@ -1,53 +1,50 @@
import { expect } from "chai"
import { ethers } from "hardhat"

describe("V1TaikoL2", function () {
async function deployV1TaikoL2Fixture() {
describe("TaikoL2", function () {
async function deployTaikoL2Fixture() {
// Deploying addressManager Contract
const addressManager = await (
await ethers.getContractFactory("AddressManager")
).deploy()
await addressManager.init()

// Deploying V1TaikoL2 Contract linked with LibTxDecoder (throws error otherwise)
// Deploying TaikoL2 Contract linked with LibTxDecoder (throws error otherwise)
const libTxDecoder = await (
await ethers.getContractFactory("LibTxDecoder")
).deploy()

const v1TaikoL2Factory = await ethers.getContractFactory("V1TaikoL2", {
const taikoL2Factory = await ethers.getContractFactory("TaikoL2", {
libraries: {
LibTxDecoder: libTxDecoder.address,
},
})
const v1TaikoL2 = await v1TaikoL2Factory.deploy(addressManager.address)
const taikoL2 = await taikoL2Factory.deploy(addressManager.address)

return { v1TaikoL2 }
return { taikoL2 }
}

describe("anchor()", async function () {
it("should revert since ancestor hashes not written", async function () {
const { v1TaikoL2 } = await deployV1TaikoL2Fixture()
const { taikoL2 } = await deployTaikoL2Fixture()
await expect(
v1TaikoL2.anchor(
Math.ceil(Math.random() * 1024),
randomBytes32()
)
taikoL2.anchor(Math.ceil(Math.random() * 1024), randomBytes32())
).to.be.revertedWith("L2:publicInputHash")
})
})

describe("getLatestSyncedHeader()", async function () {
it("should be 0 because no headers have been synced", async function () {
const { v1TaikoL2 } = await deployV1TaikoL2Fixture()
const hash = await v1TaikoL2.getLatestSyncedHeader()
const { taikoL2 } = await deployTaikoL2Fixture()
const hash = await taikoL2.getLatestSyncedHeader()
expect(hash).to.be.eq(ethers.constants.HashZero)
})
})

describe("getSyncedHeader()", async function () {
it("should be 0 because header number has not been synced", async function () {
const { v1TaikoL2 } = await deployV1TaikoL2Fixture()
const hash = await v1TaikoL2.getSyncedHeader(1)
const { taikoL2 } = await deployTaikoL2Fixture()
const hash = await taikoL2.getSyncedHeader(1)
expect(hash).to.be.eq(ethers.constants.HashZero)
})
})
Expand Down
32 changes: 14 additions & 18 deletions packages/protocol/test/genesis/generate_genesis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ action("Generate Genesis", function () {
getContractAlloc("EtherVault").address
)

const v1TaikoL2 = await addressManager.getAddress(
const taikoL2 = await addressManager.getAddress(
`${testConfig.chainId}.taiko`
)

expect(v1TaikoL2).to.be.equal(getContractAlloc("V1TaikoL2").address)
expect(taikoL2).to.be.equal(getContractAlloc("TaikoL2").address)
})

it("LibTxDecoder", async function () {
Expand All @@ -147,18 +147,18 @@ action("Generate Genesis", function () {
).to.be.revertedWith("empty txList")
})

it("V1TaikoL2", async function () {
const V1TaikoL2Alloc = getContractAlloc("V1TaikoL2")
it("TaikoL2", async function () {
const TaikoL2Alloc = getContractAlloc("TaikoL2")

const V1TaikoL2 = new hre.ethers.Contract(
V1TaikoL2Alloc.address,
require("../../artifacts/contracts/L2/V1TaikoL2.sol/V1TaikoL2.json").abi,
const TaikoL2 = new hre.ethers.Contract(
TaikoL2Alloc.address,
require("../../artifacts/contracts/L2/TaikoL2.sol/TaikoL2.json").abi,
signer
)

let latestL1Height = 1
for (let i = 0; i < 300; i++) {
const tx = await V1TaikoL2.anchor(
const tx = await TaikoL2.anchor(
latestL1Height++,
ethers.utils.hexlify(ethers.utils.randomBytes(32)),
{ gasLimit: 1000000 }
Expand All @@ -170,18 +170,15 @@ action("Generate Genesis", function () {

if (i === 299) {
console.log({
message:
"V1TaikoL2.anchor gas cost after 256 L2 blocks",
message: "TaikoL2.anchor gas cost after 256 L2 blocks",
gasUsed: receipt.gasUsed,
})
}
}

const [bytes, txNums] = await generateMaxSizeInvalidTxList(
V1TaikoL2
)
const [bytes, txNums] = await generateMaxSizeInvalidTxList(TaikoL2)

const tx = await V1TaikoL2.invalidateBlock(
const tx = await TaikoL2.invalidateBlock(
bytes,
5, // hint: TX_INVALID_SIG
0
Expand All @@ -192,8 +189,7 @@ action("Generate Genesis", function () {
expect(receipt.status).to.be.equal(1)

console.log({
message:
"V1TaikoL2.invalidateBlock gas cost after 256 L2 blocks",
message: "TaikoL2.invalidateBlock gas cost after 256 L2 blocks",
TxListBytes: ethers.utils.arrayify(bytes).length,
txNums,
reason: "TX_INVALID_SIG",
Expand Down Expand Up @@ -334,8 +330,8 @@ action("Generate Genesis", function () {
}
})

async function generateMaxSizeInvalidTxList(V1TaikoL2: any) {
const constants = await V1TaikoL2.getConstants()
async function generateMaxSizeInvalidTxList(TaikoL2: any) {
const constants = await TaikoL2.getConstants()

const chainId = constants[0].toNumber()
const blockMaxTxNums = constants[7].toNumber()
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/test/genesis/test_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
}
],
"contractAddresses": {
"V1TaikoL2": "0x0000777700000000000000000000000000000001",
"TaikoL2": "0x0000777700000000000000000000000000000001",
"TokenVault": "0x0000777700000000000000000000000000000002",
"EtherVault": "0x0000777700000000000000000000000000000003",
"Bridge": "0x0000777700000000000000000000000000000004",
Expand Down
6 changes: 3 additions & 3 deletions packages/protocol/utils/generate_genesis/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Config } from "./interface"
const fs = require("fs")
const path = require("path")
const { ethers } = require("ethers")
const { deployV1TaikoL2 } = require("./v1TaikoL2")
const { deployTaikoL2 } = require("./taikoL2")
const { deployERC20 } = require("./erc20")

// Generate a L2 genesis JSON based on the given configurations.
Expand Down Expand Up @@ -45,9 +45,9 @@ async function main() {

console.log("config: %o", config)

console.log("start deploy V1TaikoL2 contract")
console.log("start deploy TaikoL2 contract")

let result = await deployV1TaikoL2(config, {
let result = await deployTaikoL2(config, {
alloc: {},
storageLayouts: {},
}).catch(console.error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const {
} = require("@defi-wonderland/smock/dist/src/utils")
const ARTIFACTS_PATH = path.join(__dirname, "../../artifacts/contracts")

// deployV1TaikoL2 generates a L2 genesis alloc of the V1TaikoL2 contract.
export async function deployV1TaikoL2(
// deployTaikoL2 generates a L2 genesis alloc of the TaikoL2 contract.
export async function deployTaikoL2(
config: Config,
result: Result
): Promise<Result> {
Expand Down Expand Up @@ -115,9 +115,9 @@ async function generateContractConfigs(
ARTIFACTS_PATH,
"./thirdparty/AddressManager.sol/AddressManager.json"
)),
V1TaikoL2: require(path.join(
TaikoL2: require(path.join(
ARTIFACTS_PATH,
"./L2/V1TaikoL2.sol/V1TaikoL2.json"
"./L2/TaikoL2.sol/TaikoL2.json"
)),
Bridge: require(path.join(
ARTIFACTS_PATH,
Expand All @@ -138,12 +138,12 @@ async function generateContractConfigs(
for (const [contractName, artifact] of Object.entries(contractArtifacts)) {
let bytecode = (artifact as any).bytecode

if (contractName === "V1TaikoL2") {
if (contractName === "TaikoL2") {
if (!addressMap.LibTxDecoder) {
throw new Error("LibTxDecoder not initialized")
}

bytecode = linkContractLibs(contractArtifacts.V1TaikoL2, addressMap)
bytecode = linkContractLibs(contractArtifacts.TaikoL2, addressMap)
} else if (contractName === "LibBridgeProcess") {
if (!addressMap.LibTrieProof) {
throw new Error("LibTrieProof not initialized")
Expand Down Expand Up @@ -226,7 +226,7 @@ async function generateContractConfigs(
[`${ethers.utils.solidityKeccak256(
["string"],
[`${chainId}.taiko`]
)}`]: addressMap.V1TaikoL2,
)}`]: addressMap.TaikoL2,
[`${ethers.utils.solidityKeccak256(
["string"],
[`${chainId}.bridge`]
Expand All @@ -242,18 +242,18 @@ async function generateContractConfigs(
},
},
},
V1TaikoL2: {
address: addressMap.V1TaikoL2,
TaikoL2: {
address: addressMap.TaikoL2,
deployedBytecode: linkContractLibs(
contractArtifacts.V1TaikoL2,
contractArtifacts.TaikoL2,
addressMap
),
variables: {
// ReentrancyGuardUpgradeable
_status: 1, // _NOT_ENTERED
// AddressResolver
_addressManager: addressMap.AddressManager,
// V1TaikoL2
// TaikoL2
// keccak256(abi.encodePacked(block.chainid, basefee, ancestors))
publicInputHash: `${ethers.utils.solidityKeccak256(
["uint256", "uint256", "uint256", "bytes32[255]"],
Expand Down
2 changes: 1 addition & 1 deletion packages/relayer/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ terraform.rc
.idea

Bridge.json
V1TaikoL2.json
TaikoL2.json
IHeaderSync.json
4 changes: 2 additions & 2 deletions packages/relayer/abigen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ if [ ! -d "../protocol/artifacts" ]; then
exit 1
fi

paths=("bridge/Bridge.sol" "common/IHeaderSync.sol" "L2/V1TaikoL2.sol" "L1/TaikoL1.sol")
paths=("bridge/Bridge.sol" "common/IHeaderSync.sol" "L2/TaikoL2.sol" "L1/TaikoL1.sol")

names=("Bridge" "IHeaderSync" "V1TaikoL2" "TaikoL1")
names=("Bridge" "IHeaderSync" "TaikoL2" "TaikoL1")

for (( i = 0; i < ${#paths[@]}; ++i ));
do
Expand Down
Loading

0 comments on commit 1f63367

Please sign in to comment.