Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- name: Install dependencies
run: bun install
Expand All @@ -24,7 +26,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- name: Install dependencies
run: bun install
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/fetch-data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ jobs:
ALCHEMY_API_KEY: ${{ secrets.ALCHEMY_API_KEY }}
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- name: Print versions
run: |
bun --version
bun -p process.version

- name: Install dependencies
run: bun install
Expand Down
Binary file modified bun.lockb
Binary file not shown.
9 changes: 6 additions & 3 deletions script/archive/precompile-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// they are precompiles or predeploys, and prints the result.
// Example usage:
// bun script/precompile-check.ts optimism
import { http, type Address, createPublicClient, getAddress } from 'viem';
import { http, type Address, createPublicClient, getAddress, type GetBytecodeReturnType } from 'viem';
import { type Chain, arbitrum, optimism } from 'viem/chains';

type ChainConfig = {
Expand Down Expand Up @@ -74,8 +74,11 @@ async function main() {
const transport = http(rpcUrl, { batch: true });
const client = createPublicClient({ chain, transport });

const promises = addresses.map((address) => client.getBytecode({ address }));
const codes = await Promise.all(promises);
const codes: GetBytecodeReturnType[] = []
for (const address of addresses) {
const code = await client.getBytecode({ address });
codes.push(code);
}
const kinds = codes.map((code) =>
code === '0x' || code === '0xfe' ? 'precompile' : 'predeploy',
);
Expand Down
9 changes: 5 additions & 4 deletions script/checks/deployed-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ const NO_CODE_HASH = keccak256('0x');
export async function checkDeployedContracts(
client: PublicClient,
): Promise<{ name: string; address: Address; codeHash: Hex; hasCode: boolean }[]> {
const result = deployedContracts.map(async ({ name, address }) => {
const result = [];
for (const { name, address } of deployedContracts) {
const code = await client.getBytecode({ address });
const codeHash = (code && keccak256(code)) || NO_CODE_HASH;
return { name, address, codeHash, hasCode: codeHash !== NO_CODE_HASH };
});
return await Promise.all(result);
result.push({ name, address, codeHash, hasCode: codeHash !== NO_CODE_HASH });
}
return result;
}

export const deployedContracts: { name: string; address: Address }[] = [
Expand Down
8 changes: 4 additions & 4 deletions script/checks/evm-stack-addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ export async function checkEvmStackAddresses(

for (const stack of Object.keys(evmStackAddresses)) {
const stackPredploys = evmStackAddresses[stack as EVMStack];
const res = stackPredploys.map(async ({ name, address, kind }) => {
result[stack as EVMStack] = [];
for (const { name, address, kind } of stackPredploys) {
const code = await client.getBytecode({ address });
const codeHash = (code && keccak256(code)) || NO_CODE_HASH;
const exists = evmStackAddressExists(stack as EVMStack, codeHash);
return { name, address, kind, codeHash, exists };
});
result[stack as EVMStack] = await Promise.all(res);
result[stack as EVMStack].push({ name, address, kind, codeHash, exists });
}
}

return result;
Expand Down
34 changes: 28 additions & 6 deletions script/checks/opcodes.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { type Hex, type PublicClient, toHex } from 'viem';

type Opcode = number;
type CallError = { details: string };

export async function checkOpcodes(
client: PublicClient,
): Promise<{ number: Hex; name: string; supported: boolean | string }[]> {
const opcodes = Array.from(Array(0xff + 1).keys());
const supported = await Promise.all(opcodes.map(async (opcode) => checkOpcode(opcode, client)));
const supported: Array<boolean | 'unknown'> = [];
for (const opcode of opcodes) {
supported.push(await checkOpcode(opcode, client));
}

const result: { number: Hex; name: string; supported: boolean | string }[] = [];
opcodes.forEach((opcode, index) => {
Expand All @@ -29,15 +31,34 @@ async function checkOpcode(opcode: Opcode, client: PublicClient): Promise<boolea
try {
await client.call({ data: toHex(opcode, { size: 1 }) });
return true; // Call succeeded so opcode is supported.
} catch (e: unknown) {
const err = e as CallError;
} catch (err: unknown) {
if (
typeof err !== 'object' ||
err === null ||
!('details' in err) ||
typeof err.details !== 'string'
) {
throw err;
}
const details = err.details.toLowerCase();
// TODO These might be specific to the node implementation, can this be more robust?
if (opcode === 0xfe && details.includes('invalid opcode: invalid')) return true; // Designated invalid opcode.
if (details.includes('stack underflow')) return true; // Implies opcode is supported.
if (
opcode === 0xfe &&
(details.includes('invalid opcode: invalid') || details.includes('invalidfeopcode'))
)
return true; // Designated invalid opcode.
if (
details.includes('stack underflow') ||
details.includes('stackunderflow') ||
details.includes('stackoverflow')
) {
return true; // Implies opcode is supported.
}
if (details.includes('not defined')) return false;
if (details.includes('not supported')) return false;
if (details.includes('notactivated')) return false;
if (details.includes('invalid opcode')) return false;
if (details.includes('opcodenotfound')) return false;

console.log(`\n======== Opcode ${opcode} ========`);
console.log('err.details:', err.details);
Expand Down Expand Up @@ -73,6 +94,7 @@ export const knownOpcodes: Record<Opcode, string> = {
0x1b: 'SHL',
0x1c: 'SHR',
0x1d: 'SAR',
0x1e: 'CLZ',
0x20: 'KECCAK256',
0x30: 'ADDRESS',
0x31: 'BALANCE',
Expand Down
12 changes: 7 additions & 5 deletions script/checks/precompiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ import type { Address, Hex, PublicClient } from 'viem';
export async function checkPrecompiles(
client: PublicClient,
): Promise<{ name: string; address: Address; implemented: boolean }[]> {
const result = precompiles.map(async ({ name, address, testCalldata, expectedResponse }) => {
const result = [];

for (const { name, address, testCalldata, expectedResponse } of precompiles) {
try {
const res = await client.call({ to: address, data: testCalldata });
const implemented = res.data === expectedResponse;
return { name, address, implemented };
result.push({ name, address, implemented });
} catch (e) {
// If the call fails, the precompile is not implemented.
return { name, address, implemented: false };
result.push({ name, address, implemented: false });
}
});
return await Promise.all(result);
}
return result;
}

// By default a call to an EOA succeeds and returns no data, therefore we cannot simply use a
Expand Down
3 changes: 2 additions & 1 deletion script/data/chain/1.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
{ "number": "0x1b", "name": "SHL", "supported": true },
{ "number": "0x1c", "name": "SHR", "supported": true },
{ "number": "0x1d", "name": "SAR", "supported": true },
{ "number": "0x1e", "name": "CLZ", "supported": true },
{ "number": "0x20", "name": "KECCAK256", "supported": true },
{ "number": "0x30", "name": "ADDRESS", "supported": true },
{ "number": "0x31", "name": "BALANCE", "supported": true },
Expand Down Expand Up @@ -299,7 +300,7 @@
{
"name": "secp256r1",
"address": "0x0000000000000000000000000000000000000100",
"implemented": false
"implemented": true
}
],
"evmStackAddresses": {
Expand Down
1 change: 1 addition & 0 deletions script/data/chain/10.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
{ "number": "0x1b", "name": "SHL", "supported": true },
{ "number": "0x1c", "name": "SHR", "supported": true },
{ "number": "0x1d", "name": "SAR", "supported": true },
{ "number": "0x1e", "name": "CLZ", "supported": false },
{ "number": "0x20", "name": "KECCAK256", "supported": true },
{ "number": "0x30", "name": "ADDRESS", "supported": true },
{ "number": "0x31", "name": "BALANCE", "supported": true },
Expand Down
3 changes: 2 additions & 1 deletion script/data/chain/137.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
{ "number": "0x1b", "name": "SHL", "supported": true },
{ "number": "0x1c", "name": "SHR", "supported": true },
{ "number": "0x1d", "name": "SAR", "supported": true },
{ "number": "0x1e", "name": "CLZ", "supported": false },
{ "number": "0x20", "name": "KECCAK256", "supported": true },
{ "number": "0x30", "name": "ADDRESS", "supported": true },
{ "number": "0x31", "name": "BALANCE", "supported": true },
Expand Down Expand Up @@ -280,7 +281,7 @@
{
"name": "point evaluation",
"address": "0x000000000000000000000000000000000000000a",
"implemented": false
"implemented": true
},
{
"name": "secp256r1",
Expand Down
8 changes: 7 additions & 1 deletion script/data/chain/34443.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
],
"faucets": [],
"icon": "mode",
"rpc": ["https://mainnet.mode.network", "https://mode.drpc.org", "wss://mode.drpc.org"]
"rpc": [
"https://mainnet.mode.network",
"https://mode.drpc.org",
"wss://mode.drpc.org",
"https://mode-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}"
]
},
"opcodes": [
{ "number": "0x00", "name": "STOP", "supported": true },
Expand Down Expand Up @@ -42,6 +47,7 @@
{ "number": "0x1b", "name": "SHL", "supported": true },
{ "number": "0x1c", "name": "SHR", "supported": true },
{ "number": "0x1d", "name": "SAR", "supported": true },
{ "number": "0x1e", "name": "CLZ", "supported": false },
{ "number": "0x20", "name": "KECCAK256", "supported": true },
{ "number": "0x30", "name": "ADDRESS", "supported": true },
{ "number": "0x31", "name": "BALANCE", "supported": true },
Expand Down
1 change: 1 addition & 0 deletions script/data/chain/42161.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
{ "number": "0x1b", "name": "SHL", "supported": true },
{ "number": "0x1c", "name": "SHR", "supported": true },
{ "number": "0x1d", "name": "SAR", "supported": true },
{ "number": "0x1e", "name": "CLZ", "supported": true },
{ "number": "0x20", "name": "KECCAK256", "supported": true },
{ "number": "0x30", "name": "ADDRESS", "supported": true },
{ "number": "0x31", "name": "BALANCE", "supported": true },
Expand Down
6 changes: 4 additions & 2 deletions script/data/chain/43114.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"wss://avalanche-c-chain-rpc.publicnode.com",
"https://rpc.ankr.com/avalanche",
"https://ava-mainnet.public.blastapi.io/ext/bc/C/rpc",
"https://avalanche-mainnet.infura.io/v3/${INFURA_API_KEY}"
"https://avalanche-mainnet.infura.io/v3/${INFURA_API_KEY}",
"https://avax-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}"
],
"slip44": 9005
},
Expand Down Expand Up @@ -52,6 +53,7 @@
{ "number": "0x1b", "name": "SHL", "supported": true },
{ "number": "0x1c", "name": "SHR", "supported": true },
{ "number": "0x1d", "name": "SAR", "supported": true },
{ "number": "0x1e", "name": "CLZ", "supported": false },
{ "number": "0x20", "name": "KECCAK256", "supported": true },
{ "number": "0x30", "name": "ADDRESS", "supported": true },
{ "number": "0x31", "name": "BALANCE", "supported": true },
Expand Down Expand Up @@ -274,7 +276,7 @@
{
"name": "secp256r1",
"address": "0x0000000000000000000000000000000000000100",
"implemented": false
"implemented": true
}
],
"evmStackAddresses": {
Expand Down
3 changes: 2 additions & 1 deletion script/data/chain/534352.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
{ "number": "0x1b", "name": "SHL", "supported": true },
{ "number": "0x1c", "name": "SHR", "supported": true },
{ "number": "0x1d", "name": "SAR", "supported": true },
{ "number": "0x1e", "name": "CLZ", "supported": true },
{ "number": "0x20", "name": "KECCAK256", "supported": true },
{ "number": "0x30", "name": "ADDRESS", "supported": true },
{ "number": "0x31", "name": "BALANCE", "supported": true },
Expand Down Expand Up @@ -274,7 +275,7 @@
{
"name": "secp256r1",
"address": "0x0000000000000000000000000000000000000100",
"implemented": false
"implemented": true
}
],
"evmStackAddresses": {
Expand Down
17 changes: 9 additions & 8 deletions script/data/chain/59144.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
{ "number": "0x1b", "name": "SHL", "supported": true },
{ "number": "0x1c", "name": "SHR", "supported": true },
{ "number": "0x1d", "name": "SAR", "supported": true },
{ "number": "0x1e", "name": "CLZ", "supported": true },
{ "number": "0x20", "name": "KECCAK256", "supported": true },
{ "number": "0x30", "name": "ADDRESS", "supported": true },
{ "number": "0x31", "name": "BALANCE", "supported": true },
Expand All @@ -94,8 +95,8 @@
{ "number": "0x46", "name": "CHAINID", "supported": true },
{ "number": "0x47", "name": "SELFBALANCE", "supported": true },
{ "number": "0x48", "name": "BASEFEE", "supported": true },
{ "number": "0x49", "name": "BLOBHASH", "supported": false },
{ "number": "0x4a", "name": "BLOBBASEFEE", "supported": false },
{ "number": "0x49", "name": "BLOBHASH", "supported": true },
{ "number": "0x4a", "name": "BLOBBASEFEE", "supported": true },
{ "number": "0x50", "name": "POP", "supported": true },
{ "number": "0x51", "name": "MLOAD", "supported": true },
{ "number": "0x52", "name": "MSTORE", "supported": true },
Expand All @@ -108,10 +109,10 @@
{ "number": "0x59", "name": "MSIZE", "supported": true },
{ "number": "0x5a", "name": "GAS", "supported": true },
{ "number": "0x5b", "name": "JUMPDEST", "supported": true },
{ "number": "0x5c", "name": "TLOAD", "supported": false },
{ "number": "0x5d", "name": "TSTORE", "supported": false },
{ "number": "0x5e", "name": "MCOPY", "supported": false },
{ "number": "0x5f", "name": "PUSH0", "supported": false },
{ "number": "0x5c", "name": "TLOAD", "supported": true },
{ "number": "0x5d", "name": "TSTORE", "supported": true },
{ "number": "0x5e", "name": "MCOPY", "supported": true },
{ "number": "0x5f", "name": "PUSH0", "supported": true },
{ "number": "0x60", "name": "PUSH1", "supported": true },
{ "number": "0x61", "name": "PUSH2", "supported": true },
{ "number": "0x62", "name": "PUSH3", "supported": true },
Expand Down Expand Up @@ -285,12 +286,12 @@
{
"name": "point evaluation",
"address": "0x000000000000000000000000000000000000000a",
"implemented": false
"implemented": true
},
{
"name": "secp256r1",
"address": "0x0000000000000000000000000000000000000100",
"implemented": false
"implemented": true
}
],
"evmStackAddresses": {
Expand Down
1 change: 1 addition & 0 deletions script/data/chain/8453.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
{ "number": "0x1b", "name": "SHL", "supported": true },
{ "number": "0x1c", "name": "SHR", "supported": true },
{ "number": "0x1d", "name": "SAR", "supported": true },
{ "number": "0x1e", "name": "CLZ", "supported": false },
{ "number": "0x20", "name": "KECCAK256", "supported": true },
{ "number": "0x30", "name": "ADDRESS", "supported": true },
{ "number": "0x31", "name": "BALANCE", "supported": true },
Expand Down
10 changes: 8 additions & 2 deletions script/data/feature/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,12 @@
],
"faucets": [],
"icon": "mode",
"rpc": ["https://mainnet.mode.network", "https://mode.drpc.org", "wss://mode.drpc.org"]
"rpc": [
"https://mainnet.mode.network",
"https://mode.drpc.org",
"wss://mode.drpc.org",
"https://mode-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}"
]
},
"42161": {
"name": "Arbitrum One",
Expand Down Expand Up @@ -232,7 +237,8 @@
"wss://avalanche-c-chain-rpc.publicnode.com",
"https://rpc.ankr.com/avalanche",
"https://ava-mainnet.public.blastapi.io/ext/bc/C/rpc",
"https://avalanche-mainnet.infura.io/v3/${INFURA_API_KEY}"
"https://avalanche-mainnet.infura.io/v3/${INFURA_API_KEY}",
"https://avax-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}"
],
"slip44": 9005
},
Expand Down
Loading