Skip to content

Turn Error into an ADT and add require/assert#389

Open
axic wants to merge 6 commits into
argotorg:mainfrom
axic:revert2
Open

Turn Error into an ADT and add require/assert#389
axic wants to merge 6 commits into
argotorg:mainfrom
axic:revert2

Conversation

@axic
Copy link
Copy Markdown
Contributor

@axic axic commented May 15, 2026

No description provided.

Comment thread std/std.solc
@@ -80,6 +81,7 @@ export {
revert,
revertEmpty,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering removing this, since we can use revert(Error.Empty).

Comment thread test/imports/import_std_minimal.solc Outdated
@axic axic force-pushed the revert2 branch 2 times, most recently from 099d8f4 to 7764171 Compare May 18, 2026 09:04
Comment thread test/examples/dispatch/miniERC20.solc Outdated
function transferFrom(src:address, dst:address, amt:uint256) -> bool {
let msg_sender = caller();
require( balances[src] >= amt /* "token/insufficient-balance" */
myrequire( balances[src] >= amt /* "token/insufficient-balance" */
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it would make sense to exercise the new Error system here - if I understand it correctly then this should be

require( balances[src] >= amt /* "token/insufficient-balance" */
        , Error.Error(0x746f6b656e2f696e73756666696369656e742d62616c616e6365)
        )

Probably no need to change it in other tests, but miniERC20 is one of our main ones.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error encoding follows the ABI, so it is sha256(<errorname>(<arguments>))[:4] (truncating to the first 4 bytes). Since error and function names cannot have forward slashes (/), the original error token/insufficient-balance cannot be represented. This is the reason I haven't changed it.

We need to change it to something like InsufficientBalance() if we follow Solidity's model.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mbenke updated the dispatch tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants