united-states
Protections for workers from wrongful termination from employment in the U.S. are among the weakest in the developed world.
Unemployment benefits
If you are fired and there is not a "good cause" basis to fire you, you are entitled to unemployment insurance in almost all U.S. states (at least if you have worked for the employer long enough). Firing you because you discovered a payroll accounting problem and brought it to the employer's attention would ordinarily not constitute "good cause" for unemployment insurance purposes.
Unemployment benefits last only a limited period of time, are for only a fraction of what you earned when you were employed, and can be terminated if you fail to actively look for work or find new employment.
Whistleblower protections
There are whistleblower statutes that prohibit employers from firing someone for reporting certain kinds of employer misconduct (although the remedy is usually a large dollar damages award - typically more than unemployment benefits, rather than reinstatement).
But it isn't entirely clear that one would apply in this case, particularly without knowing which state if it is in the U.S., is involved.
There is not one omnibus whistleblower protection statute at the federal level or in most U.S. states that prohibits firing or punishing an employee in every case where misconduct is revealed (this kind of conduct by an employer is also sometimes called "retaliation" or a "retaliatory firing").
Instead, there is a patchwork of whistleblower protections for particular kinds of misconduct that is reported by the employee. One would have to determine if this particular kind of misconduct would fit one of those statutes.
For example, there are at least five different agencies that enforce whistleblower protections at the federal level:
Occupational Safety and Health Administration (OSHA)
With the Occupational Safety and Health Act of 1970, Congress created
the Occupational Safety and Health Administration (OSHA) to ensure
safe and healthful working conditions for workers by setting and
enforcing standards and by providing training, outreach, education and
assistance.
Mine Safety and Health Administration (MSHA)
The U.S. Department of Labor's Mine Safety and Health Administration
(MSHA) helps to reduce deaths, injuries, and illnesses in the nation's
mines with a variety of activities and programs. The Agency develops
and enforces safety and health rules for all U.S. mines, and provides
technical, educational and other types of assistance to mine
operators.
Office of Federal Contract Compliance Programs (OFCCP)
The Office of Federal Contract Compliance Programs (OFCCP), protects
workers, promotes diversity and enforces the law. OFCCP holds those
who do business with the federal government (contractors and
subcontractors) responsible for complying with the legal requirement
to take affirmative action and not discriminate on the basis of race,
color, sex, sexual orientation, gender identity, religion, national
origin, disability, or status as a protected veteran. In addition,
contractors and subcontractors are prohibited from discharging or
otherwise discriminating against applicants or employees who inquire
about, discuss or disclose their compensation or that of others,
subject to certain limitations.
Wage and Hour Division (WHD)
The Wage and Hour Division (WHD) mission is to promote and achieve
compliance with labor standards to protect and enhance the welfare of
the nation's workforce. The agency enforces federal minimum wage,
overtime pay, recordkeeping, and child labor requirements of the Fair
Labor Standards Act. WHD also enforces the Migrant and Seasonal
Agricultural Worker Protection Act, the Employee Polygraph Protection
Act, the Family and Medical Leave Act, wage garnishment provisions of
the Consumer Credit Protection Act, and a number of employment
standards and worker protections as provided in several immigration
related statutes.
Veterans’ Employment and Training Service (VETS)
The Veterans’ Employment and Training Service prepares America's
veterans, service members and their spouses, for meaningful careers,
provide them with employment resources and expertise, protect their
employment rights and promote their employment opportunities.
There are also typically whistleblower protections related to union activity at an employer.
Employees of the government and government contractors have stronger protections for whistleblowers than most employees.
The Wage and Hour division whistleblowing rules might apply, but that would depend upon detailed facts not present in the question about the exact nature of the errors in the payroll system.
Whistleblower protections might apply under the Sarbanes–Oxley Act (SOX) of 2002, but typically that protects only employees of large or publicly held companies. Similarly, whistleblower protections arising from securities laws are typically only applicable to publicly held companies or companies that are going public.