Skip to content
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

Use error strings in smart contracts #81

Closed
8 tasks done
czepluch opened this issue May 22, 2018 · 14 comments · Fixed by #1499
Closed
8 tasks done

Use error strings in smart contracts #81

czepluch opened this issue May 22, 2018 · 14 comments · Fixed by #1499
Assignees
Labels
enhancement New feature or request P1 urgent, blocker, or makes life easier forever
Milestone

Comments

@czepluch
Copy link
Contributor

czepluch commented May 22, 2018

Description

Since solidity 0.4.22 error strings are supported for revert and require:

pragma solidity ^0.4.22;

contract VendingMachine {
    function buy(uint amount) payable {
        if (amount > msg.value / 2 ether)
            revert("Not enough Ether provided.");
        // Alternative way to do it:
        require(
            amount <= msg.value / 2 ether,
            "Not enough Ether provided."
        );
        // Perform the purchase.
    }
}

Adding this to the smart contract will make it easier to debug where things go wrong in a function. It also makes the terrible work flow of removing requires to figure out which require is failing obsolete.

Tasklist

@czepluch czepluch added the good first issue Good for newcomers label May 22, 2018
@loredanacirstea loredanacirstea added this to the Red Eyes milestone Jul 30, 2018
@LefterisJP
Copy link
Contributor

@loredanacirstea Do you think you can add them in this contract change (red eyes testnet 4)? I would say it's good to take advantage of the redeployment to include them.

@loredanacirstea
Copy link
Contributor

Yes, added the milestone now.

@loredanacirstea
Copy link
Contributor

loredanacirstea commented Aug 6, 2018

Just some notes:

Aside from these mentions, I am ok with just using some error strings right now and re-evaluating them after standards are clarified, because I assume it will take a while.

@loredanacirstea
Copy link
Contributor

The revert error strings cannot be implemented right now in a satisfactory manner, as commented in #213 (comment)
I would move this to the Ithaca milestone and address it after #215.

@LefterisJP ?

@LefterisJP
Copy link
Contributor

@loredanacirstea Was looking at the Testnet 4 milestone and was wondering why this is not there yet. I understand now. Sure let's do this. It's not a requirement right now at all anyway.

@LefterisJP LefterisJP modified the milestones: Red Eyes Testnet 4, Ithaca Aug 9, 2018
@loredanacirstea loredanacirstea added lower priority P3 keeping somebody waiting possibly and removed good first issue Good for newcomers lower priority labels Jan 7, 2019
@pirapira pirapira removed this from the Ithaca milestone Jan 31, 2019
@pirapira pirapira added enhancement New feature or request and removed P3 keeping somebody waiting possibly labels Feb 4, 2019
@pirapira pirapira added the P2 demanded by somebody label Mar 28, 2019
@pirapira
Copy link
Contributor

P2 because I heard error strings would have saved our time today.

@pirapira pirapira changed the title Use error strings in smart contracts Use error strings in smart contracts (first try enabling coop settle) Apr 16, 2019
@pirapira

This comment has been minimized.

@pirapira pirapira changed the title Use error strings in smart contracts (first try enabling coop settle) Use error strings in smart contracts Apr 16, 2019
@pirapira pirapira self-assigned this Jun 21, 2019
@pirapira

This comment has been minimized.

@pirapira
Copy link
Contributor

If we recover cooperativeSettle() and add a two-character comment on each of require, the runtime codesize will be 28835 bytes, which exceeds the deployable limit of 24576 bytes.

@pirapira
Copy link
Contributor

Whether we optimize or not, any message that fits 32 bytes seems to compile into the samely sized runtime code. So no need to go for cryptic "a" "b" "c" style messages.

@pirapira
Copy link
Contributor

I’ll just add somewhat recognizable comments under 32 bytes.

@pirapira
Copy link
Contributor

This depends on #401.

@palango
Copy link
Contributor

palango commented Feb 19, 2021

Just tried the old PR again, we're still running into code size issues.

Blocked by #401

@karlb karlb mentioned this issue Jun 29, 2021
21 tasks
@karlb
Copy link
Contributor

karlb commented Jun 29, 2021

See #1435 for more space saving.

@palango palango self-assigned this Jul 29, 2021
@palango palango mentioned this issue Jul 29, 2021
19 tasks
@palango palango added P1 urgent, blocker, or makes life easier forever and removed P2 demanded by somebody labels Jul 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request P1 urgent, blocker, or makes life easier forever
Projects
None yet
6 participants