Skip to content

Commit

Permalink
Merge pull request #11 from ConsenSys/feat/test-on-goerli-fork
Browse files Browse the repository at this point in the history
Feat/test on goerli fork
  • Loading branch information
Julink-eth authored Apr 7, 2023
2 parents d52bc88 + b8ba1c6 commit 6da0f62
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 172 deletions.
38 changes: 29 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,32 @@ yarn hardhat node --fork YOUR_GOERLI_L1_RPC_URL

### Deploy contracts

In second terminal, deploy L1 and L2 smart contracts:
In second terminal, deploy L1 and L2 smart contracts.

Compile
Set your `.env` config file. You can copy [env.example](./packages/contracts/.env.example):

```bash
cd packages/contracts
cp .env.example .env
```

Edit `.env` and set your config:

| Var | Description | Default values |
| ----------------- | ------------------------- | --------------------------------------------------------- |
| GOERLI_URL | Goerli provider URL | |
| GOERLI_LINEA_URL | Linea Goerli provider URL | |
| PRIVATE_KEY | Wallet private key | |
| ETHERSCAN_API_KEY | Etherscan API key | |
| L1_ENS_NAME | L1 ENS name | lineatest.eth |
| L2_ENS_NAME | L2 ENS name | julink.lineatest.eth |
| GATEWAY_URL | Primary gateway URL | https://www.ensgateway.amineharty.me/{sender}/{data}.json |

For local/L2 mode, `GOERLI_URL` is not required.

Compile smart contracts:

```bash
yarn hardhat compile
```

Expand All @@ -31,21 +51,21 @@ Deploy L2 contracts first:
npx hardhat run --network goerliLinea scripts/deployL2.ts
```

Get the resolver address, then deploy L1 contracts.
Get the `L2_RESOLVER_ADDRESS` resolver address, then deploy L1 contracts:

```
L2_RESOLVER_ADDRESS=$L2_RESOLVER_ADDRESS npx hardhat run --network localhost scripts/deployL1.ts
```

### Start Gateway server

Then start the gateway.
Once smart contracts are deployed, start the gateway:

```bash
cd ../gateway
yarn
yarn build
yarn start --l2_resolver_address $L2_RESOLVER_ADDRESS --l1_provider_url http://127.0.0.1:8545/ --l1_chain_id 5 --l2_provider_url YOUR_GOERLI_L2_RPC_URL --l2_chain_id 59140
yarn start --l2_resolver_address $L2_RESOLVER_ADDRESS --l1_provider_url http://127.0.0.1:8545/ --l2_provider_url $GOERLI_LINEA_URL --l2_chain_id 59140
```

### Run Client test script
Expand All @@ -54,10 +74,10 @@ In a third terminal, run the demo app:

```bash
cd packages/clients
yarn start -r $ENS_REGISTRY_ADDRESS test.test --l1_provider_url http://127.0.0.1:8545/ --chainId 5 --l2_provider_url YOUR_GOERLI_L2_RPC_URL
yarn start julink.lineatest.eth
```

If sucessful, it should show the following output
If successful, it should show the following output:

```bash
addr(bytes32) 0xF110a41f75edEb224227747b64Be7f6A7f140abc
Expand All @@ -73,14 +93,14 @@ addr(bytes32) 0xF110a41f75edEb224227747b64Be7f6A7f140abc

## Deploy gateway

Create secret.yaml and update credentials
Create secret.yaml and update credentials:

```
cd gateway
cp secret.yaml.org secret.yaml
```

Deploy to app engine
Deploy to app engine:

```
gcloud app deploy goeril.app.yml
Expand Down
31 changes: 12 additions & 19 deletions packages/client/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
import { Command } from "commander";
import { ethers } from "ethers";
import fetch from "cross-fetch";
import { REGISTRY_ADDRESS } from "./constants";

const namehash = require("eth-ens-namehash");
const StubAbi = require("../abi/LineaResolverStub.json").abi;
const program = new Command();
const { defaultAbiCoder, hexConcat } = require("ethers/lib/utils");
program
.requiredOption("-r --registry <address>", "ENS registry address")
.requiredOption(
"-r --registry <address>",
"ENS registry address",
REGISTRY_ADDRESS
)
.option(
"-l1 --l1_provider_url <url1>",
"L1_PROVIDER_URL",
"http://127.0.0.1:8545/"
)
.option(
"-l2 --l2_provider_url <url2>",
"L2_PROVIDER_URL",
"http://127.0.0.1:8545/"
)
.option("-i --chainId <chainId>", "chainId", "31337")
.option("-n --chainName <chainName>", "chainName", "unknown")
.option("-d --debug", "debug", false)
Expand All @@ -35,16 +32,12 @@ console.log("options", {
chainName,
debug,
});
let provider: ethers.providers.JsonRpcProvider;
if (chainId && chainName) {
provider = new ethers.providers.JsonRpcProvider(l1_provider_url, {
chainId,
name: chainName,
ensAddress,
});
} else {
provider = new ethers.providers.JsonRpcProvider(options.l1_provider_url);
}

const provider = new ethers.providers.JsonRpcProvider(l1_provider_url, {
chainId,
name: chainName,
ensAddress,
});

(async () => {
const name = program.args[0];
Expand Down
5 changes: 4 additions & 1 deletion packages/contracts/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
GOERLI_URL=
GOERLI_LINEA_URL=
PRIVATE_KEY=
ETHERSCAN_API_KEY=
ETHERSCAN_API_KEY=
L1_ENS_NAME=lineatest.eth
L2_ENS_NAME=julink.lineatest.eth
GATEWAY_URL=https://www.ensgateway.amineharty.me/{sender}/{data}.json
9 changes: 5 additions & 4 deletions packages/contracts/contracts/l1/LineaResolverStub.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
pragma abicoder v2;

import { Lib_OVMCodec } from "@eth-optimism/contracts/libraries/codec/Lib_OVMCodec.sol";
import { Lib_SecureMerkleTrie } from "@eth-optimism/contracts/libraries/trie/Lib_SecureMerkleTrie.sol";
import { Lib_RLPReader } from "@eth-optimism/contracts/libraries/rlp/Lib_RLPReader.sol";
import { Lib_BytesUtils } from "@eth-optimism/contracts/libraries/utils/Lib_BytesUtils.sol";

import "hardhat/console.sol";

struct L2StateProof {
uint64 nodeIndex;
bytes32 blockHash;
Expand Down Expand Up @@ -76,7 +73,6 @@ contract LineaResolverStub is IExtendedResolver, SupportsInterface {
bytes calldata name,
bytes calldata data
) external view override returns (bytes memory) {
console.log("name %s", string(name));
bytes memory callData = abi.encodeWithSelector(
IResolverService.resolve.selector,
name,
Expand Down Expand Up @@ -119,6 +115,11 @@ contract LineaResolverStub is IExtendedResolver, SupportsInterface {
proof.storageTrieWitness
);

require(
keccak256(proof.result) == keccak256(abi.encode(value)),
"LineaResolverStub: value different from expected result"
);

return proof.result;
}

Expand Down
61 changes: 0 additions & 61 deletions packages/contracts/contracts/l1/utils/BytesUtils.sol

This file was deleted.

47 changes: 0 additions & 47 deletions packages/contracts/contracts/l1/utils/NameEncoder.sol

This file was deleted.

20 changes: 10 additions & 10 deletions packages/contracts/contracts/l2/LineaResolver.sol
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";

contract LineaResolver is Ownable {
mapping(bytes32 => address) addresses;
mapping(bytes32 => address) addresses;

event AddrChanged(bytes32 indexed node, address a);
event AddrChanged(bytes32 indexed node, address a);

function setAddr(bytes32 node, address _addr) public onlyOwner {
addresses[node] = _addr;
emit AddrChanged(node, _addr);
}
function setAddr(bytes32 node, address _addr) public {
addresses[node] = _addr;
emit AddrChanged(node, _addr);
}

function addr(bytes32 node) public view returns (address) {
return addresses[node];
}
function addr(bytes32 node) public view returns (address) {
return addresses[node];
}
}
11 changes: 5 additions & 6 deletions packages/contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,23 @@ import * as dotenv from "dotenv";
import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";

const hardhatPrivateKey = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80";

dotenv.config();

const config: HardhatUserConfig = {
solidity: "0.8.17",
networks: {
goerli: {
url: process.env.GOERLI_URL,
accounts:
process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [],
accounts: process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [],
},
goerliLinea: {
url: process.env.GOERLI_LINEA_URL,
accounts:
process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [],
accounts: process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [],
},
localhost: {
accounts:
process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [],
accounts: process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY, hardhatPrivateKey] : [],
},
},
etherscan: {
Expand Down
16 changes: 12 additions & 4 deletions packages/contracts/scripts/deployL1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@ import { REGISTRY_ADDRESS, ROLLUP_ADDRESSES } from "./constants";
const ensRegistryAbi = require("../abi/ENSRegistry.json");
const namehash = require("eth-ens-namehash");

const HARDHAT_NETWORK_CHAIN_ID = 31337;

let L2_RESOLVER_ADDRESS: string;
async function main() {
const [owner] = await ethers.getSigners();
const [owner, hardhatAccount] = await ethers.getSigners();
const chainId = await owner.getChainId();

// If on localhost we can send ETH to the owner so that we make sure we have enough for deployment
if (chainId === HARDHAT_NETWORK_CHAIN_ID) {
await hardhatAccount.sendTransaction({ value: ethers.utils.parseEther("100"), to: owner.address });
}

if (process.env.L2_RESOLVER_ADDRESS) {
L2_RESOLVER_ADDRESS = process.env.L2_RESOLVER_ADDRESS;
} else {
Expand All @@ -23,12 +30,13 @@ async function main() {
console.log(`LineaResolverStub deployed to ${lineaResolverStub.address}`);
const registryAddr = REGISTRY_ADDRESS[network.name as keyof typeof REGISTRY_ADDRESS];
const registry = await new ethers.Contract(registryAddr, ensRegistryAbi, owner);
const node = namehash.hash("lineatest.eth");
console.log("node", node);
const name = process.env.L1_ENS_NAME ? process.env.L1_ENS_NAME : "lineatest.eth";
const node = namehash.hash(name);
let tx = await registry.setResolver(node, lineaResolverStub.address);
await tx.wait();
console.log("L1 ENS name:", name, ", set to LineaResolverStub: ", lineaResolverStub.address);

if (chainId !== 31337) {
if (chainId !== HARDHAT_NETWORK_CHAIN_ID) {
// Only verify on "live" blockchain
setTimeout(async () => {
await run("verify:verify", {
Expand Down
Loading

0 comments on commit 6da0f62

Please sign in to comment.