비탈릭이 이더리움 스마트 컨트랙트를 위한 새로운 언어 개발에 몰두하고 있답니다.
이미 3가지의 언어가 있지만, 이번 개스비를 두고 이루어진 DoS 공격에 대햔 보다 근본적인 해결책을 모색하고 있는 것 같습니다.
새 언어의 이름은 viper 입니다. 아직 아이디어 단계이지만, 기본골격은 거의 갖추어진 것 같군요.
파이썬에 익숙한 사람에게는 이해하기 쉬운 것 같군요. 스트롱 타입을 가지고 있는 점이 파이썬과는 다르네요.
그리고 개스 계산을 정확히 하기 위해 while 문을 지원하지 않고, 정해진 루프 숫자를 쓰는 for 구문만 지원하는군요.
https://github.com/ethereum/viper
the features in Viper are:
- Types. Serpent had not types, and you could even do things like
seq(x = array(5), y = array(5), z=x + y)
and get out a completely random memory location that could theoretically point to anything. Viper prevents you from doing something that silly, and only allows you to add things that are numbers, doesn't allow you to array-access things that are not arrays, etc. Types can be either inferred, or can be declared via thex = type
syntax. - There are five major types supported: num, decimal, address, bytes32, bool. Num are 128-bit signed numbers (this makes overflow checking easier), decimals are fixed point numbers where the integral component is 128-bit signed and the fractional component is base-10 with ten decimal places. Decimal fixed point is considered to be a very good choice in finance due to its ability to exactly store base-10 fractional values (eg. $15.2857) and is even mandated in some applications for this reason. Addresses, bytes32 and booleans are self-explanatory.
- Total functional. There are no
while
loops; the only looping construct that exists is afor i in range(n): do_stuff
statement, wheren
MUST be a constant nonzero positive integer. This means that for allvalid Viper code it is possible to compute a precise upper-limit on gas consumption, resolving many classes of security issues. - Same sorts of complex and composite data structures that you can find in Serpent
- ABI compatibility
- Bounds checking for array accesses
- Overflow and zero-division checking for arithmetic
Here is a code example:
# Global variables
funders = {num: [sender(address), value(num)]}
nextFunderIndex = num
beneficiary = address
deadline = num
goal = num
refundIndex = num
# Constructor
def __init__(_beneficiary: address, _goal: num, _timelimit: num):
self.beneficiary = _beneficiary
self.deadline = block.timestamp + _timelimit
self.goal = _goal
# Participate in the crowdfund
def participate():
assert block.timestamp < self.deadline
nfi = self.nextFunderIndex
self.funders[nfi].sender = msg.sender
self.funders[nfi].value = msg.value
self.nextFunderIndex = nfi + 1
# Is the crowdfund expired?
def expired() -> bool(const):
return block.timestamp >= self.deadline
# Has the goal been reached?
def reached() -> bool(const):
return self.balance >= self.goal
# Send money to beneficiary if sufficient
def finalize():
assert block.timestamp >= self.deadline and self.balance >= self.goal
selfdestruct(self.beneficiary)
# If balance insufficient, refund
def refund():
assert block.timestamp >= self.deadline and self.balance < self.goal
# Refund everyone in a loop
ind = self.refundIndex
for i in range(30):
if ind + i >= self.nextFunderIndex:
self.refundIndex = self.nextFunderIndex
return
send(self.funders[ind + i].sender, self.funders[ind + i].value)
self.funders[ind + i].sender = "0x0000000000000000000000000000000000000000"
self.funders[ind + i].value = 0
self.refundIndex = ind + 30
Compiler and tests are here: http://github.com/ethereum/viper
매번 소식 감사합니다. 이더리움은 흔들리지 않고 묵묵히 진행 중이군요.