// SPDX-License-Identifier: ISC pragma solidity ^0.8.20; // Contracts for scenario 4 (developer-registry abuse, design 4.5): a Worker whose calls spend gas (so a tip is // attributable to its code), and a Factory that deploys Workers via CREATE and CREATE2 and exercises the registry's // register rules, including a same-transaction override by the creator. interface IReg { function register(address account, address payee) external; function payeeOf(address account) external view returns (address); function creatorOf(address account) external view returns (address); } contract Worker { uint256 public acc; function work(uint256 n) external returns (uint256) { for (uint256 i = 0; i < n; i++) acc += i + 1; return acc; } } contract Factory { address constant REG = 0x0000000000000000000000000000000000000210; event Created(address child); // The factory registers itself (allowed: msg.sender == account). function registerSelf(address payee) external { IReg(REG).register(address(this), payee); } // CREATE: child inherits the factory's payee by the executor's rule. function createChild() external returns (address c) { c = address(new Worker()); emit Created(c); } // CREATE2: same inheritance. function createChild2(bytes32 salt) external returns (address c) { c = address(new Worker{salt: salt}()); emit Created(c); } // The creating transaction overrides the child's payee in the same tx (allowed: factory is the recorded creator). function createAndOverride(address payee) external returns (address c) { c = address(new Worker()); IReg(REG).register(c, payee); emit Created(c); } }