6

Some times when using meta mask or other contracts, instead of sending an amount, I simply sign the transaction.

see here https://user-images.githubusercontent.com/731743/29750441-7a95dad2-8b37-11e7-803d-34e8b1c94f82.png

Say I want a function() that renames a string.

function string(string name){
    string myname = name;
}

How would I make this function do this - not by sending ether, but by signing the transaction? Does a transaction already need to take place?

I'm looking for a technical explanation of implementation signing within a contract. Say I want a function that requires a signature from metamask.

10

Sending ether is a type of transaction. A transaction is a set of instructions for modifying the state of the blockchain (e.g., transferring ether or calling a non-constant function of a contract -- such as a token-transfer function). If we consider only things like token transfers and ether transfers (for the sake of analogy), a "transaction" is like a bank cheque with all the details filled out -- the recipient, date, amount, account, etc. However, the cheque is useless to the bearer for the purposes of cashing it in unless it is signed. Similarly, all transactions must be signed for them to modify the blockchain.

So, taking a step back, in order to send ether, one generates a transaction that authorizes the transfer of ether from one account to another. Then one signs the transaction. These parts can be done off-line. Then, the last step, is for the transaction is broadcast onto the network and then it's up to the Ethereum network to work its magic and confirm the transaction into a block!

In order to sign something, a mathematical function is used to "sign" a piece of document/data. A digital signature of a document/data is a number generated using a private key. The private key has a corresponding public key. Anyone can sign a document but only (with high probability, according to our current understanding of mathematics and available computing power) the bearer of the private key can sign the document in such a way as to cause the signature to be valid with the matching public key.

One scheme we use works like this (where Hash creates a "fingerprint" of a particular piece of data):

signature = F(private_key, Hash(data))
verification = F(public_key, signature)
if verification == Hash(data):
    data signed by private_key associated with public_key
else:
    data not signed by private_key associated with public_key

The assumption is that, without private_key, one will pretty much be unable to generate signature such that F(public_key, signature) == Hash(data). Our current understanding of mathematics suggest that we know of a few functions we can use for F that are suitable for this purpose.

3

This might help a bit: https://medium.com/hello-sugoi/ethereum-signing-and-validating-13a2d7cb0ee3

But to attempt a simplification, you create a signature as some cryptohash thing of the keys and the message Signature = F(private key, message)

then you create a validation scheme that is some crypto-hash thing of the signature and the message Validation = F(Signature, message)

And then you know that if Validation = public key then it was signed and you didn't need to know or expose private keys

  • does Signature really use public key, or just private key? – Luke W Feb 10 '18 at 15:55
  • 2
    So the public key is derived from the private key. I think the answer from lungj explains it a bit better where you sign it with your private key so that F(public_key, signature) == Hash(data) – thefett Feb 11 '18 at 1:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.