Signature

HOT uses an EIP 712 signature scheme. The signature verification is done through the isValidSignatureNow function in the Open Zeppellin SignatureChecker library.

        bytes32 hotHash = hot.hashParams();
        if (!hotReadSlotCache.signer.isValidSignatureNow(_hashTypedDataV4(hotHash), signature)) {
            revert HOT___hotSwap_invalidSignature();
        }

To construct a valid signature the typehash and the domain separator are needed, both of which can be calculated offchain or retrieved from onchain public functions in the smart contract. A working foundry example is provided below:

    function getEOASignedQuote(
        HolverOrderType memory hotParams,
        uint256 privateKey
    ) public view returns (bytes memory signedQuoteExternalContext) {
        bytes32 digest = keccak256(
            abi.encodePacked(
                '\x19\x01',
                hot.domainSeparatorV4(),
                keccak256(abi.encode(HOTConstants.HOT_TYPEHASH, hotParams))
            )
        );

        (uint8 v, bytes32 r, bytes32 s) = vm.sign(privateKey, digest);

        bytes memory signature = abi.encodePacked(r, s, bytes1(v));

        signedQuoteExternalContext = abi.encode(hotParams, signature);
    }

The complete work-flow of a HOT swap can be found in the scripts/SepoliaHOTSwap.s.solfile.

Last updated