Consider the random walk $$S_n=\sum_{k}^{n}X_{k}$$
Where $X_k$'s are iid, $$\mathbb P(X_1=1)=\mathbb P(X_1=-1)=\frac{1}{2}$$
and $\mathcal{F}_{n}=\sigma(X_i,0\leq i\leq n)$.
How do I prove that $$(S_n^{2}-n,n\geq 0)$$
is a $\mathcal{F}_{n}$-martingale, and that $\mathbb E(S_{\tau}^{2})=\mathbb E(\tau)$, where $\tau$ is a bounded stopping time?
Given $(S_n^2-n,\mathcal{F_n})_{n\ge 0}$ is martingale, all you want to do is to check if you can apply Doob's optional sampling. Basically, the theorem specifies conditions under which one is allowed to plug stopping times instead of fixed numbers into the definition of martingale. In other words, it says when $$\mathbb{E}(X_\tau\mid\mathcal{F_\sigma})=X_\sigma$$ holds for a martingale $(X_n,\mathcal{F}_n)_{n\ge0}$ and stopping times s.t. $\sigma\le\tau$.
It turns out that one of the sufficient conditions is that $\tau$ is a bounded stopping variable, i.e. there is a constant $N\in\mathbb{N}$ s.t. $\tau\le N$ almost surely. It is exactly the assumption which you have in your problem, so now you have to make a clever choice for $\sigma$ and you are done.
For a technical problem, you want to check if $$\mathbb{E}(S_{n+1}^2-(n+1)\mid\mathcal{F}_n)=S^2_n-n$$ is true. Note the $(n+1)$-th variable can be expressed in a suggestive form $$(S_n+X_{n+1})^2-(n+1)=[S_n^2-n]+[2S_nX_{n+1}]+[X_{n+1}^2-1]$$ and keep in mind the conditional expectation is a powerful thing.