Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IMT optimization #154

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
c2eae4f
remove length check to avoid storage read
NouDaimon Oct 23, 2022
4a35971
add natspec
NouDaimon Oct 23, 2022
5dcf49a
store IMT hashes via assembly
ItsNickBarry Oct 23, 2022
4c5850b
rename rowSize to rowLength, modify lt comparison for clarity
ItsNickBarry Oct 23, 2022
af581c5
remove rootIndex variable
ItsNickBarry Oct 23, 2022
045c652
optimize rowLength calculation
ItsNickBarry Oct 23, 2022
dfebf46
optimize IMT size function
ItsNickBarry Oct 23, 2022
cc90a1d
wrap contents of IMT pop function in unchecked block
ItsNickBarry Oct 24, 2022
ba217cd
remove unused unchecked block
ItsNickBarry Oct 24, 2022
3fdae95
do not recalculate hashes if layer is removed on pop
ItsNickBarry Oct 24, 2022
bff831e
emphasize prallel structure of push and pop functions
ItsNickBarry Oct 24, 2022
761ce87
optimize recursive row length calculation
ItsNickBarry Oct 24, 2022
24b4834
replace lt with not eq comparison
ItsNickBarry Oct 24, 2022
886ba4b
add additional at function revert test
ItsNickBarry Oct 24, 2022
e3116c3
use assembly for height and root functions
ItsNickBarry Oct 24, 2022
511153c
circumvent all Solididity safety features for underlying IMT arrays
ItsNickBarry Oct 24, 2022
ad3f47d
wrap root functionality in assembly block
NouDaimon Oct 24, 2022
d455bb9
remove unrequired mstore operation
NouDaimon Oct 24, 2022
d9c9175
Merge branch 'master' into IMT-optimization
ItsNickBarry Nov 3, 2022
e8d8ebc
Merge branch 'IMT-optimization' into IMT-optimization-extreme
ItsNickBarry Nov 3, 2022
ea628a8
Merge branch 'master' into IMT-optimization
ItsNickBarry Dec 1, 2022
ba3c5ba
Merge branch 'IMT-optimization' into IMT-optimization-extreme
ItsNickBarry Dec 1, 2022
5340f02
Merge branch 'master' into IMT-optimization
ItsNickBarry Dec 14, 2022
a594007
Merge branch 'IMT-optimization' into IMT-optimization-extreme
ItsNickBarry Dec 14, 2022
4f204a3
Merge branch 'master' into IMT-optimization
ItsNickBarry Apr 17, 2023
610d22b
Merge branch 'IMT-optimization' into IMT-optimization-extreme
ItsNickBarry Apr 17, 2023
9ddd1fd
Merge branch 'master' into IMT-optimization
ItsNickBarry Feb 22, 2025
0e2d727
Merge branch 'IMT-optimization' into IMT-optimization-extreme
ItsNickBarry Feb 22, 2025
b0adf4d
Merge branch 'master' into IMT-optimization
ItsNickBarry Feb 24, 2025
6535209
Merge branch 'IMT-optimization' into IMT-optimization-extreme
ItsNickBarry Feb 24, 2025
ece54c2
Merge branch 'master' into IMT-optimization
ItsNickBarry Mar 22, 2025
9131b4f
Merge branch 'IMT-optimization' into IMT-optimization-extreme
ItsNickBarry Mar 22, 2025
1dedd3b
add comments explaining some IMT assembly blocks
ItsNickBarry Mar 22, 2025
fbc5115
panic via assembly rather than inline invalid array indexing
ItsNickBarry Mar 22, 2025
4f1e391
Merge pull request #155 from solidstate-network/IMT-optimization-extreme
ItsNickBarry Mar 22, 2025
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
Prev Previous commit
Next Next commit
remove rootIndex variable
ItsNickBarry committed Oct 23, 2022
commit af581c571da7d45f97f0d233bc0cdaf787f404b4
15 changes: 3 additions & 12 deletions contracts/data/IncrementalMerkleTree.sol
Original file line number Diff line number Diff line change
@@ -128,7 +128,7 @@ library IncrementalMerkleTree {
bytes32 hash
) internal {
unchecked {
_set(t.nodes, 0, index, t.height() - 1, t.size(), hash);
_set(t.nodes, 0, index, t.size(), hash);
}
}

@@ -137,15 +137,13 @@ library IncrementalMerkleTree {
* @param nodes internal tree structure storage reference
* @param rowIndex index of current row to update
* @param colIndex index of current column to update
* @param rootIndex index of root row
* @param rowLength length of row at rowIndex
* @param hash hash to store at current position
*/
function _set(
bytes32[][] storage nodes,
uint256 rowIndex,
uint256 colIndex,
uint256 rootIndex,
uint256 rowLength,
bytes32 hash
) private {
@@ -158,7 +156,7 @@ library IncrementalMerkleTree {
sstore(add(keccak256(0x00, 0x20), colIndex), hash)
}

if (rowIndex == rootIndex) return;
if (rowLength == 1) return;

unchecked {
if (colIndex & 1 == 1) {
@@ -188,14 +186,7 @@ library IncrementalMerkleTree {
rowLength = rowLength % 2 == 0
? rowLength >> 1
: (rowLength >> 1) + 1;
_set(
nodes,
rowIndex + 1,
colIndex >> 1,
rootIndex,
rowLength,
hash
);
_set(nodes, rowIndex + 1, colIndex >> 1, rowLength, hash);
}
}
}