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

Expressions and control structures - differences #7

Open
ghost opened this issue Oct 10, 2018 · 0 comments
Open

Expressions and control structures - differences #7

ghost opened this issue Oct 10, 2018 · 0 comments

Comments

@ghost
Copy link

ghost commented Oct 10, 2018

1. Sections of code which does not compile:

-Scoping and Declarations: second set of code
https://github.com/arrayio/array-io-solidity/blob/master/control-structures.rst#scoping-and-declarations
A: most likely because baz is not implicitly initialized as zero.

2. Questions:

  1. Do we support .value()?
    https://github.com/arrayio/array-io-solidity/blob/master/control-structures.rst#creating-contracts-via-new

  2. In Complications for Arrays and Structs:
    https://github.com/arrayio/array-io-solidity/blob/master/control-structures.rst#complications-for-arrays-and-structs

...assigning to a local variable creates an independent copy only for elementary types, i.e. static types that fit into 32 bytes

  • is this correct?

A second assignment to the local variable does not modify the state but only changes the reference. Assignments to members (or elements) of the local variable do change the state.

  • is this correct?
  1. Error handling assert require revert and exceptions
    https://github.com/arrayio/array-io-solidity/blob/master/control-structures.rst#error-handling-assert-require-revert-and-exceptions

Internally, Solidity performs a revert operation (instruction 0xfd) for a require-style exception and executes an invalid operation (instruction 0xfe) to throw an assert-style exception. In both cases, this causes the EVM to revert all changes made to the state. The reason for reverting is that there is no safe way to continue execution, because an expected effect did not occur. Because we want to retain the atomicity of transactions, the safest thing to do is to revert all changes and make the whole transaction (or at least call) without effect. Note that assert-style exceptions consume all gas available to the call, while require-style exceptions will not consume any gas starting from the Metropolis release.

  • is this correct?

3. Errors:
a) Scoping and Declarations: second set of code
https://github.com/arrayio/array-io-solidity/blob/master/control-structures.rst#scoping-and-declarations

contract C {
    function foo() public pure returns (uint) {
        // baz is implicitly initialized as 0
        uint bar = 5;
        if (true) {
            bar += baz;
        } else {
            uint baz = 10;// never executes
        }
        return bar;// returns 5
    }
}

A: ERROR: IfStatement_id(17): cannot get oparg1

b) Error handling assert require revert and exceptions
https://github.com/arrayio/array-io-solidity/blob/master/control-structures.rst#error-handling-assert-require-revert-and-exceptions

The throw keyword can also be used as an alternative to revert().

A: Throw doesn't work but it's depricated ERROR: Block_id(11): unknown "Throw
assert and require do work, but this.balance is not supported

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

No branches or pull requests

0 participants