Skip to content

Commit 19995e4

Browse files
committedMar 8, 2023
tada
1 parent 7d52502 commit 19995e4

File tree

6 files changed

+63
-16
lines changed

6 files changed

+63
-16
lines changed
 

‎.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
path = lib/forge-std
33
url = https://github.com/foundry-rs/forge-std
44
branch = v1.5.0
5+
[submodule "lib/foundry-huff"]
6+
path = lib/foundry-huff
7+
url = https://github.com/huff-language/foundry-huff

‎lib/foundry-huff

Submodule foundry-huff added at e691315

‎script/Counter.s.sol

-12
This file was deleted.

‎src/Add.huff

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#define macro MAIN() = {
2+
ADD()
3+
}
4+
5+
#define macro ADD() = takes(2) returns (1) {
6+
jumpdest
7+
add
8+
}

‎src/Counter.sol

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ contract Counter {
99
}
1010

1111
function increment() public {
12-
number++;
12+
function (uint256, uint256) pure returns (uint256) _add;
13+
assembly {
14+
_add := sub(codesize(), 2)
15+
}
16+
number = _add(number, 1);
1317
}
1418
}

‎test/Counter.t.sol

+46-3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,56 @@ pragma solidity ^0.8.13;
33

44
import "forge-std/Test.sol";
55
import "../src/Counter.sol";
6+
import { HuffDeployer } from "foundry-huff/HuffDeployer.sol";
7+
8+
9+
contract CounterHuffidity is Test {
10+
constructor() {
11+
bytes memory solidityCode = type(Counter).runtimeCode;
12+
bytes memory huffCode = (HuffDeployer.deploy("Add")).code;
13+
14+
// console.logBytes(solidityCode);
15+
// console.logBytes(huffCode);
16+
17+
assembly {
18+
let concatenated := mload(0x40)
19+
let solidityCodeLen := mload(solidityCode)
20+
let huffCodeLen := mload(huffCode)
21+
22+
pop(staticcall(
23+
gas(),
24+
0x04,
25+
add(solidityCode, 0x20),
26+
solidityCodeLen,
27+
concatenated,
28+
solidityCodeLen
29+
))
30+
31+
pop(staticcall(
32+
gas(),
33+
0x04,
34+
add(huffCode, 0x20),
35+
huffCodeLen,
36+
add(concatenated, solidityCodeLen),
37+
huffCodeLen
38+
))
39+
40+
return(concatenated, add(solidityCodeLen, huffCodeLen))
41+
}
42+
}
43+
44+
function number() external view returns (uint256) {}
45+
function setNumber(uint256) external {}
46+
function increment() external {}
47+
}
48+
649

750
contract CounterTest is Test {
8-
Counter public counter;
51+
CounterHuffidity public counter;
952

1053
function setUp() public {
11-
counter = new Counter();
12-
counter.setNumber(0);
54+
counter = new CounterHuffidity();
55+
console.logBytes(address(counter).code);
1356
}
1457

1558
function testIncrement() public {

0 commit comments

Comments
 (0)
Please sign in to comment.