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

[recreated] Detect read function aborting by messaged require statement #276

Conversation

hakumai-iida
Copy link
Contributor

[Reposted because the repository was recreated]

Dear all:

If a require statement with a message aborts the reading function, an unexpected value may be returned as a response.

For example, if you call the following function,

function testC3( uint val ) public pure returns( uint256 ){
  require( val != 0, "aborted by testC3" );

  return( 0 );
}

The following response will be returned.

// Succeeded: testC3( 1 )
["0": 0]

// aborted: testC3( 0 )
["0": 3963877391197344453575983046348115674221700746820753546331534351508065746944]

If the reading function is aborted by a require statement that has a message, it seems that the data with the following configuration will be returned.(By the way, if there is no message specified in the require statement, [0] bytes will be returned as a response, so require could not be detected.)

byte[00-31]: 08C379A000000000000000000000000000000000000000000000000000000000
byte[32-63]: 0000002000000000000000000000000000000000000000000000000000000000
byte[64-67]: length of require message
byte[68-(68+length)]: require message body

Since it is helpful to know whether the reading function was aborted by require statement, I made a simple correction and sent the pull request.
please confirm.

If you call the above sample function with the modified code, empty data will be returned with the following log

// Aborted: testC3( 0 )
read function aborted by require statement: aborted by testC3
["0": 0, "_abortedByRequire": true, "_errorMessageFromRequire": "aborted by testC3"]

Also, I have confirmed the operation by checking the operation with the following contract.

pragma solidity >= 0.5.0 < 0.7.0;

contract HelloWorld {
    //-----------------------------
    // test A
    //-----------------------------
    function testA1( uint val ) public pure{
      require( val != 0 );      // no message
    }

    function testA2( uint val ) public pure{
      require( val != 0, "" );  // empty string
    }

    function testA3( uint val ) public pure{
      require( val != 0, "aboreted by testA3" );
    }

    //-----------------------------
    // test B
    //-----------------------------
    function testB1( uint val ) public pure returns( string memory ){
      require( val != 0 );      // no message

      return( "hello, world" );
    }

    function testB2( uint val ) public pure returns( string memory ){
      require( val != 0, "" );  // empty string

      return( "hello, world" );
    }

    function testB3( uint val ) public pure returns( string memory ){
      require( val != 0, "aborted by testB3" );

      return( "hello, world" );
    }

    //-----------------------------
    // test C
    //-----------------------------
    function testC1( uint val ) public pure returns( uint256 ){
      require( val != 0 );      // no message

      return( 0 );
    }

    function testC2( uint val ) public pure returns( uint256 ){
      require( val != 0, "" );  // empty string

      return( 0 );
    }

    function testC3( uint val ) public pure returns( uint256 ){
      require( val != 0, "aborted by testC3" );

      return( 0 );
    }

    //-----------------------------
    // test D
    //-----------------------------
    function testD1( uint val ) public pure returns( uint256[5] memory ){
      require( val != 0 );      // no message

      uint256[5] memory temp;
      return( temp );
    }

    function testD2( uint val ) public pure returns( uint256[5] memory ){
      require( val != 0, "" );  // empty string

      uint256[5] memory temp;
      return( temp );
    }

    function testD3( uint val ) public pure returns( uint256[5] memory ){
      require( val != 0, "aborted by testD3" );

      uint256[5] memory temp;
      return( temp );
    }

    function testD4( uint val ) public pure returns( uint256[5] memory ){
      require( val != 0, "long message from testD4, abcdefghijklmnopqrstuvwxyz, ABCDEFGHIJKLMNOPQRSTUVWXYZ, 0123456789.abcdefghijklmnopqrstuvwxyz, ABCDEFGHIJKLMNOPQRSTUVWXYZ, 0123456789.abcdefghijklmnopqrstuvwxyz, ABCDEFGHIJKLMNOPQRSTUVWXYZ, 0123456789.abcdefghijklmnopqrstuvwxyz, ABCDEFGHIJKLMNOPQRSTUVWXYZ, 0123456789.abcdefghijklmnopqrstuvwxyz, ABCDEFGHIJKLMNOPQRSTUVWXYZ, 0123456789.abcdefghijklmnopqrstuvwxyz, ABCDEFGHIJKLMNOPQRSTUVWXYZ, 0123456789.abcdefghijklmnopqrstuvwxyz, ABCDEFGHIJKLMNOPQRSTUVWXYZ, 0123456789.abcdefghijklmnopqrstuvwxyz, ABCDEFGHIJKLMNOPQRSTUVWXYZ, 0123456789.abcdefghijklmnopqrstuvwxyz, ABCDEFGHIJKLMNOPQRSTUVWXYZ, 0123456789." );

      uint256[5] memory temp;
      return( temp );
    }
}

Then, thank you for the above.

@hakumai-iida hakumai-iida changed the base branch from develop to master September 26, 2020 21:46
@skywinder skywinder added enhancement New feature or request hacktoberfest 💸 gitcoin-bounty Earn money by helping with this issue! labels Oct 1, 2020
@gitcoinbot
Copy link

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


This issue now has a funding of 33.0 DAI (33.0 USD @ $1.0/DAI) attached to it.

@skywinder
Copy link
Collaborator

Thank you very much! Great addition!

And thank for represent test cases as well! As final addition before merge, I would like to setup test of feature on rinkeby network.

@hakumai-iida
Copy link
Contributor Author

Thank you for your reply.
Please check the code and operation.

@gitcoinbot
Copy link

@janus Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!

  • reminder (3 days)
  • escalation to mods (6 days)

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

@janus
Copy link

janus commented Oct 4, 2020

@gitcoinbot I received acceptance notification about 3 hours ago. Please I am on it .. I would update in 24 hours time.

@skywinder
Copy link
Collaborator

skywinder commented Oct 4, 2020

@janus would you like to add test as @hakumai-iida described above? is so, i will create separate bounty for that. (this bount reserved for @hakumai-iida (please, apply for this task in https://gitcoin.co/issue/matter-labs/web3swift/276/100023790)

@janus
Copy link

janus commented Oct 4, 2020

@skywinder Okay .. I would do as per your instruction

@hakumai-iida
Copy link
Contributor Author

@skywinder

Sorry for the my late action.
(I was going to apply once your check was complete.)

And, i tried to apply it, but it failed with the following error.
"There is already someone working on this bounty."

@skywinder
Copy link
Collaborator

No worries @hakumai-iida no it should be fine please try again and feel free to contact me by email if you need any support.

I Check Code is excellent.
just want to finish some automated tests before the merge 👍

@gitcoinbot
Copy link

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


Work has been started.

These users each claimed they can complete the work by 265 years, 10 months from now.
Please review their action plans below:

1) hakumai-iida has been approved to start work.

From github
#276

I checked the operation in the rinkeby test net, and the check completed successfully.

Learn more on the Gitcoin Issue Details page.

@skywinder
Copy link
Collaborator

dear @hakumai-iida ,
thank you for your outstanding work!
Since you already made PR, Please submit for this bounty. I would be happy to reward you!
Even more, I really appreciate the quality of your code and test coverage. So I will double the amount of this bounty upon submission.

Happy new year! 🎉

@skywinder skywinder merged commit 6eddd2c into web3swift-team:master Dec 31, 2020
@skywinder
Copy link
Collaborator

@janus
we need to cover it by tests it before the next major release
feels free to apply for updating tests. I will release bounty for this case!

@janus
Copy link

janus commented Dec 31, 2020

@janus
we need to cover it by tests it before the next major release
feels free to apply for updating tests. I will release bounty for this case!

Thanks. Let me have the url of the bounty.

@skywinder
Copy link
Collaborator

@janus there is no URL (yet). you have to create an issue and I will link bounty to it. 👍

@janus
Copy link

janus commented Dec 31, 2020

@janus there is no URL (yet). you have to create an issue and I will link bounty to it. 👍

Okay

@gitcoinbot
Copy link

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


Work for 64.0 DAI (64.0 USD @ $1.0/DAI) has been submitted by:


@hakumai-iida hakumai-iida deleted the detect_read_function_aborting_by_messaged_require_statement branch December 31, 2020 09:18
@hakumai-iida
Copy link
Contributor Author

dear @skywinder

I am glad the pull request merged without problems.
And I submitted the work on gitcoin.

Thank you for the double bounty!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request 💸 gitcoin-bounty Earn money by helping with this issue!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants