huff-rs icon indicating copy to clipboard operation
huff-rs copied to clipboard

Using derived storage pointer instead of constant when passing as argument to macro breaks

Open af-afk opened this issue 3 years ago • 2 comments

The following snippets are identical in theory:

#define constant SWAG = 0x00

#define macro M(slot) = {
	<slot> sload 0x00 mstore 0x14 0x00 return
}

#define macro MAIN() = {
	M(SWAG)
}
#define constant SWAG = FREE_STORAGE_POINTER()

#define macro M(slot) = {
	<slot> sload 0x00 mstore 0x14 0x00 return
}

#define macro MAIN() = {
	M(SWAG)
}

But the latter errors without context with Error: Storage Pointers Not Derived.

Seems to be a bug?

af-afk avatar Dec 28 '22 12:12 af-afk

The macro TEST will not insert SLOT_SOMETHING into the stack (silently fail) if it's referred to this way:

#define constant SLOT_SOMETHING = FREE_STORAGE_POINTER()

#define macro TEST() = {
	0x01

	<SLOT_SOMETHING> sstore
}

#define macro MAIN() = {
	TEST()
}

Generating bytecode 60038060093d393df3600155. Having SLOT_SOMETHING be accessed with [SLOT_SOMETHING] instead means 60058060093d393df36001600055.

Doing this in MAIN is a different story:

#define constant SLOT_SOMETHING = FREE_STORAGE_POINTER()

#define macro MAIN() = {
	0x01

	<SLOT_SOMETHING> sstore
}

In the above example it fails with:

[31m
Error: Unmatched Jump Label

[0m
huffc: exit 1

af-afk avatar Dec 29 '22 02:12 af-afk

The original issue has been merged in, could you make the second comment into another issue please so its easier to triage! Appreciate you finding these issues :):)

Maddiaa0 avatar Jan 30 '23 19:01 Maddiaa0