标签: evm

我可以根据 RSK 和以太坊的平均区块时间,使用区块高度来衡量一年的流逝吗?

我想在 RSK 和以太坊中构建一个每年支付股息的 Solidity 智能合约。假设 RSK 和以太坊当前的平均块间时间,我应该使用块时间还是可以依赖块编号?

blockchain ethereum evm rsk

8
推荐指数
1
解决办法
449
查看次数

我尝试使用 cmake 来制作项目,但它调用了错误 ld: library not found for -levmc::loader

我 git clone 了一个名为evmc 的项目

\n

我尝试构建示例文件夹通过 cmake 在此项目中但这里有一些错误称为:

\n

cmake .

\n
-- Configuring done\nCMake Error at CMakeLists.txt:23 (add_executable):\n  Target "evmc-example" links to target "evmc::evmc_cpp" but the target was\n  not found.  Perhaps a find_package() call is missing for an IMPORTED\n  target, or an ALIAS target is missing?\n\n\nCMake Error at CMakeLists.txt:23 (add_executable):\n  Target "evmc-example" links to target "evmc::loader" but the target was not\n  found.  Perhaps a find_package() call is missing for an IMPORTED target, or\n …
Run Code Online (Sandbox Code Playgroud)

c++ makefile cmake ethereum evm

5
推荐指数
1
解决办法
1万
查看次数

Solidity 0.8+ 版本中是否需要 SafeMath ,如果不需要,是否还可以导入它?

我有这样的 Solidity 智能合约,pragma solidity >=0.7.0 <0.9.0;即使 0.8+ 不需要它,我仍然可以导入 SafeMath 吗?由于 SafeMath 使用的是 0.7,但我的合同指定它接受 0.7.0 至低于 0.9.0,在这种情况下 SafeMath 会做什么。

ethereum solidity smartcontracts evm

5
推荐指数
1
解决办法
1万
查看次数

从 geth 事务跟踪中提取发出的事件(日志)(debug_traceCall)

使用debug_traceCall时,我可以获得执行期间所有操作码和状态更改的低级 EVM 跟踪。这实在是太详细了。当我使用 default 时callTracer,我可以获得更好的调用树。但是,无论哪种方式,我似乎都无法从跟踪中提取发出的事件。我可以在跟踪(LOG*操作码)中看到它们,但是没有简单的方法可以将它们实际解析为“可读”的东西(以及值和原始地址)必须有一种方法来获取日志 - 有什么想法吗?

例如。这是 Etherscan 显示的https://etherscan.io/tx-decoder?tx=0x3e3ad35fda1fddd9e154b3860b50371a1acd2fdb4f27f897e234846522bde732(请参阅“发出的事件”部分)

ethereum evm go-ethereum geth

5
推荐指数
1
解决办法
3121
查看次数

为什么在这个智能合约上使用断言?

contract Sharer {
    function sendHalf(address payable addr) public payable returns (uint balance) {
        require(msg.value % 2 == 0, "Even value required.");
        uint balanceBeforeTransfer = address(this).balance;
        addr.transfer(msg.value / 2);
        // Since transfer throws an exception on failure and
        // cannot call back here, there should be no way for us to
        // still have half of the money.
        assert(address(this).balance == balanceBeforeTransfer - msg.value / 2);
        return address(this).balance;
    }
}
Run Code Online (Sandbox Code Playgroud)

对于上述合约,在什么情况下断言失败/address(this).balance 不会减少 (msg.value / 2)?为什么我们需要在这里断言?

assert solidity evm

4
推荐指数
1
解决办法
518
查看次数

Solidity Assembly、mstore 函数和一个字的宽度(以字节为单位)

我正在学习 Solidity Assembly,但我对某些事情感到困惑。我正在查看这个名为 Seriality 的库。具体来说,这个函数:https : //github.com/pouladzade/Seriality/blob/master/src/TypesToBytes.sol#L21

function bytes32ToBytes(uint _offst, bytes32 _input, bytes memory _output) internal pure {
    assembly {
        mstore(add(_output, _offst), _input)
        mstore(add(add(_output, _offst),32), add(_input,32))
    }
}
Run Code Online (Sandbox Code Playgroud)

该函数 bytes32ToBytes 接受一个 bytes32 变量并将其存储在动态大小的字节数组中,从传入的偏移量开始。

让我困惑的是它使用了 mstore 函数两次。但是mstore函数存储了一个词,是32个字节,对吧?既然输入是 32 个字节,那么为什么它会被调用两次呢?不会调用它两次存储 2 个字,即 64 个字节?

谢谢!

ethereum solidity smartcontracts evm

3
推荐指数
1
解决办法
723
查看次数

如何为 Substrate 运行时实现 EVM Trait?

在向运行时添加模块之后,我尝试为Dothereum 运行时实现Parity Substrate 特征。paint-evm

EVM模块特征定义如下:

pub trait Trait: Trait + Trait {
    type FeeCalculator: FeeCalculator;
    type ConvertAccountId: ConvertAccountId<Self::AccountId>;
    type Currency: Currency<Self::AccountId>;
    type Event: From<Event> + Into<Self::Event>;
    type Precompiles: Precompiles;
}
Run Code Online (Sandbox Code Playgroud)

然而,这里添加模块的教程有点含糊,鼓励人们:

“.. 如果事情没有意义,请探索 [..] 模块的源代码 ..”

虽然 EVM 模块代码看起来不太复杂,但我无法理解如何为我的运行时实现 EVM 特征:

impl evm::Trait for Runtime {
    type FeeCalculator = ();
    type ConvertAccountId = ();
    type Currency = Balances; 
    type Event = Event;
    type Precompiles = ();
}
Run Code Online (Sandbox Code Playgroud)

这里有什么类型的人FeeCalculator以及ConvertAccountId期望什么类型的人?

rust ethereum evm parity-io substrate

3
推荐指数
1
解决办法
440
查看次数

在solidity中动态创建变量

我想在我的合约中包含一个内部方法,该方法允许在由参数命名的存储中创建一个新的 uint256。就像是:

function createUint (string memory _name) internal {
    /*
     * creates a new uint256 named _name in storage
     */
}
Run Code Online (Sandbox Code Playgroud)

我的猜测是它需要内联汇编,但我不知道如何

inline-assembly ethereum solidity evm

1
推荐指数
1
解决办法
1049
查看次数

Solidity 汇编错误:必须调用内置函数“gas”

我正在用 Solidity 编写代理合约。为了在我的后备函数中转发传入呼叫,我使用内联汇编代码。我是一名学生,下面的代码是我的老师在教程中编写的代码。

不过,我的代码收到以下错误:

必须调用内置函数“gas”。

我假设自本教程制作以来 Solidity 已经不断发展,但我在网上找不到任何东西(谷歌或文档)。

这是代码:

assembly {
        let result := delegatecall(gas, implementation, add(data, 0x20), mload(data), 0, 0)
        let size := returndatasize
        let ptr := mload(0x40)
        returndatacopy(ptr, 0, size)
        switch result   
        case 0 {revert(ptr, size)}  
        default{return(ptr, size)}  
}
Run Code Online (Sandbox Code Playgroud)

该错误是指第 2 行中带有红色下划线的单词“gas”。
有什么改变吗?

assembly solidity evm

1
推荐指数
1
解决办法
1480
查看次数