Skip to content

Commit

Permalink
Generic transaction decompressor (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
Agusx1211 authored Feb 8, 2024
1 parent e0c5382 commit 51d8c32
Show file tree
Hide file tree
Showing 25 changed files with 5,443 additions and 7 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,22 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

huff-tests:
name: Huff tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Install Huff
uses: huff-language/huff-toolchain@v2
with:
version: nightly

- name: Run tests
run: bash ./run_huff_tests.sh

foundry-tests:
name: Foundry tests
runs-on: ubuntu-latest
Expand All @@ -131,6 +147,11 @@ jobs:
with:
version: nightly

- name: Install Huff
uses: huff-language/huff-toolchain@v2
with:
version: nightly

- name: Run tests
run: FOUNDRY_FUZZ_RUNS=2048 MAX_ARRAY_LEN=32 forge test -vvv

Expand All @@ -147,5 +168,10 @@ jobs:
with:
version: nightly

- name: Install Huff
uses: huff-language/huff-toolchain@v2
with:
version: nightly

- name: Run tests
run: FOUNDRY_FUZZ_RUNS=1024 forge test -vvv
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/foundry-huff"]
path = lib/foundry-huff
url = https://github.com/huff-language/foundry-huff
14 changes: 7 additions & 7 deletions contracts/modules/commons/submodules/auth/SequenceBaseSig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import "../../../../utils/LibOptim.sol";
library SequenceBaseSig {
using LibBytesPointer for bytes;

uint256 private constant FLAG_SIGNATURE = 0;
uint256 private constant FLAG_ADDRESS = 1;
uint256 private constant FLAG_DYNAMIC_SIGNATURE = 2;
uint256 private constant FLAG_NODE = 3;
uint256 private constant FLAG_BRANCH = 4;
uint256 private constant FLAG_SUBDIGEST = 5;
uint256 private constant FLAG_NESTED = 6;
uint256 internal constant FLAG_SIGNATURE = 0;
uint256 internal constant FLAG_ADDRESS = 1;
uint256 internal constant FLAG_DYNAMIC_SIGNATURE = 2;
uint256 internal constant FLAG_NODE = 3;
uint256 internal constant FLAG_BRANCH = 4;
uint256 internal constant FLAG_SUBDIGEST = 5;
uint256 internal constant FLAG_NESTED = 6;

error InvalidNestedSignature(bytes32 _hash, address _addr, bytes _signature);
error InvalidSignatureFlag(uint256 _flag);
Expand Down
7 changes: 7 additions & 0 deletions contracts/modules/commons/submodules/nonce/SubModuleNonce.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,11 @@ library SubModuleNonce {
_nonce = uint256(bytes32(_rawNonce) & NONCE_MASK);
}
}

function encodeNonce(uint256 _space, uint256 _nonce) internal pure returns (uint256) {
unchecked {
// Combine space and nonce
return (_space << NONCE_BITS) | _nonce;
}
}
}
23 changes: 23 additions & 0 deletions contracts/utils/LibBytes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,27 @@ library LibBytes {
a := shr(224, word)
}
}

function readMBytes4(
bytes memory data,
uint256 index
) internal pure returns (
bytes4 a
) {
assembly {
let word := mload(add(add(data, 0x20), index))
a := and(word, 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000)
}
}

function readMBytes32(
bytes memory data,
uint256 index
) internal pure returns (
bytes32 a
) {
assembly {
a := mload(add(add(data, 0x20), index))
}
}
}
44 changes: 44 additions & 0 deletions contracts/utils/LibBytesPointer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ library LibBytesPointer {
}
}

function readAddress(
bytes calldata _data,
uint256 _index
) internal pure returns (
address a,
uint256 newPointer
) {
assembly {
let word := calldataload(add(_index, _data.offset))
a := and(shr(96, word), 0xffffffffffffffffffffffffffffffffffffffff)
newPointer := add(_index, 20)
}
}

/**
* @notice Returns the uint8 value and the address at the given index in the input data and updates the pointer.
* @param _data The input data.
Expand Down Expand Up @@ -97,6 +111,22 @@ library LibBytesPointer {
}
}

function readUintX(
bytes calldata _data,
uint256 _bytes,
uint256 _index
) internal pure returns (
uint256 a,
uint256 newPointer
) {
assembly {
let word := calldataload(add(_index, _data.offset))
let shift := sub(256, mul(_bytes, 8))
a := and(shr(shift, word), sub(shl(mul(8, _bytes), 1), 1))
newPointer := add(_index, _bytes)
}
}

/**
* @notice Returns the uint24 value at the given index in the input data and updates the pointer.
* @param _data The input data.
Expand Down Expand Up @@ -139,6 +169,20 @@ library LibBytesPointer {
}
}

function readBytes4(
bytes calldata _data,
uint256 _pointer
) internal pure returns (
bytes4 a,
uint256 newPointer
) {
assembly {
a := calldataload(add(_pointer, _data.offset))
a := and(a, 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000)
newPointer := add(_pointer, 4)
}
}

/**
* @notice Returns the bytes32 value at the given index in the input data and updates the pointer.
* @param _data The input data.
Expand Down
1 change: 1 addition & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ src = 'contracts'
out = 'foundry_artifacts'
libs = ["node_modules", "lib"]
test = 'foundry_test'
ffi = true
Loading

0 comments on commit 51d8c32

Please sign in to comment.