-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
require和assert的gas消耗对比问题 #93
Comments
可能是因为require里包含了报错提示字符,字符越长gas消耗越多。另外例子中代码比较少,可能代码长一些,才能看出差别。 |
@edddyguo 可以用钱包连公链测试一下差异,remix提供的默认节点返回的gas应该是实际执行指令的gas cost,跟公链有差别 |
我在相应的require和assert的下方加入了一个for循环100次的逻辑,测试结果和原来的一直,assert都是将剩下的gas返还给user了,考虑到编译器版本的问题,我用0.6.4的编译器也是同样的测试结果,不知道为啥和搜到的文档里面描述的不一样 |
一直是用的rinkeby测试的 |
Panic exceptions used to use the invalid opcode before Solidity 0.8.0, which consumed all gas available to the call. 0.8.0以后,revert、require、assert的底层字节码都是revert。 |
我深入研究了一下: Assert
On execution of any invalid operation, whether the designated INVALID opcode or simply an undefined opcode, all remaining gas is consumed and the state is reverted to the point immediately prior to the beginning of the current execution context.
Require
Revert
Highlight以上讨论的topic都是 References
|
wow 详细 |
bravo! |
Note另外,在 Time logs
BTW,从这里我们可以看出来好像是Solidity语言先支持,然后EVM再支持,这个有点违反我的直觉了,没想通。References |
理论上require的报错会将余下的gas返回给user,而assert会全部没收,而15_Error中实验结果,是assert比require更少的损耗,问题出在哪里
The text was updated successfully, but these errors were encountered: