Skip to content

Commit 2a9ae0b

Browse files
authored
Merge branch 'main' into Docs_linea_fixes
2 parents bd7801f + 972cc85 commit 2a9ae0b

File tree

129 files changed

+10606
-586
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+10606
-586
lines changed

.github/workflows/codeql.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ on:
1818
# '!**.md' will not work by itself to exclude *.md files. See https://github.com/orgs/community/discussions/25369
1919
- '**'
2020
- '!**.md'
21+
- '!**.mdx'
22+
- '!**/docs/**'
23+
- '!docs/**'
2124

2225
jobs:
2326
analyze:

.github/workflows/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ jobs:
122122
filters: |
123123
has-changes-requiring-build:
124124
- '!**/*.md'
125+
- '!**/*.mdx'
126+
- '!**/docs/**'
125127
- '!docs/**'
126128
# Enables us to exclude changes in multiple file types if required
127129
predicate-quantifier: 'every'

.github/workflows/run-smc-tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ on:
77
- 'testdata/**'
88
- 'prover/**'
99
- '!contracts/**/*.md'
10+
- '!contracts/**/*.mdx'
1011
- '!testdata/**/*.md'
1112
- '!prover/**/*.md'
13+
- '!**/docs/**'
1214
push:
1315
branches:
1416
- main
@@ -17,8 +19,10 @@ on:
1719
- 'testdata/**'
1820
- 'prover/**'
1921
- '!contracts/**/*.md'
22+
- '!contracts/**/*.mdx'
2023
- '!testdata/**/*.md'
2124
- '!prover/**/*.md'
25+
- '!**/docs/**'
2226

2327
env:
2428
GOPROXY: "https://proxy.golang.org"

.husky/pre-commit

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
# Run `npx husky` in root directory to initialize this pre-commit hook for local machine
4+
5+
# Execute NodeJS script because
6+
# i.) Husky requires NodeJS -> fair assumption that machine will have NodeJS
7+
# ii.) Cleaner syntax and abstractions than shell scripting
8+
node .husky/pre-commit.js
9+
10+
exit 0

.husky/pre-commit.js

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
/**
2+
* Runs as git pre-commit hook
3+
* Filters the list of changed files on 'git commit'
4+
* If *.ts files in specified projects are detected, runs the 'lint:ts:fix' package.json script for that project
5+
* E.g. if a *.ts file is changed in /sdk, then this script will run 'pnpm run lint:ts:fix' in the /sdk project
6+
*/
7+
8+
const fs = require('fs');
9+
const { execSync } = require('child_process');
10+
11+
/**
12+
* ENUMS
13+
*/
14+
15+
// File extensions to filter for
16+
const FILE_EXTENSION = {
17+
TYPESCRIPT: "TYPESCRIPT",
18+
SOLIDITY: "SOLIDITY",
19+
}
20+
21+
// Projects to filter for
22+
const FOLDER = {
23+
BRIDGEUI: "BRIDGEUI",
24+
CONTRACTS: "CONTRACTS",
25+
E2E: "E2E",
26+
OPERATIONS: "OPERATIONS",
27+
POSTMAN: "POSTMAN",
28+
SDK: "SDK",
29+
}
30+
31+
// Project runtimes
32+
const RUNTIME = {
33+
NODEJS: "NODEJS"
34+
}
35+
36+
/**
37+
* MAPPINGS
38+
*/
39+
40+
// File extension => regex
41+
const FILE_EXTENSION_FILTERS = {
42+
[FILE_EXTENSION.TYPESCRIPT]: "\.ts$",
43+
[FILE_EXTENSION.SOLIDITY]: "\.sol$",
44+
};
45+
46+
// File extension => script in package.json to run
47+
const FILE_EXTENSION_LINTING_COMMAND = {
48+
[FILE_EXTENSION.TYPESCRIPT]: "pnpm run lint:ts:fix",
49+
[FILE_EXTENSION.SOLIDITY]: "pnpm run lint:sol:fix",
50+
};
51+
52+
// Project => Path in monorepo
53+
const FOLDER_PATH = {
54+
[FOLDER.BRIDGEUI]: "bridge-ui/",
55+
[FOLDER.CONTRACTS]: "contracts/",
56+
[FOLDER.E2E]: "e2e/",
57+
[FOLDER.OPERATIONS]: "operations/",
58+
[FOLDER.POSTMAN]: "postman/",
59+
[FOLDER.SDK]: "sdk/",
60+
};
61+
62+
// Project => List of changed files
63+
const FOLDER_CHANGED_FILES = {
64+
[FOLDER.BRIDGEUI]: new Array(),
65+
[FOLDER.CONTRACTS]: new Array(),
66+
[FOLDER.E2E]: new Array(),
67+
[FOLDER.OPERATIONS]: new Array(),
68+
[FOLDER.POSTMAN]: new Array(),
69+
[FOLDER.SDK]: new Array(),
70+
};
71+
72+
// Project => Runtime
73+
const FOLDER_RUNTIME = {
74+
[FOLDER.BRIDGEUI]: RUNTIME.NODEJS,
75+
[FOLDER.CONTRACTS]: RUNTIME.NODEJS,
76+
[FOLDER.E2E]: RUNTIME.NODEJS,
77+
[FOLDER.OPERATIONS]: RUNTIME.NODEJS,
78+
[FOLDER.POSTMAN]: RUNTIME.NODEJS,
79+
[FOLDER.SDK]: RUNTIME.NODEJS,
80+
};
81+
82+
/**
83+
* MAIN FUNCTION
84+
*/
85+
86+
main();
87+
88+
function main() {
89+
const changedFileList = getChangedFileList();
90+
partitionChangedFileList(changedFileList);
91+
92+
for (const folder in FOLDER) {
93+
if (!isDependenciesInstalled(folder)) {
94+
console.error(`Dependencies not installed in ${FOLDER_PATH[folder]}, exiting...`)
95+
process.exit(1);
96+
}
97+
const changedFileExtensions = getChangedFileExtensions(folder);
98+
executeLinting(folder, changedFileExtensions);
99+
}
100+
101+
updateGitIndex();
102+
}
103+
104+
/**
105+
* HELPER FUNCTIONS
106+
*/
107+
108+
/**
109+
* Gets a list of changed files in the git commit
110+
* @returns {string[]}
111+
*/
112+
function getChangedFileList() {
113+
try {
114+
const cmd = 'git diff --name-only HEAD'
115+
const stdout = execSync(cmd, { encoding: 'utf8' });
116+
return stdout.split('\n').filter(file => file.trim() !== '');
117+
} catch (error) {
118+
console.error($`Error running ${cmd}:`, error.message);
119+
process.exit(1)
120+
}
121+
}
122+
123+
/**
124+
* Partitions list of changed files from getChangedFileList() by project
125+
* Stores results in FOLDER_CHANGED_FILES
126+
* @param {string[]}
127+
*/
128+
function partitionChangedFileList(_changedFileList) {
129+
for (const file of _changedFileList) {
130+
for (const path in FOLDER) {
131+
if (file.match(new RegExp(`^${FOLDER_PATH[path]}`))) {
132+
FOLDER_CHANGED_FILES[path].push(file);
133+
}
134+
}
135+
}
136+
}
137+
138+
/**
139+
* Checks if runtime dependencies are installed for a project
140+
* @param {FOLDER}
141+
* @returns {boolean}
142+
*/
143+
function isDependenciesInstalled(_folder) {
144+
const runtime = FOLDER_RUNTIME[_folder];
145+
const path = FOLDER_PATH[_folder];
146+
147+
switch(runtime) {
148+
case RUNTIME.NODEJS:
149+
const dependencyFolder = `${path}node_modules`
150+
return fs.existsSync(dependencyFolder)
151+
default:
152+
console.error(`${runtime} runtime not supported.`);
153+
return false
154+
}
155+
}
156+
157+
/**
158+
* Resolve list of changed file extensions for a project
159+
* @param {FOLDER}
160+
* @returns {FILE_EXTENSION[]}
161+
*/
162+
function getChangedFileExtensions(_folder) {
163+
// Use sets to implement early exit from loop, once we have matched all configured file extensions
164+
const remainingFileExtensionsSet = new Set(Object.values(FILE_EXTENSION));
165+
const foundFileExtensionsSet = new Set();
166+
167+
for (const file of FOLDER_CHANGED_FILES[_folder]) {
168+
for (const fileExtension of remainingFileExtensionsSet) {
169+
if (file.match(new RegExp(FILE_EXTENSION_FILTERS[fileExtension]))) {
170+
foundFileExtensionsSet.add(fileExtension);
171+
remainingFileExtensionsSet.delete(fileExtension);
172+
}
173+
}
174+
175+
// No more remaining file extensions to look for
176+
if (remainingFileExtensionsSet.size == 0) break;
177+
}
178+
179+
return Array.from(foundFileExtensionsSet);
180+
}
181+
182+
/**
183+
* Execute linting command
184+
* @param {FOLDER, FILE_EXTENSION[]}
185+
*/
186+
function executeLinting(_folder, _changedFileExtensions) {
187+
for (const fileExtension of _changedFileExtensions) {
188+
const path = FOLDER_PATH[_folder];
189+
const cmd = FILE_EXTENSION_LINTING_COMMAND[fileExtension];
190+
console.log(`${fileExtension} change found in ${path}, linting...`);
191+
try {
192+
// Execute command synchronously and stream output directly to the current stdout
193+
execSync(`
194+
cd ${path};
195+
${cmd};
196+
`, { stdio: 'inherit' });
197+
} catch (error) {
198+
console.error(`Error:`, error.message);
199+
console.error(`Exiting...`);
200+
process.exit(1);
201+
}
202+
}
203+
}
204+
205+
/**
206+
* Redo `git add` for files updated during executeLinting(), so that they are not left out of the commit
207+
* The difference between 'git add .' and 'git update-index --again', is that the latter will not include untracked files
208+
*/
209+
function updateGitIndex() {
210+
try {
211+
const cmd = 'git update-index --again'
212+
execSync(cmd, { stdio: 'inherit' });
213+
} catch (error) {
214+
console.error($`Error running ${cmd}:`, error.message);
215+
process.exit(1);
216+
}
217+
}

bridge-ui/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"build": "next build",
99
"start": "next start",
1010
"lint": "next lint",
11-
"lint:fix": "next lint --fix",
11+
"lint:fix": "pnpm run lint:ts:fix",
12+
"lint:ts:fix": "next lint --fix",
1213
"clean": "rimraf node_modules .next .next-env.d.ts",
1314
"install:playwright": "playwright install --with-deps",
1415
"build:cache": "synpress",

contracts/contracts/lib/SparseMerkleProof.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ library SparseMerkleProof {
7979
/**
8080
* @notice Hash a value using MIMC hash
8181
* @param _input Value to hash
82-
* @return {bytes32} Mimc hash
82+
* @return bytes32 Mimc hash
8383
*/
8484
function mimcHash(bytes calldata _input) external pure returns (bytes32) {
8585
return Mimc.hash(_input);
@@ -106,7 +106,7 @@ library SparseMerkleProof {
106106
/**
107107
* @notice Hash account value
108108
* @param _value Encoded account value bytes (nonce, balance, storageRoot, mimcCodeHash, keccakCodeHash, codeSize)
109-
* @return {bytes32} Account value hash
109+
* @return bytes32 Account value hash
110110
*/
111111
function hashAccountValue(bytes calldata _value) external pure returns (bytes32) {
112112
Account memory account = _parseAccount(_value);
@@ -128,7 +128,7 @@ library SparseMerkleProof {
128128
/**
129129
* @notice Hash storage value
130130
* @param _value Encoded storage value bytes
131-
* @return {bytes32} Storage value hash
131+
* @return bytes32 Storage value hash
132132
*/
133133
function hashStorageValue(bytes32 _value) external pure returns (bytes32) {
134134
(bytes32 msb, bytes32 lsb) = _splitBytes32(_value);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// SPDX-License-Identifier: AGPL-3.0
2+
pragma solidity 0.8.19;
3+
4+
/// @dev Not intended for mainnet or testnet deployment, only for local testing
5+
contract OpcodeTestContract {
6+
/// @dev erc7201:opcodeTestContract.main
7+
struct MainStorage {
8+
uint256 gasLimit;
9+
}
10+
11+
// keccak256(abi.encode(uint256(keccak256("opcodeTestContract.main")) - 1)) & ~bytes32(uint256(0xff))
12+
bytes32 private constant MAIN_STORAGE_SLOT =
13+
0xb69ece048aea1886497badfc9449787df15ad9606ca8687d17308088ee555100;
14+
15+
function _getMainStorage() private pure returns (MainStorage storage $) {
16+
assembly {
17+
$.slot := MAIN_STORAGE_SLOT
18+
}
19+
}
20+
21+
function getGasLimit() external view returns (uint256) {
22+
MainStorage storage $ = _getMainStorage();
23+
return $.gasLimit;
24+
}
25+
26+
function setGasLimit() external {
27+
uint256 gasLimit;
28+
assembly {
29+
gasLimit := gaslimit()
30+
}
31+
MainStorage storage $ = _getMainStorage();
32+
$.gasLimit = gasLimit;
33+
}
34+
}

contracts/docs/api/LineaRollup.md renamed to contracts/docs/api/LineaRollup.mdx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# Solidity API
2-
3-
## LineaRollup
1+
# `LineaRollup`
42

53
### CONTRACT_VERSION
64

contracts/docs/api/ZkEvmV2.md renamed to contracts/docs/api/ZkEvmV2.mdx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# Solidity API
2-
3-
## ZkEvmV2
1+
# `ZkEvmV2`
42

53
### MODULO_R
64

contracts/docs/api/interfaces/IGenericErrors.md renamed to contracts/docs/api/interfaces/IGenericErrors.mdx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# Solidity API
2-
3-
## IGenericErrors
1+
# `IGenericErrors`
42

53
### ZeroAddressNotAllowed
64

contracts/docs/api/interfaces/IMessageService.md renamed to contracts/docs/api/interfaces/IMessageService.mdx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# Solidity API
2-
3-
## IMessageService
1+
# `IMessageService`
42

53
### MessageSent
64

contracts/docs/api/interfaces/IPauseManager.md renamed to contracts/docs/api/interfaces/IPauseManager.mdx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# Solidity API
2-
3-
## IPauseManager
1+
# `IPauseManager`
42

53
### PauseTypeRole
64

contracts/docs/api/interfaces/IPermissionsManager.md renamed to contracts/docs/api/interfaces/IPermissionsManager.mdx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# Solidity API
2-
3-
## IPermissionsManager
1+
# `IPermissionsManager`
42

53
### RoleAddress
64

contracts/docs/api/interfaces/IRateLimiter.md renamed to contracts/docs/api/interfaces/IRateLimiter.mdx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# Solidity API
2-
3-
## IRateLimiter
1+
# `IRateLimiter`
42

53
### RateLimitInitialized
64

0 commit comments

Comments
 (0)