Skip to content

Commit

Permalink
Merge pull request #28 from devFallingstar/master
Browse files Browse the repository at this point in the history
Security Considerations 일뢀 λ²ˆμ—­
  • Loading branch information
devFallingstar committed Nov 27, 2018
2 parents a18f64b + cb60fa2 commit 6bfed3b
Showing 1 changed file with 25 additions and 38 deletions.
63 changes: 25 additions & 38 deletions security-considerations.rst
Original file line number Diff line number Diff line change
@@ -1,101 +1,88 @@
.. _security_considerations:

#######################
Security Considerations
λ³΄μ•ˆ μΈ‘λ©΄ 고렀사항
#######################

μ†Œν”„νŠΈμ›¨μ–΄λ₯Ό μ›ν•˜λŠ” λ°©μ‹μœΌλ‘œ μž‘λ™λ˜λ„λ‘ λ§Œλ“œλŠ” 것은 어렡지 μ•ŠμœΌλ‚˜, λ‹€λ₯Έ μ‚¬λžŒμ΄ μ›ν•˜μ§€ μ•ŠλŠ” λ°©μ‹μœΌλ‘œ μž‘λ™ν•˜μ§€ μ•Šλ„λ‘ ν™•μΈν•˜λŠ” 것은 맀우 μ–΄λ ΅λ‹€.
μ†Œν”„νŠΈμ›¨μ–΄λ₯Ό μ›ν•˜λŠ”λŒ€λ‘œ κ°œλ°œν•˜λŠ” 것은 어렡지 μ•Šμ§€λ§Œ, λ‹€λ₯Έ μ‚¬λžŒμ΄ μ•„μ˜ˆ λ‹€λ₯Έ μ˜λ„λ‘œ μž‘λ™μ‹œν‚€λŠ”κ±Έ λ§‰λŠ” 것은 μ–΄λ ΅μŠ΅λ‹ˆλ‹€.

μ†”λ¦¬λ””ν‹°μ—μ„œλŠ” ν† ν°μ΄λ‚˜ 심지어 더 κ°€μΉ˜μžˆλŠ” 것듀을 닀루기 λ•Œλ¬Έμ— μ΄λŸ¬ν•œ λ¬Έμ œλŠ” 특히 μ€‘μš”ν•˜λ‹€. λ”ν•΄μ„œ λͺ¨λ“  슀마트 μ½˜νŠΈλž™νŠΈλŠ” 곡개적으둜 μ‹€ν–‰λ˜κ³  λŒ€λΆ€λΆ„μ˜ μ†ŒμŠ€μ½”λ“œ λ˜ν•œ λˆ„κ΅¬λ‚˜ 확인 ν•  수 μžˆλŠ” κ²½μš°κ°€ λ§Žλ‹€.
μ†”λ¦¬λ””ν‹°μ—μ„œλŠ” λͺ¨λ“  슀마트 μ»¨νŠΈλž™νŠΈκ°€ 곡개적으둜 μ‹€ν–‰λ˜κ³  λŒ€λΆ€λΆ„μ˜ μ†ŒμŠ€μ½”λ“œλ₯Ό 확인할 수 μžˆλŠ” κ²½μš°κ°€ λ§ŽμŠ΅λ‹ˆλ‹€. λ”°λΌμ„œ 이런 λ³΄μ•ˆ 츑면의 고렀사항은 특히 더 μ€‘μš”ν•©λ‹ˆλ‹€.

λ¬Όλ‘  λ³΄μ•ˆμ— μ–Όλ§ˆλ‚˜ 신경을 써야 ν•˜λŠ” μ§€λŠ” 상황에 따라 λ‹€λ₯΄λ‹€. μ›Ή μ„œλΉ„μŠ€ λ˜ν•œ λŒ€μ€‘(μ•…μ˜μ μΈ 곡격자λ₯Ό ν¬ν•¨ν•œ) λˆ„κ΅¬λ‚˜ μ ‘κ·Όν•  수 있고 심지어 μ˜€ν”ˆμ†ŒμŠ€μΈ κ²½μš°λ„ μžˆλ‹€. λ§Œμ•½ μ›Ή μ„œλΉ„μŠ€μ— μžμž˜ν•œ μ •λ³΄λ“€λ§Œ μ €μž₯ν•œλ‹€λ©΄ λ³΄μ•ˆ λ¬Έμ œμ— 크게 신경쓰지 μ•Šμ•„λ„ λ˜μ§€λ§Œ, μ›Ή μ„œλΉ„μŠ€λ₯Ό ν†΅ν•΄μ„œ 은행 κ³„μ’Œλ₯Ό κ΄€λ¦¬ν•œλ‹€λ©΄ 쑰금 더 쑰심해야 ν•œλ‹€.
λ¬Όλ‘  λ³΄μ•ˆμ— μ–Όλ§ˆλ‚˜ 신경을 μ¨μ•Όν•˜λŠ” μ§€λŠ” 상황에 따라 λ‹€λ¦…λ‹ˆλ‹€. κ°€λ Ή, μ›Ή μ„œλΉ„μŠ€λŠ” 곡격자λ₯Ό ν¬ν•¨ν•œ λŒ€μ€‘μ—κ²Œ κ³΅κ°œλ˜μ–΄μ•Όν•˜κ³ , λˆ„κ΅¬λ‚˜ μ ‘κ·Όν•  수 μžˆμ–΄μ•Όν•˜λ©°, μ–΄λ–€ λ•Œμ—λŠ” μ˜€ν”ˆμ†ŒμŠ€λ‘œ κ΄€λ¦¬λ˜λŠ” κ²½μš°λ„ μžˆμŠ΅λ‹ˆλ‹€. λ§Œμ•½ μ›Ή μ„œλΉ„μŠ€μ— μ€‘μš”μΉ˜ μ•Šμ€ μ •λ³΄λ§Œ μ €μž₯ν•œλ‹€λ©΄ λ¬Έμ œκ°€ λ˜μ§€ μ•Šμ§€λ§Œ, 은행 κ³„μ’Œμ™€ 같은 정보λ₯Ό κ΄€λ¦¬ν•œλ‹€λ©΄ λ”μš± 쑰심할 ν•„μš”κ°€ 있죠.

이 μž₯μ—μ„œλŠ” 쑰심할 λ¬Έμ œλ“€κ³Ό 일반적인 λ³΄μ•ˆκ΄€λ ¨ νŒ¨ν„΄λ“€μ„ λ‹€λ£¨μ§€λ§Œ μ™„λ²½ν•œ 것은 μ•„λ‹ˆλ‹€. λͺ…심할 것은 슀마트 μ½˜νŠΈλž™νŠΈμ— μ•„λ¬΄λŸ° 버그가 없더라도, μ»΄νŒŒμΌλŸ¬λ‚˜ ν”Œλž«νΌ μžμ²΄μ—λŠ” 버그가 μžˆμ„ 수 μžˆλ‹€λŠ” 점이닀.
이 μž₯μ—μ„œλŠ” 쑰심해야할 λ¬Έμ œλ“€κ³Ό 일반적인 λ³΄μ•ˆκ΄€λ ¨ νŒ¨ν„΄λ“€μ„ λ‹€λ£Ήλ‹ˆλ‹€. ν•˜μ§€λ§Œ μ΄λŠ” μ™„λ²½ν•œ 해결법이 μ•„λ‹™λ‹ˆλ‹€. 즉, 슀마트 μ»¨νŠΈλž™νŠΈ μƒμ—λŠ” 버그가 없더라도, μ»΄νŒŒμΌλŸ¬λ‚˜ ν”Œλž«νΌ μžμ²΄μ— 버그가 μžˆμ„ 수 μžˆλ‹€λŠ” μ–˜κΈ°μ£ .

μ–Έμ œλ‚˜ 그렇듯이, 이 λ¬Έμ„œλŠ” μ˜€ν”ˆ μ†ŒμŠ€ 기반의 λ¬Έμ„œμ΄κΈ° λ•Œλ¬Έμ—, λ³΄μ•ˆμ— λŒ€ν•œ λ¬Έμ œκ°€ 생긴닀면 주저없이 λ‚΄μš©μ„ μΆ”κ°€ν•΄μ£Όμ‹œκΈ° λ°”λžλ‹ˆλ‹€.

********
Pitfalls
μœ μ˜μ‚¬ν•­
********

Private Information and Randomness
개인 정보와 λ¬΄μž‘μœ„μ„±
==================================

Everything you use in a smart contract is publicly visible, even
local variables and state variables marked ``private``.
슀마트 μ»¨νŠΈλž™νŠΈ μƒμ˜ λͺ¨λ“  μ •λ³΄λŠ” 곡개적으둜 λ³΄μ—¬μ§‘λ‹ˆλ‹€. 심지어 지역 λ³€μˆ˜ 및 μƒνƒœ λ³€μˆ˜κ°€ ``private``으둜 μ„ μ–Έλ˜μ—ˆλ‹€κ³ ν•΄λ„ λ§ˆμ°¬κ°€μ§€μ£ .
Using random numbers in smart contracts is quite tricky if you do not want
miners to be able to cheat.
λ§Œμ•½ 당신이 μ±„κ΅΄μžμ˜ λΆ€μ • ν–‰μœ„λ₯Ό λ§‰κ³ μž ν•œλ‹€λ©΄, λ‚œμˆ˜λ₯Ό μƒμ„±ν•˜λŠ” 것이 μ–΄λŠμ •λ„ μœ μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
Re-Entrancy
μž¬μ§„μž… 문제
===========
Any interaction from a contract (A) with another contract (B) and any transfer
of Ether hands over control to that contract (B). This makes it possible for B
to call back into A before this interaction is completed. To give an example,
the following code contains a bug (it is just a snippet and not a
complete contract):
(A)μ½˜νŠΈλž™νŠΈμ—μ„œ (B)μ½˜νŠΈλž™νŠΈλ‘œ μ—°κ²°λ˜λŠ” μ–΄λ– ν•œ μƒν˜Έμž‘μš© 및 Ether의 전솑은 μ œμ–΄κΆŒμ„ (B)μ—κ²Œ λ„˜κ²¨μ£Όκ²Œ λ©λ‹ˆλ‹€. 이 λ•Œλ¬Έμ— B의 μƒν˜Έμž‘μš©μ΄ λλ‚˜κΈ° 전에 λ‹€μ‹œ Aλ₯Ό ν˜ΈμΆœν•  수 μžˆλŠ” 상황이 λ²Œμ–΄μ§ˆ 수 μžˆμŠ΅λ‹ˆλ‹€. 예λ₯Ό λ“€μ–΄, λ‹€μŒ μ½”λ“œλŠ” 버그λ₯Ό ν¬ν•¨ν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€(μš”μ•½λœ μ½”λ“œμž…λ‹ˆλ‹€).
::
pragma solidity ^0.4.0;
// THIS CONTRACT CONTAINS A BUG - DO NOT USE
// 버그가 ν¬ν•¨λœ μ½”λ“œμž…λ‹ˆλ‹€. μ‚¬μš©ν•˜μ§€ λ§ˆμ„Έμš”!
contract Fund {
/// Mapping of ether shares of the contract.
/// μ»¨νŠΈλž™νŠΈμ˜ Ether 정보 mapping
mapping(address => uint) shares;
/// Withdraw your share.
/// 지뢄을 μΈμΆœν•˜λŠ” ν•¨μˆ˜
function withdraw() public {
if (msg.sender.send(shares[msg.sender]))
shares[msg.sender] = 0;
}
}
The problem is not too serious here because of the limited gas as part
of ``send``, but it still exposes a weakness: Ether transfer can always
include code execution, so the recipient could be a contract that calls
back into ``withdraw``. This would let it get multiple refunds and
basically retrieve all the Ether in the contract. In particular, the
following contract will allow an attacker to refund multiple times
as it uses ``call`` which forwards all remaining gas by default:
``send``ν•¨μˆ˜ μžμ²΄μ—μ„œ gas의 μ†ŒλΉ„λŸ‰μ„ μ œμ–΄ν•˜κΈ° λ•Œλ¬Έμ—, 큰 λ¬Έμ œλŠ” λ˜μ§€ μ•Šμ§€λ§Œ, κ·ΈλŸΌμ—λ„ 이 μ½”λ“œλŠ” λ³΄μ•ˆ μƒμ˜ 문제λ₯Ό 가지고 μžˆμŠ΅λ‹ˆλ‹€.
Ether의 전솑은 항상 μ½”λ“œμ˜ 싀행을 ν¬ν•¨ν•˜κΈ°μ—, μˆ˜μ‹ μžλŠ” 반볡적으둜 ``withdraw``λ₯Ό μ‹€ν–‰ν•  수 있게되죠. 결과적으둜 μ€‘λ³΅λœ ``withdraw``ν•¨μˆ˜μ˜ 싀행을 톡해 μ»¨νŠΈλž™νŠΈ μƒμ˜ λͺ¨λ“  Etherλ₯Ό κ°€μ Έκ°ˆ 수 μžˆλ‹€λŠ” μ˜λ―Έμž…λ‹ˆλ‹€. 상황에 따라, κ³΅κ²©μžλŠ” μ•„λž˜ μ½”λ“œ 속 ``call``을 톡해 남은 gasλ₯Ό λͺ¨λ‘ κ°€μ Έμ˜¬ 수 μžˆμ„μ§€λ„ λͺ¨λ¦…λ‹ˆλ‹€.
::
pragma solidity ^0.4.0;
// THIS CONTRACT CONTAINS A BUG - DO NOT USE
// 버그가 ν¬ν•¨λœ μ½”λ“œμž…λ‹ˆλ‹€. μ‚¬μš©ν•˜μ§€ λ§ˆμ„Έμš”!
contract Fund {
/// Mapping of ether shares of the contract.
/// μ»¨νŠΈλž™νŠΈμ˜ Ether 정보 mapping
mapping(address => uint) shares;
/// Withdraw your share.
/// 지뢄을 μΈμΆœν•˜λŠ” ν•¨μˆ˜
function withdraw() public {
if (msg.sender.call.value(shares[msg.sender])())
shares[msg.sender] = 0;
}
}
To avoid re-entrancy, you can use the Checks-Effects-Interactions pattern as
outlined further below:
μž¬μ§„μž… 곡격을 막기 μœ„ν•΄μ„œλŠ” μ•„λž˜μ™€ 같이 Checks-Effects-Interactions νŒ¨ν„΄μ„ μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
::
pragma solidity ^0.4.11;
contract Fund {
/// Mapping of ether shares of the contract.
/// μ»¨νŠΈλž™νŠΈμ˜ Ether 정보 mapping
mapping(address => uint) shares;
/// Withdraw your share.
/// 지뢄을 μΈμΆœν•˜λŠ” ν•¨μˆ˜
function withdraw() public {
var share = shares[msg.sender];
shares[msg.sender] = 0;
msg.sender.transfer(share);
}
}
Note that re-entrancy is not only an effect of Ether transfer but of any
function call on another contract. Furthermore, you also have to take
multi-contract situations into account. A called contract could modify the
state of another contract you depend on.
μž¬μ§„μž… 곡격은 Ether μ „μ†‘μ—μ„œ 뿐만 μ•„λ‹ˆλΌ ν•¨μˆ˜λ₯Ό ν˜ΈμΆœν•˜λŠ” μ–΄λ–€ μƒν™©μ—μ„œλ„ μˆ˜ν–‰λ  수 μžˆμŠ΅λ‹ˆλ‹€. λ‚˜μ•„κ°€, μ—¬λŸ¬λΆ„μ€ ν•˜λ‚˜μ˜ 계정에 λ§Žμ€ μ»¨νŠΈλž™νŠΈλ₯Ό κ°€μ§ˆ μˆ˜λ„ μžˆμ„ ν…λ°μš”, 이 λ•Œ, ν•˜λ‚˜μ˜ μ»¨νŠΈλž™νŠΈκ°€ λ‹€λ₯Έ μ»¨νŠΈλž™νŠΈλ₯Ό ν˜ΈμΆœν•  수 μžˆλ‹€λŠ” 것도 μ•Œμ•„λ‘¬μ•Όν•©λ‹ˆλ‹€.
Gas Limit and Loops
===================
Expand Down

0 comments on commit 6bfed3b

Please sign in to comment.