Skip to content

Commit

Permalink
add another zksync, add ink, bump blocksmith
Browse files Browse the repository at this point in the history
  • Loading branch information
adraffy committed Nov 14, 2024
1 parent 501c9ff commit 4b8aec7
Show file tree
Hide file tree
Showing 15 changed files with 114 additions and 41 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"contracts/ReadBytesAt.sol"
],
"devDependencies": {
"@adraffy/blocksmith": "^0.1.46",
"@adraffy/blocksmith": "^0.1.47",
"@types/bun": "latest",
"@typescript-eslint/eslint-plugin": "^6.7.4",
"@typescript-eslint/parser": "^6.7.4",
Expand Down
3 changes: 2 additions & 1 deletion src/GatewayProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export class GatewayProvider extends JsonRpcProvider {
jsonrpc: '2.0',
}),
});
const { result } = await res.json();
const { result, error } = await res.json();
if (!res.ok || error) throw new Error(error?.message ?? 'expected rpc');
return new this(new FetchRequest(url), BigInt(result));
}
constructor(
Expand Down
3 changes: 3 additions & 0 deletions src/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ export const CHAINS = {
WORLD: 480n,
WORLD_SEPOLIA: 4801n,
APE: 33139n,
ZERO: 543210n,
ZERO_SEPOLIA: 4457845n,
INK_SEPOLIA: 763373n,
} as const satisfies Record<string, Chain>;

export function chainName(chain: Chain): string {
Expand Down
8 changes: 8 additions & 0 deletions src/op/OPFaultRollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ export class OPFaultRollup extends AbstractOPRollup {
GameFinder: GAME_FINDER_SEPOLIA,
};

// https://docs.inkonchain.com/build/useful-info/ink-contracts#l1-testnet-contracts-sepolia
static readonly inkSepoliaConfig: RollupDeployment<OPFaultConfig> = {
chain1: CHAINS.SEPOLIA,
chain2: CHAINS.INK_SEPOLIA,
OptimismPortal: '0x5c1d29C6c9C8b0800692acC95D700bcb4966A1d7',
GameFinder: GAME_FINDER_SEPOLIA,
};

// 20240917: delayed constructor not needed
readonly OptimismPortal: Contract;
readonly GameFinder: Contract;
Expand Down
1 change: 1 addition & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const NULL_CODE_HASH = keccakStr('');

export const EVM_BLOCKHASH_DEPTH = 256;

// TODO: make this a function of Chain
export const MAINNET_BLOCK_SEC = 12;

export const LATEST_BLOCK_TAG = 'latest';
Expand Down
15 changes: 13 additions & 2 deletions src/zksync/ZKSyncRollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,22 @@ export class ZKSyncRollup extends AbstractRollup<ZKSyncCommit> {
chain2: CHAINS.ZKSYNC,
DiamondProxy: '0x32400084c286cf3e17e7b677ea9583e60a000324',
};

static readonly sepoliaConfig: RollupDeployment<ZKSyncConfig> = {
chain1: CHAINS.SEPOLIA,
chain2: CHAINS.ZKSYNC_SEPOLIA,
DiamondProxy: '0x9a6de0f62Aa270A8bCB1e2610078650D539B1Ef9',
DiamondProxy: '0x9A6DE0f62Aa270A8bCB1e2610078650D539B1Ef9',
};

// https://docs.zero.network/main-features/system-contracts#zer%CE%B8-network
static readonly zeroMainnetConfig: RollupDeployment<ZKSyncConfig> = {
chain1: CHAINS.MAINNET,
chain2: CHAINS.ZERO,
DiamondProxy: '0xdbD849acC6bA61F461CB8A41BBaeE2D673CA02d9',
};
static readonly zeroSepoliaConfig: RollupDeployment<ZKSyncConfig> = {
chain1: CHAINS.SEPOLIA,
chain2: CHAINS.ZERO_SEPOLIA,
DiamondProxy: '0x9A62B01fFa3bD358d03508ef60bB522ABA5d1bEb',
};

readonly DiamondProxy: Contract;
Expand Down
34 changes: 34 additions & 0 deletions test/gateway/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import {
ScrollRollup,
} from '../../src/scroll/ScrollRollup.js';
import { type LineaConfig, LineaRollup } from '../../src/linea/LineaRollup.js';
import {
type ZKSyncConfig,
ZKSyncRollup,
} from '../../src/zksync/ZKSyncRollup.js';
import { EthSelfRollup } from '../../src/eth/EthSelfRollup.js';
import { TrustedRollup } from '../../src/TrustedRollup.js';
import { EthProver } from '../../src/eth/EthProver.js';
Expand Down Expand Up @@ -271,3 +275,33 @@ export function testLinea(
await setupTests(verifier, opts);
});
}

export function testZKSync(
config: RollupDeployment<ZKSyncConfig>,
opts: TestOptions
) {
describe.skipIf(shouldSkip(opts))(testName(config), async () => {
const rollup = new ZKSyncRollup(createProviderPair(config), config);
const foundry = await Foundry.launch({
fork: providerURL(config.chain1),
infoLog: !!opts.log,
infiniteCallGas: true, // Blake2s is ~12m gas per proof!
});
afterAll(foundry.shutdown);
const gateway = new Gateway(rollup);
const ccip = await serve(gateway, { protocol: 'raw', log: !!opts.log });
afterAll(ccip.shutdown);
const GatewayVM = await foundry.deploy({ file: 'GatewayVM' });
const ZKSyncSMT = await foundry.deploy({ file: 'ZKSyncSMT' });
const hooks = await foundry.deploy({
file: 'ZKSyncVerifierHooks',
args: [ZKSyncSMT],
});
const verifier = await foundry.deploy({
file: 'ZKSyncVerifier',
args: [[ccip.endpoint], rollup.defaultWindow, hooks, rollup.DiamondProxy],
libs: { GatewayVM },
});
await setupTests(verifier, opts);
});
}
10 changes: 10 additions & 0 deletions test/gateway/ink-sepolia.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { OPFaultRollup } from '../../src/op/OPFaultRollup.js';
import { testOPFault } from './common.js';

testOPFault(OPFaultRollup.inkSepoliaConfig, {
// https://explorer-sepolia.inkonchain.com/address/0x0d3e01829E8364DeC0e7475ca06B5c73dbA33ef6?tab=contract
slotDataContract: '0x0d3e01829E8364DeC0e7475ca06B5c73dbA33ef6',
// https://explorer-sepolia.inkonchain.com/address/0x57C2F437E0a5E155ced91a7A17bfc372C0aF7B05?tab=contract
slotDataPointer: '0x57C2F437E0a5E155ced91a7A17bfc372C0aF7B05',
skipCI: true,
});
8 changes: 8 additions & 0 deletions test/gateway/zero.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ZKSyncRollup } from '../../src/zksync/ZKSyncRollup.js';
import { testZKSync } from './common.js';

testZKSync(ZKSyncRollup.zeroMainnetConfig, {
// https://zerion-explorer.vercel.app/address/0x1Cd42904e173EA9f7BA05BbB685882Ea46969dEc#contract
slotDataContract: '0x1Cd42904e173EA9f7BA05BbB685882Ea46969dEc',
skipCI: true,
});
10 changes: 10 additions & 0 deletions test/gateway/zksync-sepolia.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ZKSyncRollup } from '../../src/zksync/ZKSyncRollup.js';
import { testZKSync } from './common.js';

testZKSync(ZKSyncRollup.sepoliaConfig, {
// https://sepolia.explorer.zksync.io/address/0x1Cd42904e173EA9f7BA05BbB685882Ea46969dEc#contract
slotDataContract: '0x1Cd42904e173EA9f7BA05BbB685882Ea46969dEc',
// https://sepolia.explorer.zksync.io/address/0x8D42501ADE3d0D02033B7FB6FfEa338828a1A467
slotDataPointer: '0x8D42501ADE3d0D02033B7FB6FfEa338828a1A467',
skipCI: true,
});
41 changes: 7 additions & 34 deletions test/gateway/zksync.test.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,10 @@
import { ZKSyncRollup } from '../../src/zksync/ZKSyncRollup.js';
import { Gateway } from '../../src/gateway.js';
import { serve } from '@resolverworks/ezccip/serve';
import { Foundry } from '@adraffy/blocksmith';
import { createProviderPair, providerURL } from '../providers.js';
import { setupTests, testName } from './common.js';
import { describe } from '../bun-describe-fix.js';
import { afterAll } from 'bun:test';
import { testZKSync } from './common.js';

const config = ZKSyncRollup.mainnetConfig;
describe(testName(config), async () => {
const rollup = new ZKSyncRollup(createProviderPair(config), config);
const foundry = await Foundry.launch({
fork: providerURL(config.chain1),
infoLog: false,
infiniteCallGas: true, // Blake2s is ~12m gas per proof!
});
afterAll(foundry.shutdown);
const gateway = new Gateway(rollup);
const ccip = await serve(gateway, { protocol: 'raw', log: false });
afterAll(ccip.shutdown);
const GatewayVM = await foundry.deploy({ file: 'GatewayVM' });
const ZKSyncSMT = await foundry.deploy({ file: 'ZKSyncSMT' });
const hooks = await foundry.deploy({
file: 'ZKSyncVerifierHooks',
args: [ZKSyncSMT],
});
const verifier = await foundry.deploy({
file: 'ZKSyncVerifier',
args: [[ccip.endpoint], rollup.defaultWindow, hooks, rollup.DiamondProxy],
libs: { GatewayVM },
});
await setupTests(verifier, {
// https://explorer.zksync.io/address/0x1Cd42904e173EA9f7BA05BbB685882Ea46969dEc#contract
slotDataContract: '0x1Cd42904e173EA9f7BA05BbB685882Ea46969dEc',
});
testZKSync(ZKSyncRollup.mainnetConfig, {
// https://explorer.zksync.io/address/0x1Cd42904e173EA9f7BA05BbB685882Ea46969dEc#contract
slotDataContract: '0x1Cd42904e173EA9f7BA05BbB685882Ea46969dEc',
// https://explorer.zksync.io/address/0x8D42501ADE3d0D02033B7FB6FfEa338828a1A467#contract
// TODO: enable this after batch 494047 is finalized
//slotDataPointer: '0x8D42501ADE3d0D02033B7FB6FfEa338828a1A467',
});
14 changes: 14 additions & 0 deletions test/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,20 @@ export const RPC_INFO = new Map<Chain, RPCInfo>(
// wss://rpc.apechain.com/ws
// https://apechain.calderachain.xyz/http
},
// https://docs.zero.network/build-on-zero/network-information#zer%CE%B8-network
{
chain: CHAINS.ZERO,
rpc: 'https://rpc.zerion.io/v1/zero',
},
{
chain: CHAINS.ZERO_SEPOLIA,
rpc: 'https://rpc.zerion.io/v1/zero-sepolia',
},
// https://docs.inkonchain.com/quick-start/get-connected
{
chain: CHAINS.INK_SEPOLIA,
rpc: 'https://rpc-qnd-sepolia.inkonchain.com', // wss://rpc-qnd-sepolia.inkonchain.com
},
] satisfies RPCInfo[]
).map((x) => [x.chain, x])
);
Expand Down
4 changes: 2 additions & 2 deletions test/rollup/trusted.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { randomBytes, SigningKey } from 'ethers/crypto';
import { CHAINS } from '../../src/chains.js';
import { TrustedRollup } from '../../src/TrustedRollup.js';
import { EthProver } from '../../src/index.js';
import { EthProver } from '../../src/eth/EthProver.js';
import { createProvider } from '../providers.js';

const rollup = new TrustedRollup(
Expand All @@ -16,7 +16,7 @@ console.log({
cacheMs: rollup.latest.cacheMs,
});

// there is only 1 commit, always index 0
// there is only 1 commit
const { prover: _, ...commit } = await rollup.fetchCommit(0n);

console.log(commit);
Expand Down
2 changes: 1 addition & 1 deletion test/workarounds/polygon-proof-retry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { toPaddedHex } from '../../src/utils.js';
import { test, expect, afterAll } from 'bun:test';
import { describe } from '../bun-describe-fix.js';
import { CHAINS } from '../../src/chains.js';
import { EthProver } from '../../src/index.js';
import { EthProver } from '../../src/eth/EthProver.js';
import { Provider } from '../../src/types.js';

describe.skipIf(!!process.env.IS_CI)('polygon eth_getProof retry', async () => {
Expand Down

0 comments on commit 4b8aec7

Please sign in to comment.