Add assert_msg(cond, "message") emitting Solidity Error(string)#1399
Add assert_msg(cond, "message") emitting Solidity Error(string)#1399g-r-a-n-t merged 2 commits intoargotorg:masterfrom
assert_msg(cond, "message") emitting Solidity Error(string)#1399Conversation
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fb5af0b111
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
0feac7a to
9151f04
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9151f04914
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
9151f04 to
404023c
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 404023ca5e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
404023c to
35defdb
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Proposal: Define assert_msg in terms of Text aka DynString: use super::abi::Text
pub fn assert_msg(_ b: own bool, _ message: own Text) {
if !b {
let (ptr, len) = encode_calldata(0x08c379a0, message)
ops::revert(offset: ptr, len: len)
}
}(this might increase gas usage) and remove the hir changes. There's an issue in hir to be solved, but the current solution isn't the right one. I think we need to modify the type unifier so that it imposes an |
35defdb to
97db8e8
Compare
|
@sbillig ok, made the requested change. |
97db8e8 to
00ce4f2
Compare
|
I think the abi-encoded payload is wrong. I'm rebasing and investigating. |
|
Here's what the agent says: Change assert_msg from: let (ptr, len) = encode_calldata(0x08c379a0, message) to: let (ptr, len) = encode_calldata(0x08c379a0, (message,)) with a short comment explaining why. Why: encode_calldata expects its second argument to represent the full ABI payload after len || bytes but Error(string) has one ABI argument, so it needs the single-argument head first: offset(0x20) || len || bytes So for "boom", the correct full revert data is: 08c379a0 |
25e5450 to
9c90b02
Compare
|
Ok, I did what the agent said 🫡 |
Introduces `assert_msg(b: bool, message: Text)` in the std prelude.
On `b == false` it reverts with the 4-byte selector `0x08c379a0`
(keccak256("Error(string)")[..4]) followed by the ABI-encoded
message, matching Solidity's `require(cond, "message")` /
`revert("message")`.
9c90b02 to
5e31d06
Compare
|
...and added another test that covers this. |
Introduces
assert_msg<const N: usize>(b: bool, message: String<N>)inthe std prelude. On
b == falseit reverts with the 4-byte selector0x08c379a0(keccak256("Error(string)")[..4]) followed by theABI-encoded message, matching Solidity's
require(cond, "message")/revert("message").Also improves const-generic inference so a string literal can satisfy a
generic
String<N>parameter without an annotation at the call site:when a string literal is passed to a parameter of shape
String<N>andthe inference key for
Nappears only in that one parameter, thechecker pins
Nto the literal's min length. Keys shared acrossmultiple parameters are left alone so the other arguments (e.g.
[u8; N]) still drive inference forN.Implements #1348