Coder Social home page Coder Social logo

array-io-solidity's People

Contributors

cyberkostyan avatar

Watchers

 avatar  avatar

array-io-solidity's Issues

Expressions and control structures - differences

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

Expressions and Control Structures - to test and report

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

An assert-style exception is generated in the following situations:

If you access an array at a too large or negative index (i.e. x[i] where i >= x.length or i < 0).
If you access a fixed-length bytesN at a too large or negative index.
If you divide or modulo by zero (e.g. 5 / 0 or 23 % 0).
If you shift by a negative amount.
If you convert a value too big or negative into an enum type.
If you call a zero-initialized variable of internal function type.
If you call assert with an argument that evaluates to false.
A require-style exception is generated in the following situations:

Calling throw.
Calling require with an argument that evaluates to false.
If you call a function via a message call but it does not finish properly (i.e. it runs out of gas, has no matching function, or throws an exception itself), except when a low level operation call, send, delegatecall or callcode is used. The low level operations never throw exceptions but indicate failures by returning false.
If you create a contract using the new keyword but the contract creation does not finish properly (see above for the definition of "not finish properly").
If you perform an external function call targeting a contract that contains no code.
If your contract receives Ether via a public function without payable modifier (including the constructor and the fallback function).
If your contract receives Ether via a public getter function.
If a .transfer() fails.

  1. Does it work for Array? Which parts do?

Units and Globally Available Variables - all differences

In Units and Globally Available Variables, all bellow is not supported in Array:

  1. Ether Units
    https://github.com/arrayio/array-io-solidity/blob/master/units-and-global-variables.rst#ether-units

  2. Time Units
    https://github.com/arrayio/array-io-solidity/blob/master/units-and-global-variables.rst#time-units

  3. In Block and Transaction Properties, following code:
    https://github.com/arrayio/array-io-solidity/blob/master/units-and-global-variables.rst#block-and-transaction-properties

  • block.coinbase (address): current block miner’s address
  • block.difficulty (uint): current block difficulty
  • gasleft() returns (uint256): remaining gas
  • msg.data (bytes): complete calldata
  • msg.gas (uint): remaining gas - deprecated in version 0.4.21 and to be replaced by
    gasleft()
  • msg.sig (bytes4): first four bytes of the calldata (i.e. function identifier)
  • now (uint): current block timestamp
  • tx.gasprice (uint): gas price of the transaction
  • tx.origin (address): sender of the transaction (full call chain)
  1. In Mathematical and Cryptographic Functions (from keccak256(...) until the next subsection):
    https://github.com/arrayio/array-io-solidity/blob/master/units-and-global-variables.rst#mathematical-and-cryptographic-functions

keccak256(...) returns (bytes32):
compute the Ethereum-SHA-3 (Keccak-256) hash of the (tightly packed) arguments
sha256(...) returns (bytes32):
compute the SHA-256 hash of the (tightly packed) arguments
sha3(...) returns (bytes32):
alias to keccak256
ripemd160(...) returns (bytes20):

compute RIPEMD-160 hash of the (tightly packed) arguments
ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) returns (address):
recover the address associated with the public key from elliptic curve signature or return zero on error (example usage)
In the above, “tightly packed” means that the arguments are concatenated without padding. This means that the following are all identical:
keccak256("ab", "c")
keccak256("abc")
keccak256(0x616263)
keccak256(6382179)
keccak256(97, 98, 99)
If padding is needed, explicit type conversions can be used: keccak256("\x00\x12") is the same as keccak256(uint16(0x12)).
Note that constants will be packed using the minimum number of bytes required to store them. This means that, for example, keccak256(0) == keccak256(uint8(0)) andkeccak256(0x12345678) == keccak256(uint32(0x12345678)).
It might be that you run into Out-of-Gas for sha256, ripemd160 or ecrecover on a private blockchain. The reason for this is that those are implemented as so-called precompiled contracts and these contracts only really exist after they received the first message (although their contract code is hardcoded). Messages to non-existing contracts are more expensive and thus the execution runs into an Out-of-Gas error. A workaround for this problem is to first send e.g. 1 Wei to each of the contracts before you use them in your actual contracts. This is not an issue on the official or test net.

  1. In Address Related:
    https://github.com/arrayio/array-io-solidity/blob/master/units-and-global-variables.rst#address-related

<address>.call(...) returns (bool):
issue low-level CALL, returns false on failure, forwards all available gas, adjustable
<address>.callcode(...) returns (bool):
issue low-level CALLCODE, returns false on failure, forwards all available gas, adjustable
<address>.delegatecall(...) returns (bool):
issue low-level DELEGATECALL, returns false on failure, forwards all available gas, adjustable

  1. Contract Related
    https://github.com/arrayio/array-io-solidity/blob/master/units-and-global-variables.rst#contract-related

Contracts-differences

1. Does not compile in Array compiler

A: The code in the section does not compile.
A: Following does not compile either:

pragma solidity ^0.4.16;
contract B {
uint a = 3;
}

contract A {
B b;
}
pragma solidity ^0.4.11;
contract owned {
function owned() public { owner = msg.sender; }
address owner;
modifier onlyOwner {
require(msg.sender == owner);
_;
}

function close() public onlyOwner {
//
}
}

A: Doesn't compile because now doesn't work. Without it, it compiles.

Reading from state variables.
Accessing this.balance or <address>.balance.

A: don't support

Accessing any of the members of block, tx, msg (with the exception of msg.sig and msg.data).

A: Do we have these global members?

Calling any function not marked pure.
Using inline assembly that contains certain opcodes.

A: Do we support inline assembly?

-Inheritance
https://github.com/arrayio/array-io-solidity/blob/master/contracts.rst#inheritance
A: multiple inheritance -not supported
A: Since multiple inheritance is not supported, maybe we can state here something about the single inheritance?

-Abstract contracts
https://github.com/arrayio/array-io-solidity/blob/master/contracts.rst#abstract-contracts
A: ERROR: FuncDef_id(6): too few children (2) - first code
A: ERROR: FuncDef_id(6): too few children (2)- second set
Q: Why does compiler try to read this as number:
{ return "miaow";}
Error is: ERROR: strtobin: can not recognize num = "miaow" (1)

2. Questions

a) Creating contracts
https://github.com/arrayio/array-io-solidity/blob/master/contracts.rst#creating-contracts

Contracts can be created “from outside” via Ethereum transactions or from within Solidity contracts.
IDEs, such as Remix, make the creation process seamless using UI elements.
Creating contracts programatically on Ethereum is best done via using the JavaScript API web3.js. As of today it has a method called web3.eth.Contract to facilitate contract creation.

A: Ethereum stuff: we don't have Remix, web3.js. Are we gonna have something like web3.js?

If a contract wants to create another contract, the source code (and the binary) of the created contract has to be known to the creator. This means that cyclic creation dependencies are impossible.

A: Can a contract create another contract?

b) View functions
https://github.com/arrayio/array-io-solidity/blob/master/contracts.rst#view-functions

Emitting events.

A: events not supported

Creating other contracts.

A: Is this supported?

Using selfdestruct.

A: Is this supported?
When trying to selfdestruct, this is the error:
ERROR: MakeFunctionCallCore_id(14): can not get func visibility

Sending Ether via calls.

A: Doesn't compile
ERROR: dec_id_is_event: can not get "attributes.referencedDeclaration"
LOG: FunctionCall_id(14): TAG1
ERROR: MakeFunctionCallCore_id(13): unknown name: "FunctionCall"

Calling any function not marked view or pure.
Using low-level calls.
Using inline assembly that contains certain opcodes.

A: Do we support these?

c) Note

If invalid explicit type conversions are used, state modifications are possible even though a view function was called. You can switch the compiler to use STATICCALL when calling such functions and thus prevent modifications to the state on the level of the EVM by addingpragma experimental "v0.5.0";

A: Is this true for Array.IO?

d) Interfaces
https://github.com/arrayio/array-io-solidity/blob/master/contracts.rst#interfaces
A: Do we have it?

e) Libraries - first set of code
https://github.com/arrayio/array-io-solidity/blob/master/contracts.rst#libraries
A: Do we have it?
A: It doesn't compile because:
struct Data { mapping(uint => bool) flags; }
is not supported, error is:
ERROR: StructDefinition_id(6): us_prop.fullname == "C.Data" : #0 child : type == "mapping(uint256 => bool)" : can not get type properties

f) Libraries - second set of code
https://github.com/arrayio/array-io-solidity/blob/master/contracts.rst#libraries

A: Is having a mapping inside a struct supported?
A: for:

`pragma solidity ^0.4.16;
contract C {
struct Data { 
mapping(uint => bool) flags; 
}
}`

This is the error: ERROR: StructDefinition_id(6): us_prop.fullname == "C.Data" : #0 child : type == "mapping(uint256 => bool)" : can not get type properties

g) Using For
https://github.com/arrayio/array-io-solidity/blob/master/contracts.rst#using-for
A: Does call a function from a library work?
Because the following does not compile:

pragma solidity ^0.4.21;
library C {
function a() returns (address) {
return address(this);
}
}

contract A {
function a() constant returns (address) {
return C.a();
}
}

3. Errors

  1. TokenCreator creator;
    A: ERROR: VarDec_id(3): unknown type "contract TokenCreator"

  2. Fallback functions
    https://github.com/arrayio/array-io-solidity/blob/master/contracts.rst#fallback-function

In the worst case, the fallback function can only rely on 2300 gas being available (for example when send or transfer is used), leaving not much room to perform other operations except basic logging. The following operations will consume more gas than the 2300 gas stipend:
Writing to storage
Creating a contract
Calling an external function which consumes a large amount of gas
Sending Ether

A: Is this true for Array?

Note
Even though the fallback function cannot have arguments, one can still use msg.data to retrieve any payload supplied with the call.

A: can't use msg.data

Contracts that receive Ether directly (without a function call, i.e. using send or transfer) but do not define a fallback function throw an exception, sending back the Ether (this was different before Solidity v0.4.0). So if you want your contract to receive Ether, you have to implement a fallback function.

A: send does not work:
ERROR: FunctionCall_MemberAccess_of_address: unknown member_name == "send"

A contract without a payable fallback function can receive Ether as a recipient of a coinbase transaction (aka miner block reward) or as a destination of a selfdestruct.
A contract cannot react to such Ether transfers and thus also cannot reject them. This is a design choice of the EVM and Solidity cannot work around it.
It also means that this.balance can be higher than the sum of some manual accounting implemented in a contract (i.e. having a counter updated in the fallback function).

A: does not work

Introduction to Smart Contracts - all differences

Storage
https://github.com/arrayio/array-io-solidity/blob/master/introduction-to-smart-contracts.rst#storage

  1. (up to, but not including, version 0.5.0).
    A: The source code is written for Solidity version 0.4.21 and lower - for ArrayIO

  2. It is possible to store UTF-8 encoded data in string variables.
    A:

**Subcurrency Example ** https://github.com/arrayio/array-io-solidity/blob/master/introduction-to-smart-contracts.rst#subcurrency-example

  1. event Sent(address from, address to, uint amount);
    A:

  2. The address type is a 160-bit value that does not allow any arithmetic operations.

  3. The keyword public automatically generates a function that allows you to access the current value of the state variable from outside of the contract.

  4. The line event Sent(address from, address to, uint amount); declares a so-called “event” which is emitted in the last line of the function send. User interfaces (as well as server applications of course) can listen for those events being emitted on the blockchain without much cost. As soon as it is emitted, the listener will also receive the arguments from, to and amount, which makes it easy to track transactions. In order to listen for this event, you would use
    Coin.Sent().watch({}, '', function(error, result) {
    if (!error) {
    console.log("Coin transfer: " + result.args.amount +
    " coins were sent from " + result.args.from +
    " to " + result.args.to + ".");
    console.log("Balances now:\n" +
    "Sender: " + Coin.balances.call(result.args.from) +
    "Receiver: " + Coin.balances.call(result.args.to));
    }
    })

Note how the automatically generated function balances is called from the user interface.
A: We have no 'events'.

Accounts
https://github.com/arrayio/array-io-solidity/blob/master/introduction-to-smart-contracts.rst#accounts

  1. Regardless of whether or not the account stores code, the two types are treated equally by the EVM.
    A:

  2. Furthermore, every account has a balance in Ether (in “Wei” to be exact) which can be modified by sending transactions that include Ether.
    A:

Transactions
https://github.com/arrayio/array-io-solidity/blob/master/introduction-to-smart-contracts.rst#transactions-1

  1. It can include binary data (its payload) and Ether.
    A:

Storage, Memory and the Stack
https://github.com/arrayio/array-io-solidity/blob/master/introduction-to-smart-contracts.rst#storage-memory-and-the-stack

  1. (Memory) .... can be addressed at byte level,
    A:

  2. Memory is more costly the larger it grows (it scales quadratically).
    A:

  3. It has a maximum size of 1024 elements and contains words of 256 bits. Access to the stack is limited to the top end in the following way: It is possible to copy one of the topmost 16 elements to the top of the stack or swap the topmost element with one of the 16 elements below it.
    A:

Instruction Set
https://github.com/arrayio/array-io-solidity/blob/master/introduction-to-smart-contracts.rst#instruction-set

  1. The instruction set of the EVM is kept minimal in order to avoid incorrect implementations which could cause consensus problems. All instructions operate on the basic data type, 256-bit words.
    A:

  2. Calls are limited to a depth of 1024,
    A:

Delegatecall / Callcode and Libraries
https://github.com/arrayio/array-io-solidity/blob/master/introduction-to-smart-contracts.rst#delegatecall--callcode-and-libraries
A: We don't have it

Logs
https://github.com/arrayio/array-io-solidity/blob/master/introduction-to-smart-contracts.rst#logs

  1. It is possible to store data in a specially indexed data structure that maps all the way up to the block level. This feature called logs is used by Solidity in order to implement events.
    A:

  2. Since some part of the log data is stored in bloom filters,
    A:

Self-destruct
https://github.com/arrayio/array-io-solidity/blob/master/introduction-to-smart-contracts.rst#self-destruct
A: Don't have this operation

Types- all differences

Types
(https://github.com/arrayio/array-io-solidity/blob/master/types.rst#types)

A: we don't support all bellow (1-10)

  1. Fixed Point Numbers (fixed point numbers until 'Address' section)
    https://github.com/arrayio/array-io-solidity/blob/master/types.rst#fixed-point-numbers

  2. Members of addresses (first Warning and a second Note in the section)
    https://github.com/arrayio/array-io-solidity/blob/master/types.rst#members-of-addresses

  3. Fixed-sized byte arrays
    https://github.com/arrayio/array-io-solidity/blob/master/types.rst#fixed-size-byte-arrays

  4. Dynamically-sized byte array
    https://github.com/arrayio/array-io-solidity/blob/master/types.rst#dynamically-sized-byte-array

  5. Address literals
    https://github.com/arrayio/array-io-solidity/blob/master/types.rst#address-literals

  6. String literals
    https://github.com/arrayio/array-io-solidity/blob/master/types.rst#string-literals

  7. Hexadecimal literals
    https://github.com/arrayio/array-io-solidity/blob/master/types.rst#hexadecimal-literals

  8. Enums
    https://github.com/arrayio/array-io-solidity/blob/master/types.rst#enums

In Function types:
https://github.com/arrayio/array-io-solidity/blob/master/types.rst#function-types

  1. Sentence: If external function types are used outside of the context of Solidity, they are treated as the function type, which encodes the address followed by the function identifier together in a single bytes24 type.

  2. code:
    event NewRequest(uint);
    and
    emit NewRequest(requests.length - 1)

  3. In Operators Involving LValues - delete subsection

Data location
https://github.com/arrayio/array-io-solidity/blob/master/types.rst#data-location

  1. paragraph: There is also a third data location, calldata, which is a non-modifiable, non-persistent area where function arguments are stored. Function parameters (not return parameters) of external functions are forced to calldata and behave mostly like memory.
    A: in Array, calldata is ROM

Members
(https://github.com/arrayio/array-io-solidity/blob/master/types.rst#members)

  1. code in Push subsection:
    m_pairsOfFlags;
    delete m_aLotOfIntegers;
    bytes memory b = new bytes(200);
    A: doesn't exist

Miscellanous - differences

Dima recommends rewriting this part to fit our VM specs

Virtual Machine parts to test:

  1. Layout of State Variables in Storage
    https://github.com/arrayio/array-io-solidity/blob/master/miscellaneous.rst#layout-of-state-variables-in-storage
    a) > ...are packed into a single storage slot if possible ...

A: Now it is not like that for Array

b) Whole Warning segment in this section should be out.

  1. Layout in Memory
    https://github.com/arrayio/array-io-solidity/blob/master/miscellaneous.rst#layout-in-memory
  2. Internals - Cleaning Up Variables
    https://github.com/arrayio/array-io-solidity/blob/master/miscellaneous.rst#internals---cleaning-up-variables
  3. Internals - The Optimizer
    https://github.com/arrayio/array-io-solidity/blob/master/miscellaneous.rst#internals---the-optimizer
  4. Source Mappings
    https://github.com/arrayio/array-io-solidity/blob/master/miscellaneous.rst#source-mappings

Tips and Tricks
https://github.com/arrayio/array-io-solidity/blob/master/miscellaneous.rst#tips-and-tricks

Use delete on arrays to delete all its elements.

A: delete doesn't work

Cheatsheet
https://github.com/arrayio/array-io-solidity/blob/master/miscellaneous.rst#cheatsheet
Doesn't work for Array:

  1. New expression:
    new <typename>

  2. Unary operations:
    delete

  3. Exponentiation:
    **

  4. from the row 4 to 16 - remains to be tested...

Global Variables:
https://github.com/arrayio/array-io-solidity/blob/master/miscellaneous.rst#global-variables
Global vars which do not work for Array:

block.blockhash(uint blockNumber) returns (bytes32)
block.coinbase (address)
block.difficulty (uint)
block.gaslimit (uint)
block.number (uint)
gasleft() returns (uint256)
msg.data (bytes)
msg.gas (uint)
now (uint)
tx.gasprice (uint)
tx.origin (address)
revert()
keccak256(...) returns (bytes32)
sha3(...) returns (bytes32)
sha256(...) returns (bytes32):
ripemd160(...) returns (bytes20)
ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) returns (address)
addmod(uint x, uint y, uint k) returns (uint)
mulmod(uint x, uint y, uint k) returns (uint)
this
super
selfdestruct(address recipient)
suicide(address recipient)
<address>.send(uint256 amount) returns (bool)

Modifiers
https://github.com/arrayio/array-io-solidity/blob/master/miscellaneous.rst#modifiers
don't work:
anonymous for events: Does not store event signature as topic.
indexed for event parameters: Stores the parameter as topic.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.