ciri 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rspec +0 -1
- data/Gemfile.lock +11 -7
- data/LICENSE.txt +201 -21
- data/README.md +78 -25
- data/Rakefile +45 -17
- data/bin/bundle +105 -0
- data/bin/htmldiff +29 -0
- data/bin/ldiff +29 -0
- data/bin/rake +29 -0
- data/bin/rspec +29 -0
- data/ciri-crypto/.gitignore +11 -0
- data/ciri-crypto/.rspec +3 -0
- data/ciri-crypto/.travis.yml +5 -0
- data/ciri-crypto/CODE_OF_CONDUCT.md +74 -0
- data/ciri-crypto/Gemfile +6 -0
- data/ciri-crypto/Gemfile.lock +43 -0
- data/ciri-crypto/LICENSE.txt +201 -0
- data/ciri-crypto/README.md +58 -0
- data/ciri-crypto/Rakefile +6 -0
- data/ciri-crypto/bin/console +14 -0
- data/ciri-crypto/bin/setup +8 -0
- data/ciri-crypto/ciri-crypto.gemspec +40 -0
- data/ciri-crypto/lib/ciri/crypto/errors.rb +29 -0
- data/ciri-crypto/lib/ciri/crypto/signature.rb +71 -0
- data/ciri-crypto/lib/ciri/crypto/version.rb +5 -0
- data/{lib → ciri-crypto/lib}/ciri/crypto.rb +16 -69
- data/ciri-crypto/spec/ciri/crypto_spec.rb +56 -0
- data/ciri-crypto/spec/spec_helper.rb +14 -0
- data/ciri-rlp/Gemfile.lock +5 -5
- data/ciri-rlp/LICENSE.txt +201 -21
- data/ciri-rlp/README.md +1 -1
- data/ciri-rlp/ciri-rlp.gemspec +3 -3
- data/ciri-rlp/lib/ciri/rlp/decode.rb +10 -16
- data/ciri-rlp/lib/ciri/rlp/encode.rb +10 -16
- data/ciri-rlp/lib/ciri/rlp/serializable.rb +10 -16
- data/ciri-rlp/lib/ciri/rlp.rb +10 -16
- data/ciri-rlp/spec/ciri/fixture_spec.rb +10 -16
- data/ciri-rlp/spec/ciri/rlp/serializable_spec.rb +10 -16
- data/ciri-utils/Gemfile.lock +4 -4
- data/ciri-utils/LICENSE.txt +201 -21
- data/ciri-utils/README.md +1 -1
- data/ciri-utils/ciri-utils.gemspec +2 -2
- data/ciri-utils/lib/ciri/utils/logger.rb +10 -16
- data/ciri-utils/lib/ciri/utils/number.rb +10 -16
- data/ciri-utils/lib/ciri/utils/version.rb +1 -1
- data/ciri-utils/lib/ciri/utils.rb +3 -3
- data/ciri.gemspec +4 -3
- data/docker/{Base → Dockerfile} +9 -3
- data/lib/ciri/actor.rb +10 -16
- data/lib/ciri/bloom_filter.rb +11 -17
- data/lib/ciri/chain/block.rb +10 -16
- data/lib/ciri/chain/header.rb +12 -18
- data/lib/ciri/chain/header_chain.rb +8 -22
- data/lib/ciri/chain/transaction.rb +38 -33
- data/lib/ciri/chain.rb +27 -26
- data/lib/ciri/core_ext.rb +61 -0
- data/lib/ciri/db/account_db.rb +25 -21
- data/lib/ciri/db/backend/memory.rb +10 -16
- data/lib/ciri/db/backend/rocks.rb +10 -16
- data/lib/ciri/db/backend/rocks_db.rb +10 -16
- data/lib/ciri/devp2p/peer.rb +10 -16
- data/lib/ciri/devp2p/protocol.rb +10 -16
- data/lib/ciri/devp2p/protocol_io.rb +10 -16
- data/lib/ciri/devp2p/rlpx/connection.rb +10 -16
- data/lib/ciri/devp2p/rlpx/encryption_handshake.rb +13 -19
- data/lib/ciri/devp2p/rlpx/error.rb +10 -16
- data/lib/ciri/devp2p/rlpx/frame_io.rb +10 -16
- data/lib/ciri/devp2p/rlpx/message.rb +10 -16
- data/lib/ciri/devp2p/rlpx/node.rb +10 -16
- data/lib/ciri/devp2p/rlpx/protocol_handshake.rb +10 -16
- data/lib/ciri/devp2p/rlpx/protocol_messages.rb +10 -16
- data/lib/ciri/devp2p/rlpx/secrets.rb +10 -16
- data/lib/ciri/devp2p/rlpx.rb +10 -16
- data/lib/ciri/devp2p/server.rb +10 -16
- data/lib/ciri/eth/peer.rb +10 -16
- data/lib/ciri/eth/protocol_manage.rb +10 -16
- data/lib/ciri/eth/protocol_messages.rb +10 -16
- data/lib/ciri/eth/synchronizer.rb +10 -16
- data/lib/ciri/eth.rb +10 -16
- data/lib/ciri/ethash.rb +10 -16
- data/lib/ciri/evm/block_info.rb +25 -17
- data/lib/ciri/evm/errors.rb +13 -16
- data/lib/ciri/evm/execution_context.rb +136 -0
- data/lib/ciri/evm/instruction.rb +17 -24
- data/lib/ciri/evm/log_entry.rb +12 -18
- data/lib/ciri/evm/machine_state.rb +28 -33
- data/lib/ciri/evm/op.rb +52 -89
- data/lib/ciri/evm/op_call.rb +114 -0
- data/lib/ciri/evm/precompile_contract.rb +102 -0
- data/lib/ciri/evm/state.rb +28 -21
- data/lib/ciri/evm/sub_state.rb +18 -24
- data/lib/ciri/evm/vm.rb +128 -190
- data/lib/ciri/evm.rb +77 -85
- data/lib/ciri/forks/base.rb +28 -16
- data/lib/ciri/forks/byzantium.rb +43 -0
- data/lib/ciri/forks/config.rb +36 -0
- data/lib/ciri/forks/frontier/cost.rb +42 -33
- data/lib/ciri/forks/frontier.rb +47 -18
- data/lib/ciri/forks/homestead/cost.rb +195 -0
- data/lib/ciri/forks/homestead.rb +46 -0
- data/lib/ciri/forks.rb +12 -22
- data/lib/ciri/key.rb +14 -3
- data/lib/ciri/pow.rb +11 -17
- data/lib/ciri/rlp/decode.rb +10 -16
- data/lib/ciri/rlp/encode.rb +10 -16
- data/lib/ciri/rlp/serializable.rb +10 -16
- data/lib/ciri/serialize.rb +14 -17
- data/lib/ciri/trie/nibbles.rb +10 -16
- data/lib/ciri/trie/nodes.rb +12 -17
- data/lib/ciri/trie.rb +12 -18
- data/lib/ciri/types/account.rb +15 -17
- data/lib/ciri/types/address.rb +11 -17
- data/lib/ciri/types/errors.rb +10 -16
- data/lib/ciri/types/receipt.rb +12 -18
- data/lib/ciri/types/uint.rb +79 -0
- data/lib/ciri/version.rb +1 -1
- data/lib/ciri.rb +10 -16
- metadata +54 -10
- data/lib/ciri/types/number.rb +0 -73
|
@@ -1,24 +1,18 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# Copyright
|
|
3
|
+
# Copyright 2018 Jiang Jinyang <https://justjjy.com>
|
|
4
4
|
#
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
# furnished to do so, subject to the following conditions:
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
11
8
|
#
|
|
12
|
-
#
|
|
13
|
-
# all copies or substantial portions of the Software.
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
14
10
|
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
# THE SOFTWARE.
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
22
16
|
|
|
23
17
|
|
|
24
18
|
require 'ciri/actor'
|
|
@@ -1,24 +1,18 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# Copyright
|
|
3
|
+
# Copyright 2018 Jiang Jinyang <https://justjjy.com>
|
|
4
4
|
#
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
# furnished to do so, subject to the following conditions:
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
11
8
|
#
|
|
12
|
-
#
|
|
13
|
-
# all copies or substantial portions of the Software.
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
14
10
|
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
# THE SOFTWARE.
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
22
16
|
|
|
23
17
|
|
|
24
18
|
require 'ciri/chain'
|
|
@@ -1,24 +1,18 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# Copyright
|
|
3
|
+
# Copyright 2018 Jiang Jinyang <https://justjjy.com>
|
|
4
4
|
#
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
# furnished to do so, subject to the following conditions:
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
11
8
|
#
|
|
12
|
-
#
|
|
13
|
-
# all copies or substantial portions of the Software.
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
14
10
|
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
# THE SOFTWARE.
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
22
16
|
|
|
23
17
|
|
|
24
18
|
require 'lru_redux'
|
data/lib/ciri/eth.rb
CHANGED
|
@@ -1,24 +1,18 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# Copyright
|
|
3
|
+
# Copyright 2018 Jiang Jinyang <https://justjjy.com>
|
|
4
4
|
#
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
# furnished to do so, subject to the following conditions:
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
11
8
|
#
|
|
12
|
-
#
|
|
13
|
-
# all copies or substantial portions of the Software.
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
14
10
|
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
# THE SOFTWARE.
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
22
16
|
|
|
23
17
|
|
|
24
18
|
require_relative 'actor'
|
data/lib/ciri/ethash.rb
CHANGED
|
@@ -1,24 +1,18 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# Copyright
|
|
3
|
+
# Copyright 2018 Jiang Jinyang <https://justjjy.com>
|
|
4
4
|
#
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
# furnished to do so, subject to the following conditions:
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
11
8
|
#
|
|
12
|
-
#
|
|
13
|
-
# all copies or substantial portions of the Software.
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
14
10
|
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
# THE SOFTWARE.
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
22
16
|
|
|
23
17
|
|
|
24
18
|
require 'ffi'
|
data/lib/ciri/evm/block_info.rb
CHANGED
|
@@ -1,31 +1,39 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# Copyright
|
|
3
|
+
# Copyright 2018 Jiang Jinyang <https://justjjy.com>
|
|
4
4
|
#
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
# furnished to do so, subject to the following conditions:
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
11
8
|
#
|
|
12
|
-
#
|
|
13
|
-
# all copies or substantial portions of the Software.
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
14
10
|
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
# THE SOFTWARE.
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
22
16
|
|
|
23
17
|
|
|
24
18
|
module Ciri
|
|
25
19
|
class EVM
|
|
26
20
|
|
|
27
21
|
# Block Info
|
|
28
|
-
BlockInfo = Struct.new(:coinbase, :difficulty, :gas_limit, :number, :timestamp,
|
|
22
|
+
BlockInfo = Struct.new(:coinbase, :difficulty, :gas_limit, :number, :timestamp, :block_hash, :parent_hash,
|
|
23
|
+
keyword_init: true) do
|
|
24
|
+
|
|
25
|
+
def self.from_header(header)
|
|
26
|
+
BlockInfo.new(
|
|
27
|
+
coinbase: header.beneficiary,
|
|
28
|
+
difficulty: header.difficulty,
|
|
29
|
+
gas_limit: header.gas_limit,
|
|
30
|
+
number: header.number,
|
|
31
|
+
timestamp: header.timestamp,
|
|
32
|
+
parent_hash: header.parent_hash,
|
|
33
|
+
block_hash: header.get_hash,
|
|
34
|
+
)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
29
37
|
|
|
30
38
|
end
|
|
31
39
|
end
|
data/lib/ciri/evm/errors.rb
CHANGED
|
@@ -1,24 +1,18 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# Copyright
|
|
3
|
+
# Copyright 2018 Jiang Jinyang <https://justjjy.com>
|
|
4
4
|
#
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
# furnished to do so, subject to the following conditions:
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
11
8
|
#
|
|
12
|
-
#
|
|
13
|
-
# all copies or substantial portions of the Software.
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
14
10
|
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
# THE SOFTWARE.
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
22
16
|
|
|
23
17
|
|
|
24
18
|
module Ciri
|
|
@@ -52,5 +46,8 @@ module Ciri
|
|
|
52
46
|
class ReturnError < VMError
|
|
53
47
|
end
|
|
54
48
|
|
|
49
|
+
class ContractCollisionError < VMError
|
|
50
|
+
end
|
|
51
|
+
|
|
55
52
|
end
|
|
56
53
|
end
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Copyright 2018 Jiang Jinyang <https://justjjy.com>
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
require 'ciri/utils/logger'
|
|
19
|
+
require 'ciri/evm/errors'
|
|
20
|
+
|
|
21
|
+
module Ciri
|
|
22
|
+
class EVM
|
|
23
|
+
class ExecutionContext
|
|
24
|
+
|
|
25
|
+
include Utils::Logger
|
|
26
|
+
|
|
27
|
+
attr_accessor :instruction, :depth, :pc, :output, :exception, :gas_limit, :block_info, :sub_state, :fork_schema
|
|
28
|
+
attr_reader :children, :remain_gas, :machine_state
|
|
29
|
+
|
|
30
|
+
def initialize(instruction:, depth: 0, gas_limit:, remain_gas: gas_limit, fork_schema:, pc: 0,
|
|
31
|
+
block_info:, sub_state: SubState::EMPTY.dup, machine_state: MachineState.new)
|
|
32
|
+
raise ArgumentError.new("remain_gas must more than 0") if remain_gas < 0
|
|
33
|
+
raise ArgumentError.new("gas_limit must more than 0") if gas_limit < 0
|
|
34
|
+
|
|
35
|
+
@instruction = instruction
|
|
36
|
+
@depth = depth
|
|
37
|
+
@gas_limit = gas_limit
|
|
38
|
+
@block_info = block_info
|
|
39
|
+
@sub_state = sub_state
|
|
40
|
+
@remain_gas = remain_gas
|
|
41
|
+
@fork_schema = fork_schema
|
|
42
|
+
@pc = pc
|
|
43
|
+
@children = []
|
|
44
|
+
@refund_gas = 0
|
|
45
|
+
@machine_state = machine_state
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# jump to pc
|
|
49
|
+
# only valid if current op code is allowed to modify pc
|
|
50
|
+
def jump_to(pc)
|
|
51
|
+
# allow pc = nil to clear exist @jump_to
|
|
52
|
+
unless pc.nil? || instruction.destinations.include?(pc)
|
|
53
|
+
raise EVM::InvalidJumpError.new("invalid jump in runtime, pc: #{pc}")
|
|
54
|
+
end
|
|
55
|
+
@jump_to = pc
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def jump_pc
|
|
59
|
+
@jump_to
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def set_exception(e)
|
|
63
|
+
@exception ||= e
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def set_output(output)
|
|
67
|
+
@output ||= output
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def set_pc(pc)
|
|
71
|
+
@pc = pc
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def revert
|
|
75
|
+
@sub_state = SubState::EMPTY
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def status
|
|
79
|
+
exception.nil? ? 1 : 0
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def child_context(instruction: self.instruction.dup, depth: self.depth + 1, pc: 0, gas_limit:)
|
|
83
|
+
child = ExecutionContext.new(
|
|
84
|
+
instruction: instruction,
|
|
85
|
+
depth: depth,
|
|
86
|
+
pc: pc,
|
|
87
|
+
gas_limit: gas_limit,
|
|
88
|
+
block_info: block_info,
|
|
89
|
+
sub_state: SubState.new,
|
|
90
|
+
remain_gas: gas_limit,
|
|
91
|
+
fork_schema: fork_schema,
|
|
92
|
+
)
|
|
93
|
+
children << child
|
|
94
|
+
child
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def consume_gas(gas)
|
|
98
|
+
raise GasNotEnoughError.new("can't consume gas to negative, remain_gas: #{remain_gas}, consumed: #{gas}") if gas > remain_gas
|
|
99
|
+
debug "consume #{gas} gas, from #{@remain_gas} -> #{@remain_gas - gas}"
|
|
100
|
+
@remain_gas -= gas
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def return_gas(gas)
|
|
104
|
+
raise ArgumentError.new("can't return negative gas, gas: #{gas}") if gas < 0
|
|
105
|
+
debug "return #{gas} gas, from #{@remain_gas} -> #{@remain_gas + gas}"
|
|
106
|
+
@remain_gas += gas
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def reset_refund_gas
|
|
110
|
+
refund_gas = @refund_gas
|
|
111
|
+
@refund_gas = 0
|
|
112
|
+
refund_gas
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def refund_gas(gas)
|
|
116
|
+
raise ArgumentError.new("gas can't be negative: #{gas}") if gas < 0
|
|
117
|
+
debug "refund #{gas} gas"
|
|
118
|
+
@refund_gas += gas
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# used gas of context
|
|
122
|
+
def used_gas
|
|
123
|
+
@gas_limit - @remain_gas
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def all_log_series
|
|
127
|
+
sub_state.log_series + children.map {|c| c.all_log_series}.flatten
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def all_suicide_accounts
|
|
131
|
+
(sub_state.suicide_accounts + children.map {|c| c.all_suicide_accounts}.flatten).uniq(&:to_s)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
data/lib/ciri/evm/instruction.rb
CHANGED
|
@@ -1,45 +1,38 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# Copyright
|
|
3
|
+
# Copyright 2018 Jiang Jinyang <https://justjjy.com>
|
|
4
4
|
#
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
# furnished to do so, subject to the following conditions:
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
11
8
|
#
|
|
12
|
-
#
|
|
13
|
-
# all copies or substantial portions of the Software.
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
14
10
|
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
# THE SOFTWARE.
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
22
16
|
|
|
23
17
|
|
|
24
18
|
module Ciri
|
|
25
19
|
class EVM
|
|
26
20
|
|
|
27
21
|
# represent instruction
|
|
28
|
-
Instruction = Struct.new(:address, :origin, :price, :data, :sender, :value, :bytes_code,
|
|
29
|
-
keyword_init: true) do
|
|
22
|
+
Instruction = Struct.new(:address, :origin, :price, :data, :sender, :value, :bytes_code,
|
|
23
|
+
:header, keyword_init: true) do
|
|
30
24
|
|
|
31
25
|
def initialize(*args)
|
|
32
26
|
super
|
|
33
27
|
self.data ||= ''.b
|
|
34
28
|
self.value ||= 0
|
|
35
29
|
self.bytes_code ||= ''.b
|
|
36
|
-
self.execute_depth ||= 0
|
|
37
30
|
end
|
|
38
31
|
|
|
39
32
|
def get_op(pos)
|
|
40
33
|
code_size = (bytes_code || ''.b).size
|
|
41
|
-
return OP::STOP if pos
|
|
42
|
-
return OP::INVALID if pos >= code_size
|
|
34
|
+
return OP::STOP if pos >= code_size
|
|
35
|
+
# return OP::INVALID if pos >= code_size
|
|
43
36
|
bytes_code[pos].ord
|
|
44
37
|
end
|
|
45
38
|
|
|
@@ -78,12 +71,12 @@ module Ciri
|
|
|
78
71
|
def destinations_by_index(bytes_code, i)
|
|
79
72
|
destinations = []
|
|
80
73
|
loop do
|
|
81
|
-
if i
|
|
74
|
+
if i >= bytes_code.size
|
|
82
75
|
break
|
|
83
|
-
elsif bytes_code[i] == OP::JUMPDEST
|
|
76
|
+
elsif bytes_code[i].bytes[0] == OP::JUMPDEST
|
|
84
77
|
destinations << i
|
|
85
78
|
end
|
|
86
|
-
i = next_valid_instruction_pos(i, bytes_code[i])
|
|
79
|
+
i = next_valid_instruction_pos(i, bytes_code[i].bytes[0])
|
|
87
80
|
end
|
|
88
81
|
destinations
|
|
89
82
|
end
|
data/lib/ciri/evm/log_entry.rb
CHANGED
|
@@ -1,37 +1,31 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# Copyright
|
|
3
|
+
# Copyright 2018 Jiang Jinyang <https://justjjy.com>
|
|
4
4
|
#
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
# furnished to do so, subject to the following conditions:
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
11
8
|
#
|
|
12
|
-
#
|
|
13
|
-
# all copies or substantial portions of the Software.
|
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
14
10
|
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
# THE SOFTWARE.
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
22
16
|
|
|
23
17
|
|
|
24
18
|
require 'ciri/rlp'
|
|
25
19
|
require 'ciri/utils'
|
|
26
20
|
require 'ciri/types/address'
|
|
27
|
-
require 'ciri/types/
|
|
21
|
+
require 'ciri/types/uint'
|
|
28
22
|
|
|
29
23
|
module Ciri
|
|
30
24
|
class EVM
|
|
31
25
|
|
|
32
26
|
class LogEntry
|
|
33
27
|
include RLP::Serializable
|
|
34
|
-
schema [{address: Types::Address}, {topics: [Types::
|
|
28
|
+
schema [{address: Types::Address}, {topics: [Types::UInt32]}, :data]
|
|
35
29
|
|
|
36
30
|
def to_blooms
|
|
37
31
|
[address.to_s, *topics.map {|t| Utils.big_endian_encode(t, size: 32)}]
|