Precision errors arise when contracts mishandle decimal scaling or rounding in calculations, leading to inaccurate results
Code
// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;contract VulnerableToken {stringpublic name ="VulnerableToken";stringpublic symbol ="VUL";uint8public decimals =18;uint256public totalSupply;mapping(address=>uint256) public balanceOf;eventTransfer(addressindexed from, addressindexed to, uint256 value);constructor(uint256 initialSupply) {// Initialize total supply without accounting for decimals totalSupply = initialSupply; balanceOf[msg.sender] = totalSupply;emitTransfer(address(0), msg.sender, totalSupply); }// Mint function vulnerable to incorrect decimal handlingfunctionmint(uint256 amount) public {// Fails to scale by decimals, causing inflated supply totalSupply += amount; balanceOf[msg.sender] += amount;emitTransfer(address(0), msg.sender, amount); }}