Skip to content
This repository has been archived by the owner on Oct 20, 2024. It is now read-only.

Add raw bytes to huff contract bytecode #285

Open
0x366 opened this issue Jun 22, 2023 · 2 comments
Open

Add raw bytes to huff contract bytecode #285

0x366 opened this issue Jun 22, 2023 · 2 comments

Comments

@0x366
Copy link

0x366 commented Jun 22, 2023

I want to add raw bytes of arbitrary length to bytecode of huff contract:
I.e. store these 0x0000000000000000000000000000000000000000000000000000000000000000aabbccdd
bytes of length 36. Currently there are 2 ways:

  1. compile huff contract and manually append these bytes to the end. Though testing with that approach is a complete nightmare
  2. Divide the bytes into 32byte words and store as constants, though huff will add push32 opcode infront of which word and bytes won't be continuous.

Would be great to have something like

#define macro MAIN() = takes (0) returns (0) {
    ...
}
[0x0000000000000000000000000000000000000000000000000000000000000000aabbccdd]

which will append these bytes to the end of contract bytecode

@0xvv
Copy link

0xvv commented Jul 4, 2023

This exists, here is a link in the docs: https://docs.huff.sh/get-started/huff-by-example/#code-tables
Note that the arbitrary bytecode is only happened at the end is it's referenced in your huuf code using __tablesize() and/or __tablestart()

@0x366
Copy link
Author

0x366 commented Jul 6, 2023

Oh, thank you, somehow I missed that.

I just tried a simple example tho it's not appending, am I doing something wrong ?

#define macro MAIN() = takes (0) returns (0) {
    stop
}

#define table CODE_TABLE {
    0xf9f9f9
}
> huffc tmp.huff -r

⠋ Compiling...[huff_parser/src/lib.rs:1114] ident_str = "f9f9f9"
⠙ Compiling... 
00%          

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants