Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ffi: decode output as hex if it looks like a hexstring #215

Merged
merged 1 commit into from
Oct 31, 2023

Conversation

karmacoma-eth
Copy link
Collaborator

@karmacoma-eth karmacoma-eth commented Oct 31, 2023

This is for compatibility with foundry, and will work better with tools like huffc that output hexstrings without a 0x prefix. For instance:

function deployHuff(string memory srcFile) internal returns (address deployedAddress) {
    string[] memory command = new string[](3);
    command[0] = "huffc";
    command[1] = "--bytecode";
    command[2] = srcFile;

    bytes memory bytecode = vm.ffi(command);

    assembly {
        deployedAddress := create(0, add(bytecode, 0x20), mload(bytecode))
    }
}

Before this commit, bytecode was the hexstring. After this commit, bytecode is the actual bytes.

This is for compatibility with foundry, and will work better with tools like huffc that output hexstrings without a 0x prefix. For instance:

    function deployHuff(string memory contractName) internal returns (address deployedAddress) {
        string[] memory command = new string[](3);
        command[0] = "huffc";
        command[1] = "--bytecode";
        command[2] = string.concat("src/", contractName, ".huff");

        bytes memory bytecode = vm.ffi(command);

        assembly {
            deployedAddress := create(0, add(bytecode, 0x20), mload(bytecode))
        }
    }

Before this commit, bytecode was the hexstring. After this commit, bytecode is the actual bytes.
@karmacoma-eth karmacoma-eth merged commit 4d2793f into main Oct 31, 2023
110 checks passed
@karmacoma-eth karmacoma-eth deleted the ffi-implicit-hex branch October 31, 2023 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants