[Ethereum] 트랜잭션과 서명

트랜잭션

트랜잭션 T는 다음 data를 포함한다.

T = { nonce, gasPrice, gasLimit, to, value, data, v, r, s }
  • nonce: 보내는 EOA(External Owned Account) 의 counter.
    • 중간에 생략되면 생략된 nonce가 와서 유효하게 처리되기 전까지 이후의 nonce를 가지는 트랜잭션은 mempool에 저장되었다가 처리 후 유효하게 된다.
  • gasPrice: 발신자가 보내는 가스의 가격. 단위는 wei.
    • 0도 가능. 높을 수록 해당 트랜잭션이 빨리 처리됨.
  • gasLimit: 이 트랜잭션을 위해 구입할 가스의 최대량
    • 21000 gas. 이더 소비량 = 21000 * gasPrice
  • to: 수신 이더리움 address (20 bytes)
  • value: 수신처에 보낼 이더의 양
  • data: 가변 길이 data payload
    • to가 contract address라면, 4 bytes의 function selector와 그 이후의 function argument를 serialize한 data이다.
      • function selector = (keccak-256(function prototype))[0:4]
  • v, r, s: EOA의 ECDSA 디지털 서명의 구성 요소

서명

서명 시 사용되는 트랜잭션 T는 9개 필드로 다음과 같다. 이 중 맨 끝의 3개 { chainID, 0, 0 }은 EIP-155에 의해 추가된다. EIP-155는 Simple Replay Attack Protection으로 chainID를 포함하여 다른 네트워크 체인에서 해당 트랜잭션이 replay될 수 없도록 한다.

T = { nonce, gasPrice, gasLimit, to, value, data, chainID, 0, 0 }

Sig는 서명으로 서명 알고리즘, F sig() 로 (r, s) 두 값이 output으로 만들어진다. Transaction T와 private key k를 사용한다. RLP는 Recursive Length Prefix (RLP) encoding scheme 을 말한다.

Sig = F sig(keccak256(RLP(T)), k) = (r, s)

서명 시에는 임시 private key q, 그리고 q로부터 생성되는 임시 public key Q 를 사용한다.

q = rand() % 2**256
Q = q * K = (x, y)

여기서 r = Q의 x 좌표이다. s는 다음으로 계산된다.

s ≡ q**-1 (Keccak-256(RLP(T)) + r * k) mod p

서명 검증

r, s 그리고 sender의 public key K를 사용해서 Q를 계산한다. Q의 x 좌표와 r이 같으면 서명이 유효하다.

w = s**-1 mod p
u1 = Keccak-256(RLP(T)) * w mod p
u2 = r * w mod p
Q ≡ u1 * G + u2 * K     (mod p)

참고: https://github.com/ethereumbook/ethereumbook/blob/develop/06transactions.asciidoc

[English] Put on your shoes and put your shoes on (Two-Word Verbs 2)

two-word 동사(put on / take off, etc.)는 가끔 목적어object를 가진다. Sometimes a two-verb (put on / take off, etc.) has an object.

put on your coat
이렇게 쓸 수 있다:
put on your coat
put your coat on

take off your shoes
이렇게 쓸 수 있다:
take off your shoes
take your shoes off

그러나 it/them (대명사pronouns)는 언제나 on/off, etc. 앞에 온다. But it/them (pronouns) always go before on/off, etc:
put it on (not put on it)
take them off (not take off them)

  • It was cold, so I put on my coat. or … I put my coat on.
  • Here’s your coat. Put it on.
  • I’m going to take off my shoes. or … take my shoes off.
  • Your shoes are dirty. Take them off.

더 많은 two-word 동사verbs + 목적어object. More two-word verbs + objects

turn on / turn off (lights, machines, faucets, etc.)

  • It was dark, so I turned on the light. or … I turned the light on.
  • I don’t want to watch this program. You can turn it off.

pick up / put down

  • Those are my keys on the floor. Can you pick them up for me?
  • I stopped reading and put my book down. orput down my book.

bring back / take back / give back / put back

  • You can take my umbrella but please bring it back.
  • I took my new sweater back to the store. It was too small.
  • I have Diane’s keys. I have to give them back to her.
  • I read the letter and then put it back in the envelope.

[English] Go in, fall off, run away, etc. (Two-Word Verbs 1)

Two-word 동사는 동사 (go/look/be, etc.) + in/out/down, etc.이다. A two-word verb is a verb (go/look/be, etc.) + in/out/up/down, etc.

in

  • Erin opened the door of the car and got in. (= into the car)
  • I waited outside the house. I didn’t go in.

out

  • The car stopped and two women got out. (= out of the car)
  • I went to the window and looked out.

on

  • The bus came, and I got on.

off

  • Be careful! Don’t fall off.

up

  • He stood up and left the room.
  • I usually get up early. (= get out of bed)
  • We looked up at the stars.

down

  • Would you like to sit down?
  • The picture fell down.
  • Lie down on the floor.

away or off

  • The thief ran away. (or … ran off)
  • Erin got into the car and drove away. (ordrove off)

be/go away (= in/to another place)

  • Erin has gone away for a few days.

back

  • We went out for dinner and then went back to our hotel.
  • Go away and don’t come back!

be back

  • Erin is away. She’ll be back on Monday.

around

  • I’m not sure what kind of car I want. I want to look around first.
  • Somebody shouted my name, so I turned around.
  • We went for a long walk. After six miles we turned around and went back.

[English] Listen to …, look at …, etc. (Verb + Preposition)

ask somebody for

  • A man stopped me and asked me for money.

belong to

  • Does this book belong to you? (= Is this your book?)

happen to

  • I can’t find my pen. What happened to it?

listen to …

  • Listen to this music. It’s great!

look at

  • She’s looking at her watch.
  • Look at these flowers! They’re beautiful.
  • Why are you looking at me like that?

look for

  • He lost his key. He’s looking for it.
  • I’m looking for Sarah. Have you seen her?

speak/talk to somebody about

  • Did you talk to Paul about the problem?
  • (on the phone) Can I speak to Chris, please?

take care of

  • When Pat is at work, a friend of hers takes care of her children.
  • Don’t lose this book. Take care of it.

thank somebody for

  • Thank you very much for your help.

think about … or think of …

  • He never thinks about (or of) other people.
  • Mark is thinking of (or about) buying a new car.

wait for

  • Wait for me! I’m almost ready.

write and call

write (to) somebody

  • I never get letters. Nobody writes to me. (or Nobody writes me.)

call somebody (no preposition)

  • I have to call my parents. (not call to …)

depend

depend on으로 말한다. We say depend on …:

  • A: Do you like to eat in restaurants?
    B: Sometimes. It depends on the restaurant. (not it depends of)

on을 쓰거나 안써서 it depends what/where/how로 말할 수 있다. it depends what/where/how, etc., with or without on.

  • A: Do you want to go out with us?
    B: It depends where you’re going. (or It depends on where you’re going.)

[English] Afraid of, good at, etc. (Adjective + Preposition) At -ing, with -ing, etc (Preposition + -ing)

afraid of / good at, etc. (adjective + preposition)

afraid of …

  • Are you afraid of dogs?

angry/mad at somebody / angry/mad about something

  • Why are you mad at me? What did I do?
  • Are you angry about last night? (= something that happened last night)

different from … / different than …

  • Lynn is very different from her sister. or Lynn is very different than her sister.

full of …

  • The room was full of people.

good at … / bad at …

  • Are you good at math?
  • Tina is very bad at writing letters.

interested in …

  • I’m not interested in sports.

married to …

  • Sue is married to a dentist. (= her husband is a dentist)

nice/kind of somebody to … / nice/kind to somebody

  • It was kind of you to help us. Thank you very much.
  • David is very friendly. He’s always very nice to me.

sorry about something / sorry for somebody

  • I’m sorry about your accident. Was anyone hurt?
  • I feel sorry for them. They work hard, but they never have enough money.

tired of …

  • I’m tired of my job. I need a change.

Preposition + -ing

전치사preposition (at/with/for, etc.) 뒤에는 -ing 로 끝나는 동사. After a preposition (at/with/for, etc.), a verb ends in -ing.

I’m not very good at + telling + stories
Are you tried of + doing + the same thing every day?
Thank you for + helping + me.
Mark is thinking of + buying + a new car.
Tom left without + saying + goodbye. (= he didn’t say goodbye)
After + doing + the housework, they went out.

[English] On, at, by, with, and about

on

on vacation
on television
on the radio
on the phone
on fire
on time (= not late)

  • Tracy isn’t at work this week. She’s on vacation.
  • We watched the news on television.
  • We listened to the news on the radio.
  • I spoke to Carol on the phone last night.
  • The house is on fire! Call the fire department.
  • ”Was the train late?” “No, it was on time.”

at (the age of) 21 / at 50 kilometers an hour / at 100 degrees, etc.

  • Lisa got married at 21. (or … at the age of 21)
  • A car uses more gas at 70 miles an hour than at 55.
  • Water boils at 100 degrees Celsius.

by car / by bus / by plane (or by air) / by boat / by bicycle, etc.

  • Do you like traveling by train?
  • Can you get there by bike?

그러나 도보로는 on foot. But: on foot

  • You can’t get there by car. You have to go on foot.

a book by … / a painting by … / a piece of music by …, etc.
(the tile) by (the writer)

  • Have you read any books by Charles Dickens?
  • Who is that painting by? Picasso?

수동태 다음에 by. by after the passive

  • I was bitten by a dog.

with / without

  • Did you stay at a hotel or with friends?
  • Wait for me. Please don’t go without me.
  • Do you like your coffee with or without milk?
  • I cut the paper with a pair of scissors.

a main with a beard / a woman with glasses, etc.

  • Do you know that man with the beard?
  • I’d like to have a house with a big yard.

talk/speak/think/hear/know about …

  • Some people talk about their work all the time.
  • I don’t know much about cars.

a book / a question / a program (etc.) about

  • Did you see the program about computers on TV last night?

[English] Up, over, through, etc.

to / from

  • Tracy is going to Hawaii next week.
  • We walked from the hotel to the restaurant.
  • A lot of English words come from Latin.

into (in) / out of

  • We jumped into the water.
  • A man came out of the house and got into a car.
  • Why are you looking out of the window?
  • I took the old batteries out of the radio.

put something에는 (보통 into가 아니고) in …을 쓴다. We say put something in … (not usually into).

  • I put new batteries in the radio.

on / off

  • Don’t put your feet on the table.
  • Please take your feet off the table.
  • I’m going to hang some pictures on the wall.
  • Be careful! Don’t fall off your bicycle.
  • We got on the bus downtown.

up / down

  • We walked up the hill to the house.
  • Be careful! Don’t fall down the stairs.

over / under

  • The plane flew over the mountains.
  • I climbed over the wall into the yard.
  • Some people say it is unlucky to walk under a ladder.

through / around

  • A bird flew into the room through a window.
  • The old highway goes through the city.
  • The new highway goes around the city.
  • The bus stop is just around the corner.
  • I walked around the town and took some pictures.

along / across

  • I was walking along the street with my dog.
  • Let’s go for a walk along the river.
  • The dog swam across the river.

past

  • They walked past me without speaking.
  • A: Excuse me, how do I get to the hospital?
    B: Go along this street, past the movie theater, under the bridge, and the hospital is on the left.

[English] Next to, between, under, etc.

next to / between / in front of / in back of

  • Adam is next to Bob.
  • Bob is between Adam and Carla.
  • Don is in front of Bob.
  • Carla is in back of Don.
  • Adam is on the left.
  • Ellen is on the right.
  • Don is in the middle (of the group).

across from / in front of

  • Anne is sitting in front of Bruce.
  • Anne is sitting across from Christa.
  • Christa is sitting across from Anne.

by (= next to)

  • Our house is by the ocean. (= next to the ocean)
  • Who is that man by the window?
  • ”Is there a pay phone here? “Yes, by the door.”

under

  • The cat is under the table.
  • The girl is standing under a tree.
  • I’m wearing a jacket under my coat.

above and below

  • A is above the line. (= higher than the line)
  • B is below the line. (= lower than the line)
  • The pictures are above the shelves.
  • The shelves are below the pictures.