Part 3: Annotated Specification
Note: The definitions below are for specification purposes and are not necessarily optimal implementations.
This note in the spec is super important for implementers! There are many, many optimisations of the below routines that are being used in practice; a naive implementation would be impractically slow for mainnet configurations. As long as the optimised code produces identical results to the code here, then all is fine.