type
status
date
slug
summary
category
tags
icon
password
When checking an Ethereum token approval, we encountered this string of numbers:
115792089237316195423570985008687907853269984665640564039457584007913129639935
Q: What is this seemingly random large number?
A: This is the "unlimited approval" value in Ethereum smart contracts, used to grant maximum token usage rights to third-party contracts.
Q: Why was this number chosen to represent "unlimited"?
A: When converted to hexadecimal, it shows a special pattern:
0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
This is the maximum value that uint256 can represent, which is 2^256-1.
Q: Why is it 2^256-1 and not 2^256?
A: This involves basic computer principles: using 4-bit binary as an example, from 0000 to 1111, the range is 0 to 15 (2^4-1). Similarly, the range for 256-bit binary is 0 to 2^256-1.
Q: What if we absolutely need to represent 2^256?
A: 2^256 in hexadecimal would be 0x1 followed by 64 zeros, but this requires 257 bits, exceeding the range of uint256. This is the technical reason why smart contracts choose 2^256-1 as "unlimited".
This example demonstrates how blockchain elegantly implements the concept of "unlimited" within finite data types.
- Author:Zhenye Dong
- URL:https://dongzhenye.com/article/infinity-in-ethereum-approve
- Copyright:All articles in this blog, except for special statements, adopt BY-NC-SA agreement. Please indicate the source!
Relate Posts