Can someone tell me where in my "proof" that ZF is inconsistent I went wrong? I've come up with a supposed "proof" of the inconsistency of ZF, and I'm not exactly sure I went wrong. I'm not claiming to have proved it, obviously. I know it's wrong somewhere. This thought just came up into my mind and I thought it was neat. I'm only at the first-year graduate level in set theory, keep in mind. Here goes:
Let $f(n)$ be the least ordinal $\alpha$ such that $V_{\alpha}$ is a $\Sigma_n$ elementary substructure of $V$. By replacement, the range of this function is a set. Let $\beta$ be the supremum of this set. So, $V_{\beta}$ is an elementary substructure of $V$, hence it's a model of ZF. ZF proves its own consistency, so it is inconsistent.
 A: The issue has to do with the undefinability of truth, and the merely schematic definability of $\Sigma_n$-truth.
Recall that the axiom of Replacement says, roughly, that if a formula $\varphi(x,y)$ defines a function $F: V\to V$, then on any set $A$, the pointwise image $F''A$ is a set. To apply Replacement to the function $f$ as in the OP, we presumably will need a single formula $\Phi(x,y)$ that's equivalent to saying "$y$ is the least ordinal such that $V_y$ is $\Sigma_x$-elementary to $V$."
But a special case of Tarski's undefinability theorem says, for any formula $\varphi(x,y)$, the following will not hold:

For any natural number $n$ and ordinal $\alpha$, $\varphi(n,\alpha)$ if and only if $V_\alpha$ is a $\Sigma_n$-elementary substructure of $V$.

The point here is that there's no single formula that does what's required for the OP's argument to go through.
The more common form of Tarski's theorem says that there is no formula $True(x,y)$ such that for any (code of a) formula $\psi$ and any set $a$, $True(\psi, a)$ if and only if $\psi(a)$ is true. In slogan form: truth is not definable.
Now the more subtle point is that for each (meta-theoretic) natural number $n$, we do have a formula $True_n(x,y)$, satisfying

$True_n(\psi, a)$ if and only if $\psi$ is a $\Sigma_n$ formula and $\psi(a)$ is true.

Since from the definition $\Sigma_n$-truth we can go on and define the notion of "$\Sigma_n$-elementary to $V$", what we do have, then, is that for each $n$, there is a formula $\Phi_n(y)$ that is equivalent to saying "$y$ is the least ordinal such that $V_y$ is $\Sigma_n$-elementary to $V$."
The key observation is that, when it comes to $\Sigma_n$-truth in $V$, we need a separate formula for each $n$.
On the other hand, we can define truth for any set-sized structure. So this argument does have a version that's somewhat applicable. For example, one can show that the least $\kappa$ such that $V_\kappa\vDash \mathsf{ZFC}$ (if exists) has cofinality $\omega$. One way to show this is by an argument that's similar to the OP's.

suppose for contradiction that the least such $\kappa$ has uncountable cofinality. Then define $f(n)$ to be the least ordinal $\alpha$ such that $V_\alpha$ is a $\Sigma_n$-elementary substructure of $V_\kappa$. Then by replacement (in V), the image of $f$ forms a countable set of ordinals. And since $\kappa$ has uncountable cofinality, the supremum $\lambda$ of that set is bounded below $\kappa$. And because $V_\lambda$ is an increasingly elementary chain of structures, we have $V_\lambda$ is an elementary substructure of $V_\kappa$, and hence $V_\lambda\vDash\mathsf{ZFC}$, contradicting the minimality of $\kappa$.

This version of the argument goes through, because in this case we do have a single formula $\Phi(x,y)$ that's equivalent to saying "$y$ is the least ordinal such that $V_y$ is $\Sigma_x$-elementary to $V_\kappa$." This is precisely because truth in a set-sized structure is definable by a single formula.
