Skip to content

Commit 0fbdb1c

Browse files
Stabilize contracts dependency CI
1 parent f45bfb5 commit 0fbdb1c

3 files changed

Lines changed: 75 additions & 79 deletions

File tree

contracts/hardhat.config.ts

Lines changed: 63 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,62 @@ const ALLOW_UNLIMITED_CONTRACT_SIZE =
6060
const DEVNET_RPC_URL = process.env.DEVNET_RPC_URL ||
6161
"http://localhost:8545";
6262

63+
const DEFAULT_SOLIDITY_COMPILER = {
64+
version: "0.8.20",
65+
settings: {
66+
optimizer: {
67+
enabled: true,
68+
runs: 200, // Optimized for frequent function calls
69+
details: {
70+
yul: true,
71+
yulDetails: {
72+
stackAllocation: true,
73+
},
74+
},
75+
},
76+
viaIR: true, // Preserve IR-based code generation in every build profile.
77+
evmVersion: "paris",
78+
metadata: {
79+
bytecodeHash: "ipfs",
80+
useLiteralContent: true,
81+
},
82+
},
83+
};
84+
85+
const SIZE_OPTIMIZED_SOLIDITY_COMPILER = {
86+
version: "0.8.20",
87+
settings: {
88+
optimizer: {
89+
enabled: true,
90+
runs: 1,
91+
details: {
92+
yul: true,
93+
yulDetails: {
94+
stackAllocation: true,
95+
},
96+
},
97+
},
98+
viaIR: true,
99+
evmVersion: "paris",
100+
metadata: {
101+
bytecodeHash: "none",
102+
useLiteralContent: false,
103+
appendCBOR: false,
104+
},
105+
},
106+
};
107+
108+
const SIZE_OPTIMIZED_SOLIDITY_OVERRIDES = {
109+
// Size-optimized override for the institutional bridge to stay under EIP-170
110+
// without altering runtime behavior or ABI.
111+
"contracts/InstitutionalStablecoinBridge.sol": SIZE_OPTIMIZED_SOLIDITY_COMPILER,
112+
// Size-optimized override for Cruzible to stay under EIP-170 without
113+
// changing runtime behavior or ABI. This contract concentrates multiple
114+
// staking and attestation flows, so we optimize deployment size rather
115+
// than risk a late-stage logic split.
116+
"contracts/vault/Cruzible.sol": SIZE_OPTIMIZED_SOLIDITY_COMPILER,
117+
};
118+
63119
// ============================================================================
64120
// Hardhat Configuration
65121
// ============================================================================
@@ -79,79 +135,14 @@ const config = defineConfig({
79135
"@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol",
80136
"@openzeppelin/contracts/governance/TimelockController.sol",
81137
],
82-
compilers: [
83-
{
84-
version: "0.8.20",
85-
settings: {
86-
optimizer: {
87-
enabled: true,
88-
runs: 200, // Optimized for frequent function calls
89-
details: {
90-
yul: true,
91-
yulDetails: {
92-
stackAllocation: true,
93-
},
94-
},
95-
},
96-
viaIR: true, // Enable IR-based code generation for better optimization
97-
evmVersion: "paris", // Latest stable EVM version
98-
metadata: {
99-
bytecodeHash: "ipfs", // Use IPFS for metadata hash
100-
useLiteralContent: true,
101-
},
102-
},
103-
},
104-
],
105-
overrides: {
106-
// Size-optimized override for the institutional bridge to stay under EIP-170
107-
// without altering runtime behavior or ABI.
108-
"contracts/InstitutionalStablecoinBridge.sol": {
109-
version: "0.8.20",
110-
settings: {
111-
optimizer: {
112-
enabled: true,
113-
runs: 1,
114-
details: {
115-
yul: true,
116-
yulDetails: {
117-
stackAllocation: true,
118-
},
119-
},
120-
},
121-
viaIR: true,
122-
evmVersion: "paris",
123-
metadata: {
124-
bytecodeHash: "none",
125-
useLiteralContent: false,
126-
appendCBOR: false,
127-
},
128-
},
138+
profiles: {
139+
default: {
140+
compilers: [DEFAULT_SOLIDITY_COMPILER],
141+
overrides: SIZE_OPTIMIZED_SOLIDITY_OVERRIDES,
129142
},
130-
// Size-optimized override for Cruzible to stay under EIP-170 without
131-
// changing runtime behavior or ABI. This contract concentrates multiple
132-
// staking and attestation flows, so we optimize deployment size rather
133-
// than risk a late-stage logic split.
134-
"contracts/vault/Cruzible.sol": {
135-
version: "0.8.20",
136-
settings: {
137-
optimizer: {
138-
enabled: true,
139-
runs: 1,
140-
details: {
141-
yul: true,
142-
yulDetails: {
143-
stackAllocation: true,
144-
},
145-
},
146-
},
147-
viaIR: true,
148-
evmVersion: "paris",
149-
metadata: {
150-
bytecodeHash: "none",
151-
useLiteralContent: false,
152-
appendCBOR: false,
153-
},
154-
},
143+
production: {
144+
compilers: [DEFAULT_SOLIDITY_COMPILER],
145+
overrides: SIZE_OPTIMIZED_SOLIDITY_OVERRIDES,
155146
},
156147
},
157148
},

contracts/package.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@
1111
},
1212
"scripts": {
1313
"compile": "hardhat build",
14-
"test": "ALLOW_UNLIMITED_CONTRACT_SIZE=true hardhat test",
15-
"test:coverage": "ALLOW_UNLIMITED_CONTRACT_SIZE=true hardhat test --coverage",
16-
"test:gas": "ALLOW_UNLIMITED_CONTRACT_SIZE=true REPORT_GAS=true hardhat test",
14+
"test": "npm run test:hardhat",
15+
"test:hardhat": "ALLOW_UNLIMITED_CONTRACT_SIZE=true hardhat test mocha test/*.test.ts",
16+
"test:solidity": "ALLOW_UNLIMITED_CONTRACT_SIZE=true hardhat test solidity",
17+
"test:all": "ALLOW_UNLIMITED_CONTRACT_SIZE=true hardhat test",
18+
"test:coverage": "ALLOW_UNLIMITED_CONTRACT_SIZE=true hardhat --coverage test mocha test/*.test.ts",
19+
"test:gas": "ALLOW_UNLIMITED_CONTRACT_SIZE=true REPORT_GAS=true hardhat --gas-stats test mocha test/*.test.ts",
1720
"deploy:devnet": "hardhat run scripts/deploy.ts --network devnet",
1821
"deploy:sepolia": "hardhat run scripts/deploy.ts --network sepolia",
1922
"deploy:mainnet": "hardhat run scripts/deploy.ts --network mainnet",
@@ -26,8 +29,8 @@
2629
"lint:fix": "solhint 'contracts/**/*.sol' --fix",
2730
"format": "prettier --write 'contracts/**/*.sol' 'scripts/**/*.ts' 'test/**/*.ts'",
2831
"clean": "hardhat clean",
29-
"size": "hardhat build --build-profile production --force && node scripts/check-contract-size.js",
30-
"size:check": "hardhat build --build-profile production --force && node scripts/check-contract-size.js",
32+
"size": "hardhat build --build-profile production --force --no-tests --no-typechain && node scripts/check-contract-size.js",
33+
"size:check": "hardhat build --build-profile production --force --no-tests --no-typechain && node scripts/check-contract-size.js",
3134
"slither": "slither . --config-file slither.config.json",
3235
"mythril": "myth analyze contracts/AethelredBridge.sol --solc-json mythril.config.json",
3336
"docgen": "node -e \"console.log('Contract doc generation now lives in the dedicated contracts repository release process.')\""

contracts/scripts/check-contract-size.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
/* eslint-disable no-console */
2-
const fs = require("fs");
3-
const path = require("path");
2+
import fs from "node:fs";
3+
import path from "node:path";
4+
import { fileURLToPath } from "node:url";
45

56
const CONTRACT_SOURCE = process.env.CONTRACT_SOURCE || "InstitutionalStablecoinBridge.sol";
67
const CONTRACT_NAME = process.env.CONTRACT_NAME || "InstitutionalStablecoinBridge";
78
const MAX_DEPLOYED_CODE_BYTES = Number(process.env.MAX_DEPLOYED_CODE_BYTES || "24576");
9+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
810

911
function hexByteLen(hex) {
1012
if (!hex || hex === "0x") return 0;

0 commit comments

Comments
 (0)