Understanding the Name Registration Contract Example

crainbfcrainbf Member Posts: 2
There is another interesting post annotating a contract example. I wanted to add another one of those, because I don't quite understand the contract example in Vitalik's latest blog post.

Here is a description of the contract:
A simple example of a contract would be a basic name registration system, allowing users to register their name with their address. This contract would not send transactions; its sole purpose is to build up a database which other nodes can then query.

The contract has the following code:
if tx.value < block.basefee * 200: stop if contract.storage[tx.data[0]] or tx.data[0] < 100: stop contract.storage[tx.data[0]] = tx.data[1]

I don't understand the middle if condition here. Shouldn't it just be this:
if contract.storage[tx.data[0]]: stop

Assuming tx.data[0] returns the address of the user, then contract.storage[tx.data[0]] would return something if the address has been registered already. So the if statement would return true and the process would stop.

What's the point of tx.data[0]<100? Does that check for invalid addresses?

Am I missing something else here?

Comments

  • ChristianPeelChristianPeel Member Posts: 26
    Great question; I'd love to know the answer.

    Related questions are A: why are 200*basefee required for the transaction value, why not just allow it if tx.value has enough to run the contract and B: I understand that if the tx.value is more than enough to run the contract it's returned to the sender, is this somehow just a policy of the Ethereum code, or is there some way that this is enforced?
  • VetruvianVetruvian Member Posts: 17
    I understand that if the tx.value is more than enough to run the contract it's returned to the sender, is this somehow just a policy of the Ethereum code, or is there some way that this is enforced?
    On top of that: how will it be possible to determine the fee needed to run the contract? Will it be simulated by the miner? That might be very complex (a lot of transactions, conditions, looking at data in other contracts, heavy cryptographic functions). Will spamming invalid transactions to that kind of contract put a strain on the network (because a lot of simulation has to be done), or is it possible to determin beforehand if the contract can be run or not?
  • yoyoyoyo Member Posts: 34 ✭✭✭

    @crainbf: `contract.storage` also stores the script codes, so it must ensure that it doesn't overwrite itself. Assumedly 100 is an arbitrary index leaving enough room to spare. It's the starting storage address for the actual name store.

    @Vetruvian: The language is Turing Complete so in theory you cannot know whether a particular contract run will ever end or not, and you can't predict its storage or computation needs without simulating it. https://en.wikipedia.org/wiki/Halting_problem

    The script will just run until its balance is dry, at which point it will just stop. It might stop in between two important commands, this does not invalidate the transaction. I think it will be important to write scripts in such a way that they never end a run with less ether than what they started it with. (to avoid a "drying by repetition" attack).

    It will lay flat until someone reactivates it with enough energy to get rolling again.
  • ChristianPeelChristianPeel Member Posts: 26
    I think it will be important to write scripts in such a way that they never end a run with less ether than what they started it with. (to avoid a "drying by repetition" attack).
    So is it possible for a contract to grow in value with no way to end it? I guess so; and I guess there may not be much difference between a sub-currency and a pyramid or Ponzi scheme.
  • MilanMilan San Diego, CAMember Posts: 46
    Interesting observation. So, would you want to build a "cashout" clause in to your contracts, just in case they accidentally amass lots of ether?
  • StephanTualStephanTual London, EnglandMember, Moderator Posts: 1,282 mod
    Swamped so can't participate in this just yet (looks fun!) but have a look at http://www.reddit.com/r/ethereum/comments/1w1eak/contracts/ - people have started annotating the hedge contracts from the white paper.
Sign In or Register to comment.