Live data from Hacker News

Understanding Ethereum Smart Contracts

gjermundbjaanes.com

61–70 of 162 posts

Re: Understanding Ethereum Smart Contracts

#61
post #57
post #29

I've been programing my own Ethereum smart contract (virtual currency) for awhile now. Here's some gotchas off the top of my head: - You have about 500 lines of code to work with. This of course varies, but smart contracts have to be really small to fit in the max gas limit (6.7 million wei). - You can't pass strings between contracts (coming soon). - There are no floating point numbers. Since you're probably working…

A question about the 500 lines of code and tooling limitations. Is this something that is inherently an issue of the underlying technology or do you predict that this is something that is likely to be improved upon over time? And if you think it'll be improved, are we years away from big improvements? Less?

The 500 lines of code is, to be clear, just a guesstimate. It really is related to how those lines of code are compiled into Ethereum opcodes. Maybe you can get a thousand lines of code. My point is that it's pretty small, compared to what most developers are used to.

The max gas limit is voted on by Ethereum miners. They recently raised it to 6.7 million (I believe it was 4.5 million not so long ago). The gas is what is used to store the contract (thus increasing the block chain size), or to execute code (thus increasing the work load on the miners), so it's up to them.

More Eth = more $$, but they have to weigh that against the downsides. If the price of Eth keeps going up, they have less incentive to increase the gas limit, because they get more money for doing the same work.

Re: Understanding Ethereum Smart Contracts

#62
I've also just begun to play with smart contract programming.

One problem I'm having is with event listening.

It seems that MetaMask doesn't yet support subscriptions, nor does my localhost testRPC instance pass it in the web3 object.

Some have suggested I need to run my own node just to listen for contract events. Has anyone figured out an easier solution?

Re: Understanding Ethereum Smart Contracts

#63
post #62

I've also just begun to play with smart contract programming. One problem I'm having is with event listening. It seems that MetaMask doesn't yet support subscriptions, nor does my localhost testRPC instance pass it in the web3 object. Some have suggested I need to run my own node just to listen for contract events. Has anyone figured out an easier solution?

I've had success listening to events using web3, against both testrpc and geth (on private and test networks). What version of web3 & testrpc are you using?

Re: Understanding Ethereum Smart Contracts

#64
post #44
post #19

Earlier quoted context omitted.

Those are both really interesting thanks. I assume in case 2 Solidity language has some built-in mechanisms for ensuring that the current datetime is agreed across the whole network?

As DennisP said, yes there are mechanisms to ensure date is agreed upon. Your question of "consensus" brings up other interesting points. I think an increasingly valuable service in a new smart-contract world will be to have an "Outcomes As A Service" arbiter. This would be a trusted 3rd party that publishes real-world outcomes in a method that can be accessed reliably via smart contracts. Who will win the football g…

This is the main problem I see with smart contracts (Even with oracles?)...

How do the nodes running the code all get the same response from an external data source?

Even if they use a service such as oraclize if the contract calls https://api/query?param1 and it returns lets say the weather:

Node1 gets: 15.2c Node2 gets: 15.3c

We've already failed on consensus haven't we?

Re: Understanding Ethereum Smart Contracts

#65
post #17

Earlier quoted context omitted.

Some of the use cases can be fairly simple (thus easier to see the value). 1. Me and You start a company together. We would like to split things 50/50. We setup an address such that when values are paid to it, half goes to you, half goes to me. Effectively we've created an "LLC with an Operating Agreement", but we aren't relying on political legal system / country to enforce. Enforcement is automatic and done by the…

1- 50% of what? Revenue into the company or dividens/salary etc out of the company? if it's the latter, then, how do we make sure that you don't spend $500.000 for trash bins for the office? Do we have to make sure every decision goes through the network? (i.e. who is the authority to decide what is reasonable and what is blatant fraud if things go sour AND is it even possible to make sure that nothing possibly can g…

regarding number 2, the child would not have a way of selling that Ethereum before 2035.

Re: Understanding Ethereum Smart Contracts

#66
post #29

I've been programing my own Ethereum smart contract (virtual currency) for awhile now. Here's some gotchas off the top of my head: - You have about 500 lines of code to work with. This of course varies, but smart contracts have to be really small to fit in the max gas limit (6.7 million wei). - You can't pass strings between contracts (coming soon). - There are no floating point numbers. Since you're probably working…

> You can break up your code into multiple contracts, but the tradeoff is an increased attack area.

This is the way to get programs over 500 lines, and it doesn't increase the attack area as much as you'd think, since you can essentially hard-code the addresses of outside contracts into your code--it's not a combinatorial explosion.

Re: Understanding Ethereum Smart Contracts

#67
post #59

Earlier quoted context omitted.

_Red gave two examples of Ethereum applications. SeckimJohn quite quickly showed why neither work. The are some niche digital uses, but not the ones people often tout. Ethereum contracts basically break down at the point they need to interact with the real world.

Well I'm entirely new to this and pretty blockchain sceptical but I don't think SeckimJohn showed why neither work, did he? As I understand it each concern requires some kind of function/method which addresses it within the smart contract, right? So the real problem is that once you publish the contract you better make sure you haven't forgotten something important...

He didn't show that neither work, but the examples he did give were trivially bypassed and didn't seem "real world" at all.

For instance, I can't think of any corporate structures that splits income in half. Usually the money is run through the company and costs etc. are taken out first. So this isn't a real world example?

Re: Understanding Ethereum Smart Contracts

#68
post #29

I've been programing my own Ethereum smart contract (virtual currency) for awhile now. Here's some gotchas off the top of my head: - You have about 500 lines of code to work with. This of course varies, but smart contracts have to be really small to fit in the max gas limit (6.7 million wei). - You can't pass strings between contracts (coming soon). - There are no floating point numbers. Since you're probably working…

> You can break up your code into multiple contracts, but the tradeoff is an increased attack area. This is the way to get programs over 500 lines, and it doesn't increase the attack area as much as you'd think, since you can essentially hard-code the addresses of outside contracts into your code--it's not a combinatorial explosion.

> and it doesn't increase the attack area as much as you'd think

You should call Gavin Wood and tell him that :D

Re: Understanding Ethereum Smart Contracts

#69
post #58

Earlier quoted context omitted.

What bit of that needs a smart contract? Seems perfectly do-able without one, and you still need the same levels of trust even when there's a smart contract in there.

The smart contract is the tool to make sure* that transferred Ether results in power being transferred. Of course we could just use a blockchain like Bitcoin and define "send x BTC to wallet y and I promise you will get your power" - but in that case, the blockchain can just guarantee the value transfer, not the subsequent actions being undertaken. * since this involves interaction with the outside world, I don't kno…

This seems like a perfect use-case for payment channels, e.x. Lightning Network:

Car continuously delivers micropayments to charger while charger continuously delivers power to car, if one stops the other also stops. If the power is cut off prematurely the car only loses maybe a couple cents worth of power.

(Payment channels are built using smart contracts, but they’re simple enough that Bitcoin’s more limited smart contracts can do it)

Re: Understanding Ethereum Smart Contracts

#70
post #59

Earlier quoted context omitted.

_Red gave two examples of Ethereum applications. SeckimJohn quite quickly showed why neither work. The are some niche digital uses, but not the ones people often tout. Ethereum contracts basically break down at the point they need to interact with the real world.

Well I'm entirely new to this and pretty blockchain sceptical but I don't think SeckimJohn showed why neither work, did he? As I understand it each concern requires some kind of function/method which addresses it within the smart contract, right? So the real problem is that once you publish the contract you better make sure you haven't forgotten something important...

Right, the examples are just missing the step of "somehow make sure this isn't as bad an idea as it looks".
Post reply on HN