hats-finance / illuminex-0x0bb4aa1f58719707405c231fcdf0b405714799cf

0 stars 1 forks source link

Malicious actor can finish tx serializing before relayers #16

Open hats-bug-reporter[bot] opened 4 months ago

hats-bug-reporter[bot] commented 4 months ago

Github username: -- Twitter username: -- Submission hash (on-chain): 0x3ab17167f8ff71bf669daef779de918fbdbfc9fc01a30327f0bdf074c121cc22 Severity: medium

Description: Description\ An attacker can directly finish TX serialization before the relayers by directly calling the serializeTx() function before the relayers via enrichSigHash() or serializeOutgoingTransaction()

AbstractTxSerializer.sol - serializeOutgoingTransaction()

    function serializeTx(
        TxSerializingProgress storage _progress,
        BitcoinUtils.BitcoinTransaction storage _tx,
        uint256 _count
    ) external {
        require(_progress.state != TxSerializingState.Finished, "AF");

        if (_progress.state == TxSerializingState.Headers) {
            BitcoinUtils.serializeTransactionHeader(_progress.stream, _tx);
            _progress.state = TxSerializingState.Inputs;
        }

        // Serialize inputs
        BitcoinUtils.serializeTransactionInputs(
            _progress.stream,
            _tx,
            _progress.progress,
            _progress.progress + _count
        );

        _progress.progress += _count;
        if (_progress.progress == _tx.inputs.length) {
            BitcoinUtils.serializeTransactionOutputsAndTail(_progress.stream, _tx);
            _progress.state = TxSerializingState.Finished;
        }
    }

This will lead to the state being finished and serializeTx() will permanently revert with thos eparams. Note that the attacker can also front-run the relayer txs to make them revert.

Recommendation\ Consider to add appropriate access control to TxSerializerLib - serializeTx().

kill-bugs commented 4 months ago

I think this is invalid, library is not inherited, but used directly aka it can't be called directly, only the relayer can serialize either via serializeOutgoingTransaction() or enrichSigHash().