-
Notifications
You must be signed in to change notification settings - Fork 20k
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 for require reason #18360
Comments
Does anybody have information on this? |
This feature will definitely save a lot of development and debugging effort. 👍 |
So, geth is an ethereum client. However, the data returned does not wind up in the logs, so it's not accessible from the outer scope of the transaction. It might be that you are requesting something like this: #15508 . However, I'm not quite sure what it would mean to "support" it -- I guess that depends on the usecase you have in mind. If we can agree with others (Parity, Ganache, etc) what is needed, that would make it actionable. |
I have read that Ganache and Truffle already have this. Parity is yet to implement this. I hope this gives the idea of what I am looking for. Stackoverflow Question. |
any progress on this? |
In case you are looking for it, there is a similar issue (feature request) in parity: openethereum/parity-ethereum#8068 |
Ah now I get it. So essentially, our tracers are just javascript code. It should be fairly simple to add the reason into the call-struct. I'll assign this to @karalabe for now , as he's the original author of the calltracer |
@karalabe If you prefer, we could consider using https://gitcoin.co/requests to get this issue funded. |
Issue Status: 1. Open 2. Started 3. Submitted 4. Done This issue now has a funding of 700.0 DAI (700.0 USD @ $1.0/DAI) attached to it.
|
Issue Status: 1. Open 2. Started 3. Submitted 4. Done Workers have applied to start work. These users each claimed they can complete the work by 5 months from now. 1) daniyal-24 has applied to start work (Funders only: approve worker | reject worker). testing testing testing testing testing testing testing testing testing testing testing testing I'm interested in working on this but I'm not entirely sure what exactly the requested feature is. Is the idea to write a new built in tracer which nicely prints the argument to REVERT? Learn more on the Gitcoin Issue Details page. |
I ended up submitting it, and it got funded! Thanks, @ceresstation! |
@pcowgill do you have a preference regarding who takes on this issue? |
I'm interested in working on this (I've expressed interest on the gitcoin page). To make sure I understand, what exactly is the end outcome that we want? At the moment the |
The revert reason is already recorded in the return value of the contract call. The problem is that, web3.eth.sendTransaction does not provide the return value, since the transaction is not yet confirmed by the time the sendTransaction is invoked. There are 2 possible ways to retrieved the return value (and the revert reason) of a confirmed transaction: Theorically, (1) can prefectly replay the past tx, and get the correct result, but geth doesn't do it properly now, so the result will or will not be correct. I'm not sure about other client. To perfectly replay a past tx, a node need to have the pre-state of a block (archive mode), and replay all txs in the block prior to the given tx. (2) should be perfect in the long term, but requires a protocol change. |
Okay that makes sense. Am I right in thinking that the inconsistency of (1) is just a consequence of not running an archival node, rather than a geth specific problem? If that's the case then this isn't really something that can be fixed by geth and this issue should be closed? |
As I've already said, to replay a tx to get the correct result, a node need to: (a) can be achieved by running geth in archive mode |
Right, so this issue should be closed then? @holiman |
If that's the case, then in order for this to work in |
Any update on this? Could be done like done in https://github.com/pertsev/web3_utilz/tree/master/revert%20reason |
To get the correct past tx reason, clients (geth) still need to correctly reconstruct the pre-state of the tx. Currently you can still get the estimated result, which might be correct ~90% of the time. To get the imcoming transaction revert reason, the best place to do is in the wallet/extension. I'm working on an extension (alternative to MetaMask), which asynchronously fetch the transaction result while waiting for user confirmation. |
hi, geth always support the reason string in tx. but you need asynchronously add a event tracking to extract the failed tx string. see this patch: eventeum eventeum/eventeum#80 web3j's code snippet: |
i think this is not geth scope, please close this issue. |
I successfully managed to extract revert reasons (from a simulated blockchain) in my tests with the following code: func errorReason(ctx context.Context, b *ContractBackend, tx *types.Transaction, blockNum *big.Int) (string, error) {
msg := ethereum.CallMsg{
From: b.account.Address,
To: tx.To(),
Gas: tx.Gas(),
GasPrice: tx.GasPrice(),
Value: tx.Value(),
Data: tx.Data(),
}
res, err := b.CallContract(ctx, msg, blockNum)
if err != nil {
return "", errors.Wrap(err, "CallContract")
}
return unpackError(res)
}
var (
errorSig = []byte{0x08, 0xc3, 0x79, 0xa0} // Keccak256("Error(string)")[:4]
abiString, _ = abi.NewType("string", "", nil)
)
func unpackError(result []byte) (string, error) {
if len(result) < 4 || !bytes.Equal(result[:4], errorSig) {
return "<tx result not Error(string)>", errors.New("TX result not of type Error(string)")
}
vs, err := abi.Arguments{{Type: abiString}}.UnpackValues(result[4:])
if err != nil {
return "<invalid tx result>", errors.Wrap(err, "unpacking revert reason")
}
return vs[0].(string), nil
} Note that After a transaction failed, you usually hold a ( |
Or you can use https://chrome.google.com/webstore/detail/ezdefi/ejeemacpidnaejkhpbmfkadhgjhnolaa instead of MM, and you can see the revert reason clearly on confirmation dialog, or tx history UI. |
We already support it for EstimateGas, and still a open PR for EthCall(Waiting for merging) #21083 |
Great news @rjl493456442 @MariusVanDerWijden that I was wondering if the revert reason is accessible as a special error type field returned by What do you think about adding a public error type like And thanks @rjl493456442 for adding |
Hi @sebastianst
Do you mean you want to use the Geth as the library and call |
Exactly :) we use go-ethereum in go-perun and in a few places, we'd react differently to different revert reasons. E.g., here we can currently just check whether a general tx failed error occurred. We plan to change our contracts to emit standardized revert reasons, so being able to extract the revert reason directly from an Also happy to use the new Go error semantics. Then we could do var rerr *ethereum.TransactionRevertedError
if errors.As(err, &rerr) && rerr.Reason == "ALREADY_REGISTERED" {
// handle ALREADY_REGISTERED revert error...
} |
I'm also using the Geth libs (using |
@sebastianst Marius told me that you are using the |
Yes I also expected this to be a problem for when using the {
"jsonrpc": "2.0",
"id": 1,
"error": {
"code": -32000,
"message": "some error",
"reason": "revert reason"
}
} Then the eth client could check for the existence of this field and assemble it back to a |
No, it's impossible to add another field e.g. |
This is now implemented as of #21083 The new format is
We chose this because |
How about a special revert message when a function selector doesn't exist? |
Hi ,
As of Solidity 0.4.22, we can have string reasons as part of
require
orrevert
functions. But this seems to be not supported in Geth. Here is the reference.So is it true the Geth doesn't support it yet? I have been using Geth 1.8.16 Linux. Have checked the latest change log for 1.8.20. Couldn't find anything on that.
Is Geth going to provide this soon if not already? If providing already, may I know which version I can use?
Is there any work around I can come up with?
Here is my etherum stack exchange question.
The text was updated successfully, but these errors were encountered: