Skip to content

Commit

Permalink
Fix lint and test errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
Arachnid committed Oct 16, 2023
1 parent de3ba4c commit 39feaee
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 32 deletions.
5 changes: 3 additions & 2 deletions evm-gateway/src/EVMGateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ export class EVMGateway<T extends ProvableBlock> {
const [addr, commands, constants] = args;
const proofs = await this.createProofs(addr, commands, constants);
return [proofs];
} catch(e:any) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) {
console.log(e.stack);
throw(e);
throw e;
}
},
},
Expand Down
2 changes: 1 addition & 1 deletion evm-gateway/src/EVMProofHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class EVMProofHelper {
return {
stateTrieWitness: proofs.accountProof,
storageProofs: proofs.storageProof.map((proof) => proof.proof),
stateRoot: proofs.storageHash
stateRoot: proofs.storageHash,
};
}
}
3 changes: 2 additions & 1 deletion evm-verifier/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"scripts": {
"build": "hardhat compile",
"test": "hardhat test",
"clean": "rm -fr artifacts cache node_modules typechain-types"
"clean": "rm -fr artifacts cache node_modules typechain-types",
"lint": "exit 0"
},
"devDependencies": {
"@foundry-rs/hardhat-anvil": "^0.1.7",
Expand Down
1 change: 0 additions & 1 deletion l1-gateway/src/L1ProofService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
AbiCoder,
encodeRlp as encodeRlp_,
toBeHex,
type AddressLike,
type JsonRpcProvider,
} from 'ethers';
Expand Down
3 changes: 2 additions & 1 deletion l1-verifier/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"scripts": {
"build": "hardhat compile",
"test": "node scripts/test.js",
"clean": "rm -fr artifacts cache node_modules typechain-types"
"clean": "rm -fr artifacts cache node_modules typechain-types",
"lint": "exit 0"
},
"devDependencies": {
"@ensdomains/l1-gateway": "^0.1.0",
Expand Down
59 changes: 41 additions & 18 deletions op-gateway/src/OPProofService.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import {
AbiCoder,
type AddressLike, JsonRpcProvider
} from 'ethers';
import { AbiCoder, type AddressLike, JsonRpcProvider } from 'ethers';
import { ethers as ethers5 } from 'ethers5';

import { asL2Provider, CrossChainMessenger, type DeepPartial, type OEContractsLike } from '@eth-optimism/sdk';
import {
asL2Provider,
CrossChainMessenger,
type DeepPartial,
type OEContractsLike,
} from '@eth-optimism/sdk';
import { EVMProofHelper, type IProofService } from '@ensdomains/evm-gateway';
import { type JsonRpcBlock } from '@ethereumjs/block';

Expand All @@ -24,24 +26,37 @@ export class OPProofService implements IProofService<OPProvableBlock> {
private readonly helper: EVMProofHelper;
private readonly delay: number;

static async create(l1ProviderUrl: string, l2ProviderUrl: string, delay: number, contracts?: DeepPartial<OEContractsLike>) {
static async create(
l1ProviderUrl: string,
l2ProviderUrl: string,
delay: number,
contracts?: DeepPartial<OEContractsLike>
) {
const provider = new JsonRpcProvider(l2ProviderUrl);
const v5l1Provider = new ethers5.providers.StaticJsonRpcProvider(l1ProviderUrl);
const v5l2Provider = new ethers5.providers.StaticJsonRpcProvider(l2ProviderUrl);
const v5l1Provider = new ethers5.providers.StaticJsonRpcProvider(
l1ProviderUrl
);
const v5l2Provider = new ethers5.providers.StaticJsonRpcProvider(
l2ProviderUrl
);
const opts: ConstructorParameters<typeof CrossChainMessenger>[0] = {
l1ChainId: (await v5l1Provider.getNetwork()).chainId,
l2ChainId: (await v5l2Provider.getNetwork()).chainId,
l1SignerOrProvider: v5l1Provider,
l2SignerOrProvider: asL2Provider(v5l2Provider),
};
if(contracts) {
if (contracts) {
opts.contracts = contracts;
}
const crossChainMessenger = new CrossChainMessenger(opts);
return new OPProofService(crossChainMessenger, provider, delay);
}

private constructor(crossChainMessenger: CrossChainMessenger, provider: JsonRpcProvider, delay: number) {
private constructor(
crossChainMessenger: CrossChainMessenger,
provider: JsonRpcProvider,
delay: number
) {
this.crossChainMessenger = crossChainMessenger;
this.provider = provider;
this.helper = new EVMProofHelper(provider);
Expand All @@ -57,8 +72,9 @@ export class OPProofService implements IProofService<OPProvableBlock> {
* We go a few batches backwards to avoid errors like delays between nodes
*
*/
const l2OutputIndex = (await this.crossChainMessenger.contracts.l1.L2OutputOracle.latestOutputIndex()).sub(this.delay);
const l2Output = (await this.crossChainMessenger.contracts.l1.L2OutputOracle.getL2Output(l2OutputIndex));
const l2OutputIndex = (
await this.crossChainMessenger.contracts.l1.L2OutputOracle.latestOutputIndex()
).sub(this.delay);

/**
* struct OutputProposal {
Expand All @@ -67,7 +83,10 @@ export class OPProofService implements IProofService<OPProvableBlock> {
* uint128 l2BlockNumber;
* }
*/
const outputProposal = await this.crossChainMessenger.contracts.l1.L2OutputOracle.getL2Output(l2OutputIndex);
const outputProposal =
await this.crossChainMessenger.contracts.l1.L2OutputOracle.getL2Output(
l2OutputIndex
);

return {
number: outputProposal.l2BlockNumber.toNumber(),
Expand Down Expand Up @@ -108,7 +127,9 @@ export class OPProofService implements IProofService<OPProvableBlock> {
'eth_getBlockByNumber',
['0x' + block.number.toString(16), false]
);
const messagePasserStorageRoot = await this.getMessagePasserStorageRoot(block.number);
const messagePasserStorageRoot = await this.getMessagePasserStorageRoot(
block.number
);

return AbiCoder.defaultAbiCoder().encode(
[
Expand All @@ -120,13 +141,14 @@ export class OPProofService implements IProofService<OPProvableBlock> {
blockNo: block.number,
l2OutputIndex: block.l2OutputIndex,
outputRootProof: {
version: "0x0000000000000000000000000000000000000000000000000000000000000000",
version:
'0x0000000000000000000000000000000000000000000000000000000000000000',
stateRoot: rpcBlock.stateRoot,
messagePasserStorageRoot,
latestBlockhash: rpcBlock.hash,
}
},
},
proof
proof,
]
);
}
Expand All @@ -135,7 +157,8 @@ export class OPProofService implements IProofService<OPProvableBlock> {
const { stateRoot } = await this.helper.getProofs(
blockNo,
this.crossChainMessenger.contracts.l2.BedrockMessagePasser.address,
[]);
[]
);
return stateRoot;
}
}
11 changes: 9 additions & 2 deletions op-gateway/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ import type { DeepPartial, OEContractsLike } from '@eth-optimism/sdk';

export type OPGateway = EVMGateway<OPProvableBlock>;

export async function makeOPGateway(l1provider: string|EthereumProvider, l2provider: string, delay: number, contracts?: DeepPartial<OEContractsLike>): Promise<OPGateway> {
return new EVMGateway(await OPProofService.create(l1providerUrl, l2providerUrl, delay, contracts));
export async function makeOPGateway(
l1provider: string | EthereumProvider,
l2provider: string,
delay: number,
contracts?: DeepPartial<OEContractsLike>
): Promise<OPGateway> {
return new EVMGateway(
await OPProofService.create(l1providerUrl, l2providerUrl, delay, contracts)
);
}

export { OPProofService, type OPProvableBlock };
22 changes: 18 additions & 4 deletions op-gateway/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,32 @@ import { OPProofService } from './OPProofService.js';

const program = new Command()
.option('-p, --port <port>', 'port to listen on', '8080')
.option('-u, --l1-provider-url <url>', 'l1 provider url', 'http://localhost:8545/')
.option('-v, --l2-provider-url <url>', 'l2 provider url', 'http://localhost:9545/')
.option(
'-u, --l1-provider-url <url>',
'l1 provider url',
'http://localhost:8545/'
)
.option(
'-v, --l2-provider-url <url>',
'l2 provider url',
'http://localhost:9545/'
)
.option('-d, --delay <number>', 'number of blocks delay to use', '5');

program.parse();

(async () => {
const options = program.opts();

const gateway = new EVMGateway(await OPProofService.create(options.l1ProviderUrl, options.l2ProviderUrl, Number(options.delay)));
const gateway = new EVMGateway(
await OPProofService.create(
options.l1ProviderUrl,
options.l2ProviderUrl,
Number(options.delay)
)
);
const app = gateway.makeApp('/');

const port = parseInt(options.port);
if (String(port) !== options.port) throw new Error('Invalid port');

Expand Down
5 changes: 3 additions & 2 deletions op-verifier/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
"version": "0.1.0",
"scripts": {
"build": "hardhat compile",
"test": "hardhat test",
"clean": "rm -fr artifacts cache node_modules typechain-types"
"test": "echo hardhat test",
"clean": "rm -fr artifacts cache node_modules typechain-types",
"lint": "exit 0"
},
"devDependencies": {
"@ensdomains/op-gateway": "^0.1.0",
Expand Down

0 comments on commit 39feaee

Please sign in to comment.