Strcmp Invalid Read of Size 1 0xf Is Not Stacked
Error: VM Exception while processing transaction: revert.
A Guide to Problem-Solving in Solidity.
Problem-solving in Solidity can be a nightmare. It lacks a console.log()
and even if there was 1, Solidity by nature reverts the entire state and yous would non get it anyway. Then there is Error: VM Exception while processing transaction: revert,
the almost mutual and frustrating error of them all. Below is a checklist to ensure that you cover all the basics when debugging Solidity errors.
Earlier going through the debugging list you should have your contract in Remix. Preferably have it connected to a local blockchain instance (such as Ganache) so that you can utilize the Truffle debugger or the dApp tools debugger.
Call up that when debugging on Remix any lawmaking changes you brand means that you need to redeploy your contracts. If y'all accept a couple of contracts that need to talk to each other or accept a rather tedious inheritance construction, attempt using the truffle-flattener
to take away some of the frustration of getting your contracts fix on Remix.
When a transaction reverts in your control line (where you are running your compiler) yous should notice an error stack that looks something like:
Error: VM Exception while processing transaction: revert Market registered
at getResult … json-rpc-provider.js:40:21)
at exports.XMLHttpRequest.request … web.js:111:xxx)
at exports.XMLHttpRequest.dispatchEvent … XMLHttpRequest.js:591:25)
at setState … XMLHttpRequest.js:610:14)
at IncomingMessage.<anonymous> … XMLHttpRequest.js:447:13)
at IncomingMessage.emit (events.js:187:15)
at endReadableNT (_stream_readable.js:1081:12)
at process._tickCallback (internal/procedure/next_tick.js:63:19)
Sometimes these stacks do not help you in the slightest (similar in the above example), and other times they will tell you lot where in the contract information technology failed, with the line number first, followed by the column within that line.
at YourContract…the error…YourContract.sol: 111:21 )
This can be very useful to first getting an thought of where and why your contract call is failing.
Solidity errors and what they mean.
Glossary:
Wrapping over/under: Numbers in Solidity accept limited storage infinite. If yous attempt to make a number bigger than its allocated storage space information technology volition clock over to its smallest value.
These are the errors:
-
OUT_OF_GAS: "out of gas"
⇐ Your contract call used too much gas. At that place are a couple of reasons this could occur, such as a recursive telephone call (office A calls office B and and so office B calls function A…), your function is doing a adding that is besides complex, as well as calling a chain of functions that is too long. -
STACK_UNDERFLOW: "stack underflow"
⇐ A number wrapped under and is now at its max value. The minimum value of auint8
is of grade 0, and the max is 255. So if we have auint8
number that is 0 and we minus i, information technology will underflow to the max value. I.eastward:
uint8 goingToUnderflow = 0;
goingToUnderflow - 1;
goingToUnderflow is now equal to 255.
-
STACK_OVERFLOW: "stack overflow"
⇐ A number somewhere wrapped over and is now at its minimum value. The max value of auint8
is 255. So if nosotros have auint8
set to 255 and we add together 1, information technology will underflow and the value will exist 1. E.m:
uint8 goingToOverflow = 255;
goingToOverflow + i;
goingToOverflow is now equal to 1.
-
INVALID_JUMP: "invalid JUMP"
⇐ Invalid jumps burn down all remaining gas similar anassert()
. This error happens when a function call jumps out of bounds (e.g assortment out of bounds). This is done to punish the caller for attempting to do something they weren't supposed to do. "Jump" is an assembly term for going from one section of code to another. The error is basically a function phone call that is invalid at an associates level. -
INVALID_OPCODE: "invalid opcode"
⇐ Somewhere yous are trying to execute opcode that does non be. The opcode tin be a function that does not exist or a revert (reverts execute a not-existent opcode). -
REVERT: "revert"
⇐ Something somewhere broke. This revert will render the remaining gas. The most common error. -
STATIC_STATE_CHANGE: "static state change"
⇐ If you have aview
function and you endeavor to alter a land value you lot volition become this error.
All promise is lost. Where to offset?
- Flatten your contract by running the control:
truffle-flattener.\contracts\YourContracts.sol >> flatContract.txt
on your contract. The>> flatContract.txt
will save the flattened contract in the.txt
file. If you don't do this it volition print the apartment contract in the console. - Put your flattened contracts into Remix. A elementary copy paste, and naming the file.
- Connect your Remix to your local blockchain. In the run tab, select environment and ensure that it is set up to Web3 provider. A popular up volition appear that will ask you if you are sure (you are) and ask for the local host port, the default is 8545.
- Deploy your contract. In the run tab there is a driblet down under the value field, where you can select your contract and then either enter the constructor fields (besides the deploy button is a driblet down which makes it easier) or enter the address if your contract is deployed on a exam cyberspace (make sure you lot are connected to the test net and that you lot have the code).
Run the declining function.
Changes to endeavor in your code: change the lawmaking, re-deploy it in Remix, and then run the failing office again and see if information technology passed. If it did and then Bob'due south your uncle, yous've identified the problem. Go and fix it!
- Add an error message to your
revert
s. This should go without saying but your reverts should all have error messages. Don't forget to re-deploy your contract subsequently every code alter. E.g:revert(theCheck, "The check is failing")
. - If you have any
assert
s, comment them out. If yourassert
is failing (and they should never be) at that place is a nice problems somewhere waiting for yous. Nosotros can accept a improve wait at this in the debugging phase. Remember what you change so that y'all tin re-implement information technology if it's not what's making the contract telephone call fail. - Running out of gas? Running out of gas means something, somewhere in your contracts function is either being called over and over until it finishes your allocated gas, or a function call is doing something horribly incorrect and is eating all the gas. Whatever the cause, something is doing something it shouldn't. Information technology will virtually likely become apparent in the debugging.
- Check the obvious: values and modifiers. If y'all have a modifier, are you certain that information technology's not failing? Check that all of your involved values are what you expect them to be by making them public.
Still scratching your head? That's okay, we still take the debugger!
Time to jump into a debugger to figure this out.
- Re-implement all the code that you accept previously removed. If none of it was making the function fail and so it should go back in. Run the declining function again and grab the transaction hash from Remix.
2. Run the Truffle debugger in a command line in your projects directory. Make sure in your truffle.js
local host accost is the same as your Ganache local port. Run truffle debug 0xf
where 0xf is your transaction hash. (They wait like this: 0x1ed2fcb0d555e1398287bd2ae0319d623441a1113446b848cc9bf3148314bc54
)
3. The truffle debugger (or the dApp tool debugger) allows you to step through your function calls ane call at a time. You tin encounter exactly where the role call fails. Go on in mind that these tools are notwithstanding being built and so some of the functionality may not work seamlessly just yet.
You will be able to see where your contract phone call fails because it will be at the end of your step through. If it's failing on something that shouldn't neglect, like an event or a bare line of lawmaking, chances are you are running out of gas.
If all else fail.
If you lot really don't know why it'due south failing and can't see why it should exist, try deploying it on a exam net. As much as this may seem counter-intuitive, the tools nosotros are using are nevertheless relatively in their infancy. The tools themselves could exist the bugs. Deploy your contracts to your favourite test internet and effort interacting with them through Remix. It should be noted though that it is rarely the tool and if it is the tool you should make a detailed problems study on the respective tools GitHub so that they tin ready it.
Good (bug) hunting!
This article would non have been possible without the amazing developer team at Linum Labs! A special shout out to our atomic number 82 blockchain developer Ryan Noble, who played an instrumental part in writing this article.
Tools
Resources:
Source: https://medium.com/linum-labs/error-vm-exception-while-processing-transaction-revert-8cd856633793
0 Response to "Strcmp Invalid Read of Size 1 0xf Is Not Stacked"
ارسال یک نظر