-
Notifications
You must be signed in to change notification settings - Fork 409
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
Extract revert messages #6226
Extract revert messages #6226
Changes from 10 commits
ca399c7
1fd7512
88101b9
adb2ce9
dea12cd
72504b6
1239db4
073e8ef
c721e79
8ee2d7f
159f2a2
4344ef0
277c92d
d9b3e48
076bf5c
1aea8fa
8d44192
2e2328f
9246b40
d85ec07
af73bfc
bf32923
c262a7f
6561eb0
b2a04bc
1803115
6aa5cfe
91cdc4a
19d066f
6603120
056a460
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ public class TransactionSubstate | |
private const int RevertPrefix = 4; | ||
|
||
private const string RevertedErrorMessagePrefix = "Reverted "; | ||
private readonly byte[] ErrorFunctionSelector = { 0x08, 0xc3, 0x79, 0xa0 }; | ||
|
||
public bool IsError => Error is not null && !ShouldRevert; | ||
public string? Error { get; } | ||
|
@@ -68,6 +69,7 @@ public TransactionSubstate(EvmExceptionType exceptionType, bool isTracerConnecte | |
|
||
ReadOnlySpan<byte> span = Output.Span; | ||
Error = TryGetErrorMessage(span) | ||
?? TryUnpackRevertMessage(span) | ||
?? DefaultErrorMessage(span); | ||
} | ||
|
||
|
@@ -104,4 +106,36 @@ private string DefaultErrorMessage(ReadOnlySpan<byte> span) | |
return null; | ||
} | ||
} | ||
|
||
private unsafe string? TryUnpackRevertMessage(ReadOnlySpan<byte> span) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be unified with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They are similar but not the same:
Still, maybe there's something to be done to reduce the amount of code. What do you think @benaadams? |
||
{ | ||
if (span.Length < RevertPrefix + sizeof(UInt256) * 2) | ||
{ | ||
return null; | ||
} | ||
|
||
if (!span[..RevertPrefix].SequenceEqual(ErrorFunctionSelector)) | ||
{ | ||
return null; | ||
} | ||
|
||
try | ||
{ | ||
int start = (int)new UInt256(span.Slice(RevertPrefix, sizeof(UInt256)), isBigEndian: true); | ||
if (start != sizeof(UInt256)) | ||
{ | ||
return null; | ||
} | ||
|
||
int length = (int)new UInt256(span.Slice(RevertPrefix + sizeof(UInt256), sizeof(UInt256)), isBigEndian: true); | ||
ReadOnlySpan<byte> binaryMessage = span.Slice(RevertPrefix + sizeof(UInt256) + sizeof(UInt256), length); | ||
string message = string.Concat(RevertedErrorMessagePrefix, System.Text.Encoding.UTF8.GetString(binaryMessage)); | ||
|
||
return message; | ||
} | ||
catch (Exception e) when (e is OverflowException or ArgumentOutOfRangeException) | ||
{ | ||
return null; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there was an extra colon in the prefix, i.e.
Reverted: {message}
this would become compatible with Geth. I want to point it out since you're already making a breaking change.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an ongoing discussion on standarization of error messages: ethereum/execution-apis#463.