Skip to content

Commit

Permalink
Prepare for release of v0.8.3 (#72)
Browse files Browse the repository at this point in the history
* Add funding JSON file for RetroPGF

* Improve foundry setup (#67)

* chore: Remove dependencies

* chore: Add foundry.toml

* forge install: forge-std

v1.7.6

* chore: Remove remappings

* chore: Add .nvmrc

* chore: Add test workflow

* chore: Setup foundry in github workflow

* fix: Include recursive submodules in github workflow

* Deleting GitHub workflow from the PR because of safety concerns. Accepting all other changes.

---------

Co-authored-by: Gonçalo Sá <[email protected]>

* Remove non-aligned equality function to address concerns in #69

---------

Co-authored-by: Ján Jakub Naništa <[email protected]>
  • Loading branch information
GNSPS and janjakubnanista authored Feb 6, 2025
1 parent c433288 commit bb249f6
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 99 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18.16.0
66 changes: 0 additions & 66 deletions contracts/BytesLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -436,72 +436,6 @@ library BytesLib {
return success;
}

function equal_nonAligned(bytes memory _preBytes, bytes memory _postBytes) internal pure returns (bool) {
bool success = true;

assembly {
let length := mload(_preBytes)

// if lengths don't match the arrays are not equal
switch eq(length, mload(_postBytes))
case 1 {
// cb is a circuit breaker in the for loop since there's
// no said feature for inline assembly loops
// cb = 1 - don't breaker
// cb = 0 - break
let cb := 1

let endMinusWord := add(_preBytes, length)
let mc := add(_preBytes, 0x20)
let cc := add(_postBytes, 0x20)

for {
// the next line is the loop condition:
// while(uint256(mc < endWord) + cb == 2)
} eq(add(lt(mc, endMinusWord), cb), 2) {
mc := add(mc, 0x20)
cc := add(cc, 0x20)
} {
// if any of these checks fails then arrays are not equal
if iszero(eq(mload(mc), mload(cc))) {
// unsuccess:
success := 0
cb := 0
}
}

// Only if still successful
// For <1 word tail bytes
if gt(success, 0) {
// Get the remainder of length/32
// length % 32 = AND(length, 32 - 1)
let numTailBytes := and(length, 0x1f)
let mcRem := mload(mc)
let ccRem := mload(cc)
for {
let i := 0
// the next line is the loop condition:
// while(uint256(i < numTailBytes) + cb == 2)
} eq(add(lt(i, numTailBytes), cb), 2) {
i := add(i, 1)
} {
if iszero(eq(byte(i, mcRem), byte(i, ccRem))) {
// unsuccess:
success := 0
cb := 0
}
}
}
}
default {
// unsuccess:
success := 0
}
}

return success;
}

function equalStorage(
bytes storage _preBytes,
bytes memory _postBytes
Expand Down
6 changes: 6 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[profile.default]
solc-version = '0.8.22'
src = 'contracts'
test = 'test'
cache_path = 'cache'
libs = ['lib']
1 change: 1 addition & 0 deletions lib/forge-std
Submodule forge-std added at ae570f
27 changes: 1 addition & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@
"authors": [
"Gonçalo Sá <[email protected]>"
],
"scripts": {
"test": "forge test"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/GNSPS/solidity-bytes-utils/issues"
},
"homepage": "https://github.com/GNSPS/solidity-bytes-utils#readme",
"dependencies": {
"ds-test": "github:dapphub/ds-test",
"forge-std": "^1.1.2"
}
"homepage": "https://github.com/GNSPS/solidity-bytes-utils#readme"
}
2 changes: 0 additions & 2 deletions remappings.txt

This file was deleted.

0 comments on commit bb249f6

Please sign in to comment.