我想考虑一个场景,假设合同使用send执行传输。此时,气体耗尽发生,并送回-1。现在合同没有天然气,发送不恢复,EVM会发生什么情况,它会因为没有气体而阻塞吗?EVM将如何摆脱这种阻塞局面?请提供一些从Ethereum文档的链接。
contract TestOutofGas{
:
:
function transaction(address otherContract, uint x) public returns () {
:
retVal = otherContract.send(1000);//out of gas
bool success = findPrime(x);
:
:
}//func transaction
}//contract OutofGas假设另一种情况,
contract TestOutofGas{
uint trnNo=0;
:
function transaction(address otherContract) public returns (uint) {
:
retVal = otherContract.send(1000);//out of gas
require(retVal);
trnNo++;
:
:
}//func ends
}//contract endsEVM是否能够执行需求(…)?如果合同没有任何气体的指示?
祖尔菲。
发布于 2021-02-28 03:56:06
让我们分析第二个案例
function transaction(address otherContract) public returns (uint) {
:
retVal = otherContract.send(1000);//out of gas
require(retVal);
trnNo++;
:
:
}//func ends当otherContract.send失败时,EVM正在处理一个调用操作码,它将在顶部堆栈条目中留下0 (false)。
EVM将尝试执行下一个操作码,将0赋值给retVal。无论它试图执行的操作码是什么,如果没有足够的汽油来支付,EVM将立即停止任何更改。
require()是返回错误消息的一种奇特的方法。如果存在诸如除法、无效操作码等错误,EVM可以在不需要的情况下恢复。
https://ethereum.stackexchange.com/questions/93955
复制相似问题