“Just skimming through the Solidity docs, I see a lot of unwise decisions there” (comment)
recommended by 2 users | 2017 | int_19h on: 153k Ether Stolen in Parity Multi-Sig Attack | crypto | original thread |
int_19h on Jul 20, 2017 | on: 153k Ether Stolen in Parity Multi-Sig Attack | view on HN

Just skimming through the Solidity docs, I see a lot of unwise decisions there aside from the weird visibility defaults.

All state is mutable by default (this includes struct fields, array elements, and locals). Functions can mutate state by default. Both are overridable by explicit specifiers, much like C++ "const", but you have to remember to do so. Even then, the current implementation doesn't enforce this for functions.

Integers are fixed-size and wrap around, so it's possible to have overflow and underflow bugs. Granted, with 256 bits of precision by default that's harder to do than usual... but still pretty easy if you e.g. do arithmetic on two inputs.

Operators have different semantics depending on whether the operands are literals or not. For example, 1/2 is 0.5, but x/y for x==1 and y==2 is 0. Precision of the operation is also determined in this manner - literals are arbitrary-precision, other values are constrained by their types.

Copy is by reference or by value depending on where the operands are stored. This is implicit - the operation looks exactly the same in code, so unless you look at declarations, you don't know what it actually does. Because mutability is pervasive, this can can have far-reaching effects.

Map data type doesn't throw on non-existing keys, it just returns the default value.

The language has suffixes for literals to denote various units (e.g. "10 seconds" or "1000 ether"). This is purely syntactic sugar, however, and is not reflected in the type system in any way, so "10 second + 1000 ether" is valid code.

Statements allow, but do not require, braces around bodies. This means that dangling "else" is potentially an issue, as is anything else from the same class of bugs (such as the infamous Apple "goto fail" bug).

Functions can be called recursively with no special effort, but the stack size is rather limited, and it looks like there are no tail calls. So there's the whole class of bugs where recursion depth is defined by contract inputs.

Order of evaluation is not defined for expressions. This in a language that has value-returning mutating operators like ++!

Scoping rules are inherited from JS, meaning that you can declare variables inside blocks, but their scope is always the enclosing function. This is more of an annoyance than a real problem, because they don't have closures, which is where JS makes it very easy to shoot yourself in the foot with this approach to scoping.

2 users recommended this comment. What they said:
ekidd Jul 24, 2017 | on: Learn Ethereum smart contract programming | context

> 2. Ethereum software has security hole, gets hacked

The last time this was discussed on Hacker News, I found this comment particularly instructive: https://news.ycombinator.com/item?id=14810008

It points out a great many fundamental issues with the Solidity contract language. Basically, the language design sounds extremely amateurish and it appears to have ignored everything we've learned about security in the last 30 years. Samples:

- "Operators have different semantics depending on whether the operands are literals or not. For example, 1/2 is 0.5, but x/y for x==1 and y==2 is 0."

- "All state is mutable by default (this includes struct fields, array elements, and locals). Functions can mutate state by default"

- "Order of evaluation is not defined for expressions. This in a language that has value-returning mutating operators like ++!"

I wouldn't trust a Solidity smart contract with $100.

zmonx Sep 30, 2017 | on: Reviewing Ethereum Smart Contracts | context

int_19h has previously posted a nice overview of some of Solidity's flaws:

https://news.ycombinator.com/item?id=14810008

Such issues make the language extremely error-prone.

A possible remedy was also suggested:

https://news.ycombinator.com/item?id=14809743

Prolog sounds like a great tool for encoding rules, and there has already been some research for encoding legal texts in Prolog.