-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support reason string in assert #1686
Comments
Should this issue be renamed to |
Yes, this refers to |
Thought that was why, I just wanted to clarify. Will there be any limitations on the |
This is yet to be decided. I think I hope there will be a way to either agree on an encoding scheme for error codes + messages or to include such a scheme in the ABI or Natspec. If this happens, it could have an error code and optional message. |
Perhaps we should just do a quick and easy version now: Error return data is either empty or is an ABI-encoding with the signature Future versions of this specification have to increment the version number. This also forces the first 31 bytes to be zero which leaves ample room for further "selectors" (for example, the first four bytes could encode a (non-zero) function selector in the future). |
Very excited to follow this closely :-D, I am not sure how to contribute, but I'm going to try :-D |
To support tracking of
This way a debugger with having access to the sources could figure out which assertion terminated. |
@axic That is a genius idea and very forward thinking! +1000; Too often we are forced into printf-style debugging with solidity and while passing reason strings around is a good step, it still doesn't allow us to utilize modern debuggers with breakpoints, traces, watches, etc. Op-code additions are a serious thing, I imagine, and we should aim for the moon here to get it right. |
@axic +1 Yeah I think that would be just as if not more useful than the "message" or "reason" strings requested in various issues. How difficult would it be to implement "source location identifiers" and is there anything I can do towards making this a reality? This is the sort of thing that's going to save so much time the quicker it happens the better. |
An idea regarding source location identifier is to reuse parts of the source mapping: e.g. The debugger then needs to look up the source mapping (emitted by the compiler) to find the actual code in source. |
@axic You mean offset EDIT: I'm not sure I understand how that fits into 5 bytes. |
Sorry, it was late. |
Perhaps a much better optimisations would be the following: insert a unique index for each assert and have a translation table ( Then again, if debugging is needed, the sources could be recompiled with the same settings to figure out which assertion terminated. This should only pose an overhead of 2 or 3 bytes per assertions assuming there are only <=2048 assertions in the input. |
+1 |
-1 only on the implementation details. My understanding of proposal is that ABI will be extended to include a mapping of <revertReturnValue => String>. And compiler will put a return value on the stack during crash. And the client can translate those strings if necessary to any end-user language. I don't see why an additional value needs to be put on the stack before revert. This seems unnecessary. Alternate proposal:The client can already see where the program crashed by checking the program counter. Simply add a mapping of <program counter => String> for assertion operations having names. Or possibly <program counter => assert code> and <assert code => String> if you want a normal form database. This saves adding and additional code to programs. Also, you can add assertion language retroactively to existing contracts! Of course the compiler will need to treat these special REVERT assembly instructions specially: you cannot optimize by merging code paths if it results in two distinct "colors" of REVERT instructions being merged. |
It would be a great idea, I'm still stucking on debugging. |
Changed the title again, I thought we had a different issue for require. |
Above, we were discussing if it returned strings should calculatable at runtime or if compiletime is good enough. I still don't see why runtime is necessary. For-loops are an exceedingly rare commodity in this world. Also, the ABI can't be spoofed, it is generatable by anybody that has access to the source code. |
@fulldecent If |
Is the revert() error message a Solidity thing or a Web3.js issue? The latter potentially being a problem with tool like the Web3.js library not being updated yet to retrieve the error code/msg return at the low-level Ethereum interface, and bubble it up back to the caller? Also, can someone sort out the following rumors I've heard? Is an error code supported by revert() or an error message, or both? I read somewhere while scouring the Web that the error message idea was dropped because of concerns there could be DDOS-like attacks against the Ethereum network, from people spamming the network with method calls that would easily trigger a If strings error messages are still being considered, what effect does this have on the stipend as far as the error message possibly not being propagated because of a lack of gas? |
Incorrectly metered resource consumption ("DDOS") is not a concern for the language, but only for the VM, and I don't think it is an issue here. Currently, strings are implemented (note that this has been finalized for Solidity) as error messages with a possible extension to allow any ABI-encoded data. Not sure what exactly you mean with "effect [...] on the stipend". This mechanism uses |
@chiro-hiro Here is exactly how the alternate proposal works: Contract codepragma solidity ^0.4.21;
contract Math {
function addPositiveNumbers(int addend, int otherAddend) external pure returns (int sum) {
require(addend >= 0, "Parameter one must be positive");
require(otherAddend >= 0, "Parameter two must be positive");
sum = addend + otherAddend;
assert(sum > addend, "I thought adding was monotonic!");
}
} Byte code
ABI
DiscussionYes, you do have access to the revert reasons at run time, not compile time. However at compile time there is no need to place english-language strings into the byte code. Also my approach allows you to extend this concept by adding a file math-zh.po:
|
@fulldecent It's make scene, an offset of message could be better than put a string inside |
It seems this was added to the language but I can't find a way on obtaining the messages. Does anyone hasmore information about this? E.g. see my test contract with source code on the Ropsten node: Last transaction failed but I can't find the message that should be written by it. |
@devedse with web3js or at least with the latest truffle (version 5) you can get the revert reason from the exception e.g. try {
await contract.myMethodCall();
} catch (error) {
// error.reason now populated with an REVERT reason
console.log("Failure reason", error.reason);
} |
Oh so cool! |
@jamesmorgan, I see, I assume however that you can't do this on transactions that have been executed on the blockchain though? |
@jamesmorgan I can see the |
Any progress in that? I still can't see revert messegas on ethereum testnet (while it works very fine on TRON). The error I got has this format:
|
@mscherer82 there is no indication why it should not work. Perhaps you are using a client that does not support it? |
Did you set the testnet to be byzantium-compatible? |
Here is a bash script to fetch revert reason: |
Following the above previous example, how do you access "RevertStrings" data at run-time? #: Math: addPositiveNumbers:4 Best, |
This issue has been marked as stale due to inactivity for the last 90 days. |
Hi everyone! This issue has been automatically closed due to inactivity. |
Depends on EIP 140 (
REVERT
) to be fully accepted.would basically translate to
(Issue split off #1130.)
The text was updated successfully, but these errors were encountered: