Solidity Bugs — गलतियां खोजें और ठीक करें
हर Solidity developer ये गलतियां करता है। Deployment से पहले इन्हें पहचानना और ठीक करना सीखें।
Solidity बेरहम है। एक storage keyword भूलने से आपका पूरा contract बर्बाद हो सकता है। एक unchecked return value सभी funds को drain कर सकता है। Debugging skills optional नहीं हैं — वे survival हैं।
Top 5 आम Bugs
Uninitialized Storage Pointer
storage या memory के बिना struct declare करने से slot 0 का एक खतरनाक pointer बनता है।
Public vs External Visibility
केवल externally called functions के लिए public का उपयोग करना calldata को memory में copy करने में gas बर्बाद करता है।
Reentrancy Without Guards
State updates से पहले external calls आपके contract के recursive exploitation की अनुमति देती हैं।
Unchecked Return Values
call या transfer से return values को ignore करने से transfers चुपचाप fail हो जाते हैं।
tx.origin for Auth
msg.sender की जगह tx.origin का उपयोग करना phishing attacks को सक्षम करता है।
उदाहरण: Storage Pointer Bug
❌ Bug: Uninitialized Pointer
struct User {
address addr;
uint256 balance;
}
mapping(uint256 => User) users;
function addUser(uint256 id) public {
User user; // Defaults to storage slot 0!
user.addr = msg.sender;
user.balance = 100;
// Overwrites storage slot 0 instead of users[id]
}✅ ठीक किया: Explicit Storage
struct User {
address addr;
uint256 balance;
}
mapping(uint256 => User) users;
function addUser(uint256 id) public {
User storage user = users[id]; // Explicit storage
user.addr = msg.sender;
user.balance = 100;
// Correctly writes to users[id]
}समाधान: हमेशा struct variables को storage या memory के साथ declare करें। इसे छोड़ने पर यह storage slot 0 को default करता है, जो state को corrupt करता है।
अक्सर पूछे जाने वाले प्रश्न
सबसे आम Solidity bug कौन सी है?
Storage pointer bugs beginners के लिए सबसे आम हैं। Storage pointer को initialize करना भूलने पर slot 0 का एक खतरनाक reference बनता है, जो critical state को overwrite कर सकता है।
Solidity को effectively कैसे debug करें?
Foundry tests का उपयोग vm.prank, vm.expectRevert, और console.log के साथ करें। Edge cases के लिए unit tests लिखें। Common patterns पकड़ने के लिए Slither जैसे static analysis tools का उपयोग करें।
क्या Solidity bugs अन्य languages से अलग हैं?
हां। Solidity में unique footguns हैं: immutable blockchain state, gas costs, reentrancy, और storage vs memory semantics। Traditional debugging tools काम नहीं करते — आपको specialized testing frameworks चाहिए।
Solidity Debugging में माहिर बनें
50+ real-world challenges के साथ bugs खोजने और ठीक करने का अभ्यास करें। उन patterns को सीखें जो bugs होने से पहले ही उन्हें रोकते हैं।
अभी शुरू करें →