Skip to content

get-create2-address command #123

Open
@JereSalo

Description

@JereSalo

DISCLAIMER: I'm not sure if this command will be useful in practice, I just know that get-create-address is a command that I liked but I never had to use something for CREATE2. We have to put ourselves in the users' shoes and think what a user of this command would like.

Like get-create-address but for CREATE2.
Again, maybe a shorter name (but still descriptive) should be chosen.

Working code extracted from LEVM:

/// initialization_code = memory[offset:offset+size]
/// address = keccak256(0xff || sender_address || salt || keccak256(initialization_code))[12:]
pub fn calculate_create2_address(
    sender_address: Address,
    initialization_code: &Bytes,
    salt: U256,
) -> Result<Address, VMError> {
    let init_code_hash = keccak(initialization_code);

    let generated_address = Address::from_slice(
        keccak(
            [
                &[0xff],
                sender_address.as_bytes(),
                &salt.to_big_endian(),
                init_code_hash.as_bytes(),
            ]
            .concat(),
        )
        .as_bytes()
        .get(12..)
        .ok_or(VMError::Internal(
            InternalError::CouldNotComputeCreate2Address,
        ))?,
    );
    Ok(generated_address)
}

I think it would be cool to have a .sol file as input of this command but maybe it is too much haha. What's really necessary is to have the initcode or the code hash as input.

Basic example:
rex get-create2-address <address> <salt> <initcode_hash>

Ideally we would use flags because the command can have different parameters depending on what the user wants.

--address <deployer address>
--salt <salt> 
--code <bytecode> 
--code_hash <initcode_hash>

Where code and code_hash are exclusive one from another, you don't need to use both.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions