I've been reading about the vulnerabilities of PoW crypto, and there's a part of it that I don't understand.
Suppose I wanted to stage a 51% attack on Bitcoin (not really feasible, but bear with me). This would involve waiting for height n to be achieved, and then immediately working with my superior hashpower to produce blocks at heights n+1, n+2, ..., f without broadcasting said blocks to the network. For simplicity's sake, let's say I'm adding empty blocks to my private chain. When I feel like it, I can then broadcast my chain (which is longer than the trusted chain), which will nullify all transactions starting from block n+1 inclusive (is this correct?).
Firstly, on a semi-low level (i.e. in terms of actual data/file operations), how does one keep and cultivate the secret chain? Would I be saving a sequence of valid hashes for each block, while remaining disconnected from the network?
Secondly, how does one broadcast the bigger chain? My understanding is that when you connect to the network and submit a block at height k, it will be rejected if the main network is already on block k+1 or greater. So even if I sequentially broadcast my solutions, wouldn't they be rejected before it could be revealed that the number of solutions I have exceeds that of the main network's chain? For example, after starting my 51% attack after block n is found, the main network eventually gets to block n+3 while I am secretly at block n+5. In terms of actual operations, what would I need to do in order to supersede the main chain?