류짱 avatar

[KR][마루타] revert() assert() require() 뭔 차이지..

ryugihyeok

Published: 25 Apr 2018 › Updated: 25 Apr 2018[KR][마루타] revert() assert() require() 뭔 차이지..

[KR][마루타] revert() assert() require() 뭔 차이지..

뭐 검색해보면 블라블라 영어로 되어있어서..

그냥 리믹스에 해보았다..

require()

function aa(){

   require(1 != 1);

   for(uint i = 0; i < 100; i++){ }

}

transaction cost    60942 gas 

execution cost       82 gas 

assert()

function aa(){

   assert(1 != 1);

   for(uint i = 0; i < 100; i++){ }

}

 transaction cost    3000000 gas 

 execution cost    2939280 gas 

revert()

function aa(){

   if(1 != 1)

       revert();

      for(uint i = 0; i < 100; i++){ }

}

 transaction cost    77127 gas 

 execution cost    16335 gas 

결론

require은 조건에 맞지 않으면 return 시켜서 로직을 끝낸다. 그러므로 유저는 불필요한 로직을 실행 시키지 않고, 남은 Gas비용을 환불 받을 수 있다.

일반적으로 함수 초입 부분에 사용 되며, 인자 값을 비교할 때 자주 사용해야한다고 한다.

assert는 조건에 맞지 않아도 해당 function은 끝까지 돌아간다. 환불 받을 수는 있지만, 불필요한 로직도 다 실행 되고, Gas비용을 환불 받으니까. require 보다는 적게 받거나, 못 받을 것 같다.

변경 후 상태 확인 / 절대 불가능한 로직 검사 / 오버플로우 언더플로우 검사 / 일반적으로 함수의 끝 부분에 사용된다고 한다.

revert() 이 친구는 퍼포먼스? 옵코드? 가 다르다고 말씀해주시는데..

더 공부해봐야겠다.

Leave [KR][마루타] revert() assert() require() 뭔 차이지.. to:

Written by

류짱과 함께하는 암호화화폐

Read more #kr posts


Best Posts From 류짱

We have not curated any of ryugihyeok's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From 류짱