비트코인 지갑주소를 잘못입력하면? What happens if you write incorrect bitcoin address it?

in #bitcoin6 years ago (edited)

비트코인 지갑주소를 잘못입력하면 어떻게 될까?
What happens if you write incorrect bitcoin address it?

내가 입력한 주소에 오타가 있는 경우 의미하며, 실제 존재하는 주소를 잘못 복사했거나, 다른 암호화폐의 주소를 입력하는 경우를 말하는 것이 아니다.  
This means that there is an illegal character in the address I entered. It does not mean that I copied the actual address incorrectly or input the address of another Crypto currency.


결론은 아무런 일도 발생하지 않을 것이다.
The conclusion is that nothing will happens.

이를 자세히 알기위해서는 비트코인 지갑주소가 어떤식으로 구성되며, 어떻게 산출되는지를 알필요가 있다.
To know this in detail, it is necessary to know how the Bitcoin Address is constructed and how it is calculated.

본인이 비트코인 지갑을 하나 만들려고 한다. 지갑을 만들기위해 예를들어
지갑생성! 을 누르면 과연 어떤 과정을 거쳐 우리가 흔히 보는 큐알코드와 같은 지갑주소가 생성될까?

If you press the Create Wallet button to create a wallet, what process will create a wallet address like the QR code we often see?


발생하는 일은 매우 간단하다.
It's very simple.


1. 개인키가 생성된다.(Private Key) A private key is generated.
2. 개인키를 기반으로 공개키가 생성된다 (Public Key) A public key is generated based on the private key
3. 공개키를 기반으로 비트코인 주소가 생성된다. (Bitcoin Address) A Bitcoin Address is generated based on the public key.


위 그림이 아주 잘 표현되어있다. 개인키 -> 비트코인 주소까지 산출되는 과정이며, 그 역방향은 성립하지 않는다.
The picture above is very well represented. This is the process of calculating the private key to the bit coin address, and the reverse direction is not established.

그렇다면 각각의 과정을 자세히 알아보자.
Let's look at each process in detail.



1. 개인키 생성 Generate private key

* 이는 본인만 알고있어야 하는 비밀번호이기 때문에 최대한 겹칠일 없는 난수로 생성한다. 당연히 아무에게도 알려줘서는 안된다. 따라서 개인키를 도출할 프로젝트를 진행한다면 암호학적으로 안전한 난수생성기를 사용하기 바란다.

This is a password that should be known only to you, so it is generated with random numbers that do not overlap as much as possible. Of course you should not tell anyone. Therefore, if you are going to develop project with private key, please use a cryptographically secure random number generator.


- 개인키는 1~2^256 승 사이의 random number이다.  The private key is a random number between 1 and 2 ^ 256.
- 이를 발생하기위해 운영체제인 난수생성기를 이용하여 256비트의 무작위성(엔트로피)를 만들어낸다.
To generate this, a random number generator, which is an operating system, is used to generate 256 bits of randomness (entropy).
- 아래 같은 꼴의 개인키가 생성될 것다. A private key of the form below will be generated.
   18E14A7B6A307F426A94F8114701E7C8E774E7F9A47E2C2035DB29A206321725

2. 공개키 생성 Generate public key

* 개인키를 바탕으로 공개키가 만들어진다. 타원곡선 암호법(https://steemit.com/kr/@icoreport/key-2-ecc)을 이용하며 공식은 K(공개키) = k(개인키) * G(생성포인트 상수) 이다.
public key is created based on the private key. Elliptic curve cryptography is used and the formula is K (public key) = k (private key) * G (creation point constant)


- 개인키 -> 공개키는 개인키*G를 통해 알수 있으나, 공개키/G 를 하면 개인키를 알수 있지 않느냐? 알수없다. 이를 이해하기 위해서는 타원곡선 암호법을 먼저 이해해야 할것이다. 위 링크를 참조하기 바란다.
The private key -> public key is known through the private key * G. Do you know the private key when you use public key / G ? I can not know. To understand this, elliptic curve cryptography should be understood first. Please see the link above.

3. 비트코인 주소 Bitcoin Address

* 참고로, 해시함수란? 특정데이터를 일정한 길이의 데이터로 바꾸어 주는 역할한다. SHA256은 어떤 데이터가 오던지 256비트(32바이트) 데이터로 바꾸어 줄수 있기에 사용된다.
For reference, what is a hash function? It converts specific data into data of a certain length. The SHA256 is used to convert any data into 256-bit (32-byte) data.


* K = k * G 공식을 통해 공개키 까지 알아냈다.
We have figured out the public key through the formula K = k * G.


이후 작업은 보안해시알고리즘(SHA256) 과 RACE Integrity Primitives Evaluation Message Digest(RIPEMD 160) 를 이용하여 더블 해시작업을 통해 공개키 -> 더블해시 결과값 을 얻어낸다.(더블 해시를 하지않고 160비트 해시를 사용해도 된다, 굳이 더블 해싱을 하는지는 잘 모르겠다 아래 그림에서도 더블해쉬 or HASH160 이라고 표기되어 있다) 160 비트의 데이터로 공개키를 바꾸어 주었다.
Subsequent operations use a secure hash algorithm (SHA256) and the RACE Integrity Primitives Evaluation Message Digest (RIPEMD 160) to obtain the public key -> double hash result (double - You can use a hash, I do not know if you are doing double hashing. In the picture below, it is also marked as double hash or HASH160.) I changed the public key with 160 bits of data.


간략히 공식으로 표현해보면
A = RIPEMD160 ( SHA256( K ) )    or    A = HASH160 ( K )
로  나타낼수 있겠다.
In short, I can express it like this formula. 


끝일까? NO! 이 값에는 0,o, I,1 등 햇갈리기 쉬운 문자들이 포함되어있다. 따라서 (0, 'o', 1, 'I', '+', '/') 문자를 제외한 BASE64인 BASE58인코딩을 사용하여 최종적으로 아래와 같은 공식이 산출된다.

Is it the end? NO! This value contains confusing characters such as 0, o, I, and 1. Therefore, the following formula is finally calculated using the BASE58 encoding of BASE64 excluding the characters (0, 'o', 1, 'I', '+', '/') 



BITCOIN ADDRESS = Base58CheckEncoding( A )


자, 이글의 원래 질문은 ' 비트코인 지갑주소를 잘못입력하여 전달하면 어떻게될까? ' 이다.
이 질문에 대한 답을 찾기위해 꽤 오래 걸어왔다.

위에 언급한 BASE58Check인코딩 방식에 이에 대한 해답이 나와있다. Base58CheckEncoding 을 사용하는 이유는 햇갈리는 문자 6개를 제외하여 주소값을 표현해 주기 위한 이유도 있지만 진짜 이유는 따로있다.

아래 그림을 자세히 보자.


Now, the original question for this article is, "What happens if I pass the wrong bitcoin purse address? ' to be. I have been walking for quite some time to find the answer to this question.  The answer to this is the BASE58Check encoding method mentioned above. The reason for using Base58CheckEncoding is that there are reasons to express the address value by excluding the six characters, but there is no real reason.  Let's look at the picture below.


Payload란 위에서 산출해 낸 A = RIPEMD160 ( SHA256( K ) ) 의 A값을 의미한다.
그림을 보면 (1) Add Version Prefix 라는 부분이 존재한다. 이는 비트코인을 생성할 주소가 어느 버전의 주소인지를 명시해주게 된다.
Payload means the A value of A = RIPEMD160 (SHA256 (K)) calculated above. (1) There is a part called Add Version Prefix. This specifies which version of the address to generate the bit coin.


만약 비트코인 메인넷에서 사용될 주소라면 0x00 접두부가 붙을 것이고, 어떤 개발자가 테스트넷에서 사용할 주소를 만든다면 0x6F가 붙을 것이고 p2sh 주소라면 0x05 의 접두부가 Version 부분에 붙을 것입니다.
If the address to be used in the Bitcoin MainNetwork is 0x00 prefix, if some developer makes an address to use in TestNet, it will be attached with 0x6F and if it is p2sh address, prefix 0x05 will be attached to Version part.

자 그렇다면 주소의 버전정보 V와 payload A를 가지고 checkSum을 만들어야 한다. Checksum이란 오류 검사코드이다.
If so, you need to create a checkSum with version V of the address and payload A. Checksum is an error check code.



CheckSum ( C ) = Front4Bytes(더블hash(V+A)) 를 통해 산출이 가능하다.
Computed via CheckSum (C) = Front4Bytes (double hash (V + A)).

우리가 흔히 보는 비트코인 주소는 그렇다면 V+A+C의 조합이라는 것을 알수 있는데, C 에는 이미 V + A의 더블해쉬값이기 때문에, 누군가 주소를 잘못입력했을시 이 CheckSum을 가지고 검사를 하면 되는 것이다. 체크섬 문자와, 가운데 V+A 중 어떤 문자를 동시에 잘못입력했는데 이 두가지가 우연히 맞을 확률은 아예 일어나지 않을것이다.
We can see that the bit coin address we commonly see is a combination of V + A + C, since C is already a double hash of V + A, so if someone has typed in the address incorrectly, we can check with this CheckSum. If you mistakenly enter a checksum character and a middle V + A character at the same time, the probability that these two will not happen at all will not happen at all.



이 정보를 가지고 올바른 주소 입력인지 아닌지 파악이 가능하다. checkSum 자체가 기존의 V+A의 해시값이기 때문이다.
With this information, it is possible to determine whether the correct address is input or not. This is because checkSum itself is a hash value of the existing V + A.


위 제목의 솔루션을 해결하기 위해 꽤 긴 설명이 필요했다.
A long explanation was needed to solve the solution in the title above.


혹시 부가적인 정보를 알고있는 사람이 있다면, 댓글 바란다.
If you have any additional information, please comment.



[그림 출처]
[도서 비트코인, 블록체인과 금융의 혁신]