Skip to content

Instantly share code, notes, and snippets.

@highskore
highskore / Quicksort.huff
Last active March 11, 2024 04:07
Recursive QuickSort in Huff
/// @notice Sort
/// @notice Loads the unsorted array from calldata and returns the sorted array
#define macro SORT() = takes (0) returns (0) {
// copy array from calldata to memory
0x24 calldataload // [array_length]
0x20 // [0x20, array_length]
mul // [32 * array_length]
0x44 // [0x44, 32 * array_length]
0x00 // [0x00, 0x44, 32 * array_length]
calldatacopy