0

proxy contract

contract ERC20ProxyDelegator {
    constructor(ERC20Votes _token, address _delegate) {
        _token.approve(msg.sender, type(uint256).max);
        _token.delegate(_delegate);
    }
}

Main contract function which creates the proxy contract.

    function retrieveProxyContractAddress(
        ERC20Votes _token,
        address _delegate
    ) private view returns (address) {
        bytes memory bytecode = abi.encodePacked(
            type(ERC20ProxyDelegator).creationCode, 
            abi.encode(_token, _delegate)
        );
        bytes32 hash = keccak256(
            abi.encodePacked(
                bytes1(0xff),
                address(this),
                uint256(0), // salt
                keccak256(bytecode)
            )
        );
        return address(uint160(uint256(hash)));
    }
}

In the above contract creation code I have seen that the salt is not unique.If i can managed to give the same inputs all the time (_token ,_delegate) can i able to produce same address all the time?

1 Answer 1

0

Yes, given none of the inputs change, this function is deterministic. However, if any of the inputs (salt, creationCode, _token, _delegate) change, this will change. It should also be noted that this function is deterministic at each address it is deployed to, but would return different addresses for the same salt, creationCode, _token, and _delegate combination if it were called on two different instances (contract deployments).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.