Does the Bitcoin protocol guarantee that within a valid block, if transaction B spends the outputs of transaction A, A will always precede B?
Or is it possible to have B before A?
The Bitcoin protocol requires transactions to appear in topological order in the blockchain. Given two transactions A and B where B spends an output of A:
Colloquially, a miner will never include a transaction in a block template until the transaction's requirements are met. Since B spends an output of A, B is not valid until A has created said output. To satisfy this dependency, B can only be included after A was included.