// Compiles the attack contracts with solc-js and writes contracts/*.json (abi + creation bytecode). import solc from 'solc'; import { readFileSync, writeFileSync } from 'node:fs'; import { fileURLToPath } from 'node:url'; import path from 'node:path'; const here = path.dirname(fileURLToPath(import.meta.url)); const input = { language: 'Solidity', sources: { 'PgasBomb.sol': { content: readFileSync(path.join(here, 'contracts/PgasBomb.sol'), 'utf8') }, 'RegistryAbuse.sol': { content: readFileSync(path.join(here, 'contracts/RegistryAbuse.sol'), 'utf8') }, }, settings: { optimizer: { enabled: true, runs: 200 }, evmVersion: 'cancun', outputSelection: { '*': { '*': ['abi', 'evm.bytecode.object'] } } }, }; const out = JSON.parse(solc.compile(JSON.stringify(input))); for (const e of out.errors ?? []) { if (e.severity === 'error') { console.error(e.formattedMessage); process.exit(1); } } const write = (file, srcFile, name) => { const c = out.contracts[srcFile][name]; writeFileSync(path.join(here, 'contracts', file), JSON.stringify({ abi: c.abi, bytecode: '0x' + c.evm.bytecode.object }, null, 1) + '\n'); console.log(file, 'creation bytes', c.evm.bytecode.object.length / 2); }; write('PgasBomb.json', 'PgasBomb.sol', 'PgasBomb'); write('Worker.json', 'RegistryAbuse.sol', 'Worker'); write('Factory.json', 'RegistryAbuse.sol', 'Factory'); console.log('solc', solc.version());