How should I interpret the math in showing that the potential difference and the emf in an ideal battery are the same? I was reading Griffiths' Introduction to Electrodyamics where he says that in order to have the same current through out a circuit there are two force per unit charges acting on the circuit, $f=f_s+E$ where $f_s$ is the force per unit charge from an electric energy source and $E$ is the electrostatic field. In an idealized battery, $f=0$ and you get that $f_s=-E$. Therefore,
$$V=-\int_a^b \vec{E} \cdot d\vec{\ell}=\int_a^b \vec{f}_s \cdot d\vec{\ell}=\oint \vec{f}_s \cdot d\vec{\ell}=\mathscr E$$
Physically speaking it makes sense because in an idealized battery the Electric field is negligible and it is the emf that is moving all the charges in the circuit, thus establishing a potential difference. Mathematically though, I don't see the same thing. To me it seems that I can go another step further from $\oint \vec{f}_s \cdot d\vec{\ell}$ and get $$\oint \vec{f}_s \cdot d\vec{\ell}=-\oint \vec{E} \cdot d\vec{\ell}=0$$ I know that this is wrong, but I am not entirely sure why it is wrong.
 A: Everything up until you say "Physically speaking" is fine.  The first equality:
$$V=-\int_a^b \vec{E} \cdot d\vec{\ell},$$
holds because that is the definition of the potential for electrostatics. The second equality:
$$-\int_a^b \vec{E} \cdot d\vec{\ell}=\int_a^b \vec{f}_s \cdot d\vec{\ell},$$ holds because (inside the battery, where we are integrating), we have an idealized battery in the steady state (after enough time has passed to get steady currents) with no net force on the charges, so $\vec{f}=\vec{f}_s+\vec{E}=\vec{0}$. Thus, $\vec{E}=-\vec{f}_s$.
The third equality:
$$\int_a^b \vec{f}_s \cdot d\vec{\ell}=\oint \vec{f}_s \cdot d\vec{\ell}=\mathscr E,$$ holds because the source $\vec{f}_s$ only acts between a and b.  Every step of this should be clear both mathematically and physically.
But to be clear, this is electrostatics, that's why you have a clear voltage, and $\vec{\nabla}\times\vec{E}=\vec{0}$.  You can even imagine two fields, the electrostatic $\vec{E}$ field that satisfies $\vec{\nabla}\cdot\vec{E}=\rho/\epsilon_0$ and $\vec{\nabla}\times\vec{E}=\vec{0}$ and the $\vec{G}$ field satisfying $\vec{\nabla}\cdot\vec{G}=0$ and $\vec{\nabla}\times\vec{G}=-\frac{\partial \vec{B}}{\partial t}$, with the Lorentz force law being
$$\vec{F}=q(\vec{E}+\vec{G})+q\vec{v}\times\vec{B}.$$
See Griffiths footnote in the section "The Induced Electric Field".  In statics $\vec{G}$ can equal $\vec{0}$.  And then we have $\vec{\nabla}\times\vec{E}=\vec{0}$, from which we get:
$$\oint \vec{E}\cdot d\vec{\ell}=0.$$
So that isn't wrong.  What you need to realize is that
$$\mathscr E=\oint \vec{f}_s\cdot d\vec{\ell}\neq-\oint \vec{E}\cdot d\vec{\ell}=0.$$
I can't figure out why you thought they were equal, so I don't know what to say.  And everything you wrote after "Physically speaking" is just wrong.  The net force (per unit charge) is $\vec{f}=\vec{f}_s+\vec{E}$, not just $\vec{E}$ and $\vec{E}$ is very very important, hardly negligible.  The emf:
$$\mathscr E=\oint \vec{f}\cdot d\vec{\ell}=\oint \vec{f}_s\cdot d\vec{\ell}=-\int_a^b \vec{E}\cdot d\vec{\ell},$$
is responsible for the net work done (per unit charge) around the entire loop.
The first equality is the definition, the second is because $\oint \vec{E}\cdot d\vec{\ell}=0$ since this is electrostatics, and the last equality is the first derivation we did assuming an ideal source, that's the one that only holds ideally, the middle one only in statics, and the first always holds, though it is just a definition, so not very useful.
Edit based on reading the linked question
Note that $\vec{f}=\vec{0}$ only inside the ideal battery, otherwise indeed you would get $$\mathscr E=\oint \vec{f}\cdot d\vec{\ell}=\oint \vec{0}\cdot d\vec{\ell}=0=\oint \vec{E}\cdot d\vec{\ell}$$
Edit based on the comment: "What exactly would be the correct way of thinking of $\vec{f}=\vec{0}$? I mean obviously the charges are moving but it looks like in the battery they are not.
In an ideal battery, there is no energy "loss" inside the battery during operation, but it is probably literally not the case that $\vec{f}=\vec{0}$ pointwise inside the battery, even in an ideal (no power loss) situation.  Let's carefully review what happens inside a circuit and a battery in electrostatic equilibrium.
Force (per unit charge) is different than motion, you can have zero force, but still have motion, and we definitely have motion.  But we also do actually have forces in some places.  If you have a current, then there should be a force to make charges turn corners, you can get that from an electrostatic force that has some excess charge at the outside corner and opposite excess charge at the inside the corner, then the mobile charges whip around the corner.  You might have one region where there are fewer mobile charges, but moving quicker, and before that you have a region with more charges moving slower, so you should have a charge imbalance in the between region to get that transition.  All these things happen in order to even out the current so that charge no longer piles up, so it piles up where it needs to to get to an equilibrium where it doesn't pile up any further. This equilibrium still has charges and they still have forces, but the forces just produce the motion that makes the steady current from existing situations with the same existing steady current.
For instance you can have a rod moving orthogonal to itself and both those things (direction of the rod, and direction of the motion) mutually orthogonal to a $\vec{B}$-field.  Then charge piles up at the ends (equal and opposite) until the electrostatic force cancels the magnetic force.  That's equilibrium.  If you connected the ends of the rod to a circuit, that equilibrium breaks as charge distributes itself so that the mobile charges get the forces they need to negotiate every corner and every speed up and every slow down.  And then there is a new equilibrium, and that's what we want to analyze.
I think it's best not to think that $\vec{f}=\vec{0}$ everywhere inside the battery, after all, maybe the battery has some corners too.  It's best to think about energy.  So have an actual current flow in for a small time $\Delta t$.  We want an equal current to flow out for the same small time $\Delta t$.  So an equal amount of charge flows in and out, so an equal number of mobile charges (electrons) flow in and out.  So the current is the average speed of this same number of electrons.  So the work done from a to b should be zero, so while $\vec{f}\neq\vec{0}$ we do have $\int_a^b\vec{f}\cdot d\vec{\ell}=0$.  Wait, where did the assumption of the ideal battery come in?  A nonideal battery can have $\int_a^b\vec{f}\cdot d\vec{\ell}\neq 0$ if that net work done doesn't go to the kinetic energy of those same number of electrons entering/exiting the circuit.  For instance, if the battery has some resistence, and hence some resistive losses due to joule heating.  So even in the ideal situation, $\vec{f}\neq\vec{0}$ everywhere inside the battery (there might be corners for instance), but for the ideal situation $\int_a^b\vec{f}\cdot d\vec{\ell}= 0$, and that's what we need since we need:
$$ 0=\int_a^b\vec{f}\cdot d\vec{\ell}= \int_a^b(\vec{f}_s+\vec{E})\cdot d\vec{\ell}= \int_a^b\vec{f}_s\cdot d\vec{\ell}+ \int_a^b\vec{E}\cdot d\vec{\ell},
$$
So $\int_a^b\vec{f}_s\cdot d\vec{\ell}=- \int_a^b\vec{E}\cdot d\vec{\ell}$, which is what we actually wanted and needed, and is what is actually true.  It's the averaged result of $\vec{f}=\vec{0}$ in that it holds for the average $\vec{f}$ (two things have the same spatial average if their integrals are the same).  So $\vec{f}_s\neq -\vec{E}$ inside the battery, but if we integrate over the whole battery we do get  $\int_a^b\vec{f}_s\cdot d\vec{\ell}=- \int_a^b\vec{E}\cdot d\vec{\ell}$.
