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

[WIP] mark the end of block also with STOP #52

Closed
wants to merge 7 commits into from

Conversation

hiqua
Copy link
Contributor

@hiqua hiqua commented Nov 22, 2018

I think this change would make sense given the surrounding code and comments, but not completely sure. This fixes the bug with the empty contract:

pragma solidity ^0.4.24;

contract C{
}

Blocked by #57.

@ghost
Copy link

ghost commented Nov 22, 2018

DeepCode analyzed this pull request.
There are no new issues.

@hiqua hiqua requested a review from ritzdorf November 22, 2018 16:39
@ritzdorf
Copy link
Collaborator

  1. Definitely makes sense. Good catch.
  2. Don't you think we should also add Return, Revert and Selfdestruct here? Probably we should define this in a more central place like doesOpcodeEndBlock() and doesOpcodeEndExecution() or so, so that these checks are consistent everywhere.
  3. I guess we should also add it here:
    || rawInstruction.opcode == OpCodes.JUMPI
    This sparks a more general question, whether we want to keep both of them. (Background: Decompiler is more precise if it works, but function detection rarely does. I don't know why it doesn't work though.) I realized that a couple of recent PRs were only against the fallback variant. (mea culpa)
    @ptsankov was in favour of keeping the Decompiler in, maybe he can elaborate on its advantages.

@hiqua
Copy link
Contributor Author

hiqua commented Nov 23, 2018

I agree with everything you mention, and I have the same questions regarding Decompiler vs DecompilerFallback.

I think I'll first focus on having more tests before we do these changes, so that we can keep track of whether we introduce bugs or not.

Add a Python script to run securify on multiple input and see whether their
outputs match the ones previously saved, so that changes can be acknowledged
and bugs introduced can be fixed.
@hiqua hiqua force-pushed the fix_empty_contract_stack_bug branch from f5e7e4a to f7f4faf Compare November 27, 2018 15:21
@hiqua
Copy link
Contributor Author

hiqua commented Nov 27, 2018

For STOP it is clear that it fixes some things using the examples I have added on another branch (basically Securify does not fail on SafeMath anymore), I'm looking for examples for the other opcodes now so that we can compare.

@ritzdorf
Copy link
Collaborator

Isn't this an example for REVERT?

pragma solidity ^0.4.24;
contract C{
  function() public payable{
    revert();
  }
}

@hiqua
Copy link
Contributor Author

hiqua commented Nov 27, 2018

Yes, and it works also for the other opcodes, so perfect.

@hiqua
Copy link
Contributor Author

hiqua commented Nov 28, 2018

I've added the other opcodes and tests, if the changes are good for you I'll reorganize the commits and merge.

@@ -209,6 +209,30 @@ public static boolean isInvalid(int opcode) {
return "INVALID".equals(getOpName(opcode)) || opcode == INVALID;
}

/**
* Indicate whether the opcode terminates a basic block
* Ignores the case of JUMPI for which it depends on the CFG
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why does JUMPI not end a block?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the code there is a check on controlFlowGraph.get(rawInstruction.offset).contains(ControlFlowDetector.DEST_ERROR) when a JUMPI is encountered, meaning that Securify currently does not assume that this is the end of the block just because of this opcode. Ignoring JUMPI in this function was a way to refactor the code without changing the semantics of the basic blocks Securify currently builds.

@ritzdorf
Copy link
Collaborator

Can you briefly explain the changes that are going on in the 238 changed files? How does the end-to-end testing work? From where is it triggered?

@hiqua hiqua changed the base branch from master to end_to_end_testing November 28, 2018 10:44
@hiqua
Copy link
Contributor Author

hiqua commented Nov 28, 2018

Can you briefly explain the changes that are going on in the 238 changed files? How does the end-to-end testing work? From where is it triggered?

Sorry that should be clearer now, basically I want to wait until the end_to_end_testing branch is merged before we merge this. It just compares the current output with saved output so that we manually acknowledge the changes. See #57 for more details.

@hiqua hiqua force-pushed the end_to_end_testing branch 2 times, most recently from d970396 to b54522e Compare December 5, 2018 13:03
@hiqua hiqua changed the title mark the end of block also with STOP [WIP] mark the end of block also with STOP Dec 5, 2018
@hiqua
Copy link
Contributor Author

hiqua commented Dec 5, 2018

See #68.

@hiqua hiqua closed this Dec 5, 2018
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.

None yet

2 participants