Skip to content

Commit

Permalink
Don't use flag as an argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Agusx1211 committed Jan 22, 2024
1 parent de7fd88 commit 08ddb5b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}

huff-tests:
name: Foundry tests
name: Huff tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
58 changes: 13 additions & 45 deletions src/L2Compressor.huff
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,10 @@
codecopy // [flag, windex, rindex + 1]
no_load:

dup1 // [flag, flag, windex, rindex + 1]
0x01 shl // [flag << 0x01, flag, windex, rindex + 1]
mload // [word, flag, windex, rindex + 1]
0xf0 shr // [word >> 0xf0, flag, windex, rindex + 1]
jump // [flag, windex, rindex + 1]
0x01 shl // [flag << 0x01, windex, rindex + 1]
mload // [word, windex, rindex + 1]
0xf0 shr // [word >> 0xf0, windex, rindex + 1]
jump // [windex, rindex + 1]

FLAG_READ_BYTES32_0_BYTES:
READ_BYTES32_EMPTY() // [windex, rindex]
Expand Down Expand Up @@ -878,9 +877,7 @@
}

#define macro READ_ABI(nrfs, nparams) = takes (3) returns (2) {
// input stack: [flag, windex, rindex]

pop // [windex, rindex]
// input stack: [windex, rindex]

// Reserve 32 bytes to store the size, dynamic values
// use the first 32 bytes to store the size of the value
Expand Down Expand Up @@ -965,9 +962,7 @@
}

#define macro READ_BYTES32(shift_bits, read_bytes) = takes (3) returns (2) {
// input stack: [flag, windex, rindex]

pop // [windex, rindex]
// input stack: [windex, rindex]

0x20 // [0x20, windex, rindex]

Expand All @@ -991,9 +986,7 @@
}

#define macro READ_BYTES32_EMPTY() = takes (3) returns (2) {
// input stack: [flag, windex, rindex]

pop // [windex, rindex]
// input stack: [windex, rindex]

0x00 // [0x00, windex, rindex]
dup2 // [windex, 0x00, windex, rindex]
Expand All @@ -1002,13 +995,11 @@
0x20 // [0x20, windex, rindex]
add // [(0x20 + windex), rindex]

// input stack: [flag, windex, rindex]
// input stack: [windex, rindex]
}

#define macro READ_BYTES32_WORD() = takes (3) returns (2) {
// input stack: [flag, windex, rindex]

pop // [windex, rindex]
// input stack: [windex, rindex]

0x20 // [0x20, windex, rindex]
dup1 // [0x20, 0x20, windex, rindex]
Expand All @@ -1032,7 +1023,6 @@
#define test TEST_FLAG_READ_BYTES32() = {
0x01 // [rindex]
[FMS] 0x40 add // [windex, rindex]
0x00 // [flag, windex, rindex]

READ_BYTES32(0xf0, 0x02) // [windex, rindex]

Expand All @@ -1043,7 +1033,6 @@

0x00 // [rindex]
[FMS] // [windex, rindex]
0xff // [flag, windex, rindex]

READ_BYTES32(0x00, 0x20) // [windex, rindex]

Expand All @@ -1054,7 +1043,6 @@

0x00 // [rindex]
[FMS] 0x40 add // [windex, rindex]
0x00 // [flag, windex, rindex]

READ_BYTES32_WORD() // [windex, rindex]

Expand All @@ -1066,7 +1054,6 @@

0x15 // [rindex]
[FMS] 0x10 add // [windex, rindex]
0xf1 // [flag, windex, rindex]

READ_BYTES32_EMPTY() // [windex, rindex]

Expand All @@ -1077,9 +1064,7 @@
}

#define macro SAVE_ADDRESS() = takes (3) returns (2) {
// input stack: [flag, windex, rindex]

pop // [windex, rindex]
// input stack: [windex, rindex]

dup2 // [rindex, windex, rindex]
calldataload // [word, windex, rindex]
Expand Down Expand Up @@ -1110,8 +1095,6 @@
0x01 // [rindex]
[FMS] // [windex, rindex]

0x02 // [flag, windex, rindex]

SAVE_ADDRESS() // [windex, rindex]

[FMS] 0x20 add eq ASSERT() // [rindex]
Expand All @@ -1133,9 +1116,7 @@
}

#define macro SAVE_BYTES32() = takes (3) returns (2) {
// input stack: [flag, windex, rindex]

pop // [windex, rindex]
// input stack: [windex, rindex]

dup2 // [rindex, windex, rindex]
calldataload // [word, windex, rindex]
Expand Down Expand Up @@ -1164,8 +1145,6 @@
0x01 // [rindex]
0x20 // [windex, rindex]

0x02 // [flag, windex, rindex]

SAVE_BYTES32() // [windex, rindex]

0x40 eq ASSERT() // []
Expand Down Expand Up @@ -1196,9 +1175,8 @@
}

#define macro READ_STORAGE(smv, smc, read_bytes, read_bits_shift) = takes (3) returns (2) {
// input stack: [flag, windex, rindex]
// input stack: [windex, rindex]

pop // [windex, rindex]
swap1 // [rindex, windex]

LOAD_DYNAMIC_SIZE(<read_bytes>, <read_bits_shift>) // [index, nrindex + size, windex]
Expand Down Expand Up @@ -1230,7 +1208,6 @@
// Read the first bytes32
0x00 // [rindex]
0x00 // [windex, rindex]
[FLAG_READ_BYTES32_2_BYTES] // [flag, windex, rindex]

READ_BYTES32_STORAGE(0x02, 0xf0) // [windex, rindex]

Expand All @@ -1242,7 +1219,6 @@
// Read the second bytes32
0x02 // [rindex]
0x20 // [windex, rindex]
[FLAG_READ_BYTES32_2_BYTES] 0x02 add // [flag, windex, rindex]

READ_BYTES32_STORAGE(0x04, 0xe0) // [windex, rindex]

Expand All @@ -1255,8 +1231,6 @@
0x06 // [rindex]
0x10 // [windex, rindex]

[FLAG_READ_BYTES32_2_BYTES] 0x03 add // [flag, windex, rindex]

READ_BYTES32_STORAGE(0x05, 0xd8) // [windex, rindex]

0x30 eq ASSERT() // [rindex]
Expand All @@ -1281,7 +1255,6 @@
// Read the first bytes32
0x00 // [rindex]
0x00 // [windex, rindex]
[FLAG_READ_ADDRESS_2_BYTES] // [flag, windex, rindex]

READ_ADDRESS_STORAGE(0x02, 0xf0) // [windex, rindex]

Expand All @@ -1293,7 +1266,6 @@
// Read the second bytes32
0x02 // [rindex]
0x20 // [windex, rindex]
[FLAG_READ_ADDRESS_2_BYTES] 0x02 add // [flag, windex, rindex]

READ_ADDRESS_STORAGE(0x04, 0xe0) // [windex, rindex]

Expand All @@ -1306,8 +1278,6 @@
0x06 // [rindex]
0x10 // [windex, rindex]

[FLAG_READ_ADDRESS_2_BYTES] 0x03 add // [flag, windex, rindex]

READ_ADDRESS_STORAGE(0x05, 0xd8) // [windex, rindex]

0x30 eq ASSERT() // [rindex]
Expand Down Expand Up @@ -1408,9 +1378,7 @@
}

#define macro READ_N_BYTES(nrfs) = takes (2) returns (2) {
// input stack: [flag, windex, rindex]

pop // [windex, rindex]
// input stack: [windex, rindex]

PERFORM_NESTED_READ_FLAG(<nrfs>) // [windex, rindex]
BACKREAD_SINGLE_VALUE() // [size, windex, rindex]
Expand Down

0 comments on commit 08ddb5b

Please sign in to comment.