1

What is the meaning of following paragraph in the context of ISZERO & mishandled exception. I found an article at: enter link description here It says that:

Detecting a mishandled exception is straightforward. Recall that if a callee yields an exception, it pushes 0 to the caller’s operand stack. Thus we only need to check if the contract executes the ISZERO instruction (which checks if the top value of the stack is 0) after every call. If it does not, any exception occurred in the callee is ignored. Thus, we flags such contract as a contract that mishandles exceptions.

I have broken down it into small sentences and specified what I understood from it. Text uses pronouns which is making it difficult for me to understand it.

"1. Detecting a mishandled exception is straightforward. Recall that if a callee yields an exception, it pushes 0 to the caller's operand stack.”

Means that if callee is not handling exception, it pushes 0 onto the caller’s operand stack. But can the callee access caller’s stack if they are in different contracts? Also is this not a security violation?

“2. Thus we only need to check if the contract executes the ISZERO instruction (which checks if the top value of the stack is 0) after every call.”

Which contract? caller or callee?

“3. If it does not, any exception occurred in the callee is ignored.”

I think it depends upon the transfer mechanism ‘call’, ‘send’ or ‘transfer’. If the caller is using ‘transfer’, then the exception if it occurs in the callee’s contract would be propagated to the caller’s contract. Caller can’t ignore it. I am not able to understand it clearly.

"Thus, we flag such contract as a contract that mishandles exceptions."

Some body please guide me

Zulfi.

1 Answer 1

1
  1. The result of CALL opcodes is not pushed by callee. It is done by the opcode automatically. The callee do not have access to caller stack.

  2. You should check in the caller bytecode for the pair CALL/ISZERO of opcodes.

  3. I think you are right. It is possible to generate code where the pair CALL/ISZERO is not present and the code verifies a successful CALL, and conversely a pari CALL/ISZERO thad does no verification. But in anycase the code generated by solc should be pretty standard.

But you should consider that the paper is from 2017 and there were a lot of changes since then.

2
  • If we get a pair of CALL/ISZERO opcodes in the caller stack, does it mean that an exception occurred in the callee's contract and the callee did not handle the exception? & is this true in latest Solidity version?
    – zak100
    Jun 8, 2019 at 18:46
  • 1
    The pair CALL/ISZERO is checked in caller's bytecode not the stack. Its presence indicates the caller is making a call and it is checking the result. It doesn't indicate the callee generated an exception. To check for exception you have to check the top of the stack after CALL is executed: 0 -> no error, another value -> error.
    – Ismael
    Jun 9, 2019 at 2:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.