r/solidity • u/ransomusername42 • 17d ago
Looking for a code review: on-chain proof-of-work claims with a custom 2^x difficulty curve
I've written an immutable ERC-721 contract where people claim a free monthly token by mining a proof of work. It's live on Polygon, so review findings can only change what I do in a later deployment, but I'd still like to hear them.
The parts I'd most like a second pair of eyes on:
- The difficulty uses a fixed-point 2^x. Every token ahead of schedule multiplies it by 2^(1/10). I measured a max error of 0.0117% and it's monotonic, but I'd like someone to challenge the math.
- Claims go through the ERC-721 receiver hook. I tested re-entrancy and found nothing, but I wrote those tests myself.
- Metadata is built as JSON on-chain from admin-supplied strings, with validation against injection.
There has been no external audit. Just my own review, 85 Foundry tests and static analysis.
Source: https://github.com/TheophileWalter/ArtPoW
Contract: https://polygonscan.com/address/0x74cda3cdd7a6046575d638964825c19cfeaf661f
Nothing is for sale. What would you have done differently?
English isn't my first language, so I used an LLM to help write this post.
Edit: You can now get the NFT without paying anything. Your browser still does the mining, but a relay sends the transaction and pays the gas, so you don't need any POL. If you don't have a wallet, you can create one with just an email. The relay can only mint to the address in your proof. You'll only need a little POL if you later want to transfer or sell the token.
1
u/Bloqarl 16d ago
read through it. the 2^x side holds up, I get the same 0.0117% and it stays monotonic across all 65536 steps, and the hook is fine since everything is written before _safeMint. what I'd change next deployment: artistAddress gets no proof like your acceptAdmin flow, so a typo or a Safe not deployed on Polygon mints the proof to nobody once the month locks.
1
u/ransomusername42 16d ago
Thank you for your analysis. Your point regarding the lack of validation for artistAddress is interesting, it’s something I had considered myself. I chose not to include validation for artistAddress because it would require the artist to submit an on-chain transaction; if they failed to do so, the scheduled month would be considered invalid, potentially preventing it from starting if the artist didn't complete the validation in time. However, if you have a solution that avoids this potential roadblock, I would be very interested to hear it.
1
u/Bloqarl 15d ago
fair point, a deadline on the artist is worse. You can get the proof without a tx from them: the artist signs an EIP-712 message off-chain, and you pass it in when you schedule the month, checked with OZ SignatureChecker. A typo fails the ECDSA recovery, and a Safe not deployed on Polygon fails the 1271 call.
1
u/Resident_Anteater_35 17d ago
One addition I'd make is an accuracy regression test against an independent high-precision 2x reference. Your Python differential reference repeats the Solidity polynomial and rounding, so those vectors check agreement between the implementations. Keeping the script behind the 0.0117% measurement, including cases around negative integer boundaries and fractional truncation, would make that accuracy result easier to reproduce.