ciri 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,195 @@
|
|
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/evm/op'
|
19
|
+
|
20
|
+
module Ciri
|
21
|
+
module Forks
|
22
|
+
module Homestead
|
23
|
+
|
24
|
+
module Cost
|
25
|
+
|
26
|
+
include Ciri::EVM::OP
|
27
|
+
|
28
|
+
# fee schedule, start with G
|
29
|
+
G_ZERO = 0
|
30
|
+
G_BASE = 2
|
31
|
+
G_VERYLOW = 3
|
32
|
+
G_LOW = 5
|
33
|
+
G_MID = 8
|
34
|
+
G_HIGH = 10
|
35
|
+
G_EXTCODE = 700
|
36
|
+
G_BALANCE = 400
|
37
|
+
G_SLOAD = 50
|
38
|
+
G_JUMPDEST = 1
|
39
|
+
G_SSET = 20000
|
40
|
+
G_RESET = 5000
|
41
|
+
R_SCLEAR = 15000
|
42
|
+
R_SELFDESTRUCT = 24000
|
43
|
+
G_SELFDESTRUCT = 0
|
44
|
+
G_CREATE = 32000
|
45
|
+
G_CODEDEPOSIT = 200
|
46
|
+
G_CALL = 700
|
47
|
+
G_CALLVALUE = 9000
|
48
|
+
G_CALLSTIPEND = 2300
|
49
|
+
G_NEWACCOUNT = 25000
|
50
|
+
G_EXP = 10
|
51
|
+
G_EXPBYTE = 10
|
52
|
+
G_MEMORY = 3
|
53
|
+
G_TXCREATE = 32000
|
54
|
+
G_TXDATAZERO = 4
|
55
|
+
G_TXDATANONZERO = 68
|
56
|
+
G_TRANSACTION = 21000
|
57
|
+
G_LOG = 375
|
58
|
+
G_LOGDATA = 8
|
59
|
+
G_TOPIC = 375
|
60
|
+
G_SHA3 = 30
|
61
|
+
G_SHA3WORD = 6
|
62
|
+
G_COPY = 3
|
63
|
+
G_BLOCKHASH = 20
|
64
|
+
G_QUADDIVISOR = 100
|
65
|
+
|
66
|
+
# operation code by group, for later calculation
|
67
|
+
W_ZERO = [STOP, RETURN, REVERT]
|
68
|
+
W_BASE = [ADDRESS, ORIGIN, CALLER, CALLVALUE, CALLDATASIZE, CODESIZE, GASPRICE,
|
69
|
+
COINBASE, TIMESTAMP, NUMBER, DIFFICULTY, GASLIMIT, RETURNDATASIZE,
|
70
|
+
POP, PC, MSIZE, GAS]
|
71
|
+
W_VERYLOW = [ADD, SUB, NOT, LT, GT, SLT, SGT, EQ, ISZERO, AND, OR,
|
72
|
+
XOR, BYTE, CALLDATALOAD, MLOAD, MSTORE, MSTORE8,
|
73
|
+
*(1..32).map {|i| EVM::OP.get(PUSH1 + i - 1).code}, # push1 - push32
|
74
|
+
*(1..16).map {|i| EVM::OP.get(DUP1 + i - 1).code}, # dup1 - dup16
|
75
|
+
*(1..16).map {|i| EVM::OP.get(SWAP1 + i - 1).code}] # swap1 - swap16
|
76
|
+
W_LOW = [MUL, DIV, SDIV, MOD, SMOD, SIGNEXTEND]
|
77
|
+
W_MID = [ADDMOD, MULMOD, JUMP]
|
78
|
+
W_HIGH = [JUMPI]
|
79
|
+
W_EXTCODE = [EXTCODESIZE]
|
80
|
+
|
81
|
+
|
82
|
+
class << self
|
83
|
+
include Ciri::EVM::OP
|
84
|
+
|
85
|
+
# C(σ,μ,I)
|
86
|
+
# calculate cost of current operation
|
87
|
+
def cost_of_operation(vm)
|
88
|
+
ms = vm.machine_state
|
89
|
+
instruction = vm.instruction
|
90
|
+
w = instruction.get_op(vm.pc)
|
91
|
+
if w == SSTORE
|
92
|
+
cost_of_sstore(vm)
|
93
|
+
elsif w == EXP && ms.get_stack(1, Integer) == 0
|
94
|
+
G_EXP
|
95
|
+
elsif w == EXP && (x = ms.get_stack(1, Integer)) > 0
|
96
|
+
G_EXP + G_EXPBYTE * Utils.ceil_div(x.bit_length, 8)
|
97
|
+
elsif w == CALLDATACOPY || w == CODECOPY || w == RETURNDATACOPY
|
98
|
+
G_VERYLOW + G_COPY * Utils.ceil_div(ms.get_stack(2, Integer), 32)
|
99
|
+
elsif w == EXTCODECOPY
|
100
|
+
G_EXTCODE + G_COPY * Utils.ceil_div(ms.get_stack(3, Integer), 32)
|
101
|
+
elsif (LOG0..LOG4).include? w
|
102
|
+
G_LOG + G_LOGDATA * ms.get_stack(1, Integer) + (w - LOG0) * G_TOPIC
|
103
|
+
elsif w == CALL || w == CALLCODE || w == DELEGATECALL
|
104
|
+
G_CALL
|
105
|
+
elsif w == SELFDESTRUCT
|
106
|
+
cost_of_self_destruct(vm)
|
107
|
+
elsif w == CREATE
|
108
|
+
G_CREATE
|
109
|
+
elsif w == SHA3
|
110
|
+
G_SHA3 + G_SHA3WORD * Utils.ceil_div(ms.get_stack(1, Integer), 32)
|
111
|
+
elsif w == JUMPDEST
|
112
|
+
G_JUMPDEST
|
113
|
+
elsif w == SLOAD
|
114
|
+
G_SLOAD
|
115
|
+
elsif W_ZERO.include? w
|
116
|
+
G_ZERO
|
117
|
+
elsif W_BASE.include? w
|
118
|
+
G_BASE
|
119
|
+
elsif W_VERYLOW.include? w
|
120
|
+
G_VERYLOW
|
121
|
+
elsif W_LOW.include? w
|
122
|
+
G_LOW
|
123
|
+
elsif W_MID.include? w
|
124
|
+
G_MID
|
125
|
+
elsif W_HIGH.include? w
|
126
|
+
G_HIGH
|
127
|
+
elsif W_EXTCODE.include? w
|
128
|
+
G_EXTCODE
|
129
|
+
elsif w == BALANCE
|
130
|
+
G_BALANCE
|
131
|
+
elsif w == BLOCKHASH
|
132
|
+
G_BLOCKHASH
|
133
|
+
else
|
134
|
+
raise "can't compute cost for unknown op #{w}"
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def cost_of_memory(i)
|
139
|
+
G_MEMORY * i + (i ** 2) / 512
|
140
|
+
end
|
141
|
+
|
142
|
+
def intrinsic_gas_of_transaction(t)
|
143
|
+
gas = (t.data.each_byte || '').reduce(0) {|sum, i| sum + (i.zero? ? G_TXDATAZERO : G_TXDATANONZERO)}
|
144
|
+
# gas + (t.to.empty? ? G_TXCREATE : 0) + G_TRANSACTION
|
145
|
+
gas + G_TRANSACTION
|
146
|
+
end
|
147
|
+
|
148
|
+
def gas_of_call(vm:, gas:, to:, value:)
|
149
|
+
# TODO handle gas calculation for all categories calls
|
150
|
+
account_exists = vm.account_exist?(to)
|
151
|
+
transfer_gas_fee = value > 0 ? G_CALLVALUE : 0
|
152
|
+
create_gas_fee = !account_exists ? G_NEWACCOUNT : 0
|
153
|
+
extra_gas = transfer_gas_fee + create_gas_fee
|
154
|
+
|
155
|
+
total_fee = gas + extra_gas
|
156
|
+
child_gas_limit = gas + (value > 0 ? G_CALLSTIPEND : 0)
|
157
|
+
[child_gas_limit, total_fee]
|
158
|
+
end
|
159
|
+
|
160
|
+
private
|
161
|
+
|
162
|
+
def cost_of_self_destruct(vm)
|
163
|
+
G_SELFDESTRUCT
|
164
|
+
end
|
165
|
+
|
166
|
+
def cost_of_sstore(vm)
|
167
|
+
ms = vm.machine_state
|
168
|
+
instruction = vm.instruction
|
169
|
+
|
170
|
+
key = ms.get_stack(0, Integer)
|
171
|
+
value = ms.get_stack(1, Integer)
|
172
|
+
|
173
|
+
current_is_empty = vm.fetch(instruction.address, key).zero?
|
174
|
+
value_is_empty = value.nil? || value.zero?
|
175
|
+
|
176
|
+
gas_cost = if current_is_empty && !value_is_empty
|
177
|
+
G_SSET
|
178
|
+
else
|
179
|
+
G_RESET
|
180
|
+
end
|
181
|
+
gas_refund = if !current_is_empty && value_is_empty
|
182
|
+
R_SCLEAR
|
183
|
+
else
|
184
|
+
0
|
185
|
+
end
|
186
|
+
|
187
|
+
[gas_cost, gas_refund]
|
188
|
+
end
|
189
|
+
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
@@ -0,0 +1,46 @@
|
|
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_relative 'base'
|
19
|
+
require_relative 'frontier'
|
20
|
+
|
21
|
+
module Ciri
|
22
|
+
module Forks
|
23
|
+
module Homestead
|
24
|
+
class Schema < Forks::Frontier::Schema
|
25
|
+
|
26
|
+
include Forks::Frontier::Cost
|
27
|
+
|
28
|
+
def initialize(support_dao_fork:)
|
29
|
+
@support_dao_fork = support_dao_fork
|
30
|
+
end
|
31
|
+
|
32
|
+
def intrinsic_gas_of_transaction(t)
|
33
|
+
gas = (t.data.each_byte || '').reduce(0) {|sum, i| sum + (i.zero? ? G_TXDATAZERO : G_TXDATANONZERO)}
|
34
|
+
gas + (t.to.empty? ? G_TXCREATE : 0) + G_TRANSACTION
|
35
|
+
end
|
36
|
+
|
37
|
+
# chain difficulty method
|
38
|
+
# https://github.com/ethereum/EIPs/blob/984cf5de90bbf5fbe7e49be227b0c2f9567e661e/EIPS/eip-2.md
|
39
|
+
def difficulty_time_factor(header, parent_header)
|
40
|
+
[1 - (header.timestamp - parent_header.timestamp) / 10, -99].max
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/ciri/forks.rb
CHANGED
@@ -1,35 +1,25 @@
|
|
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
|
|
18
|
+
require_relative 'forks/config'
|
24
19
|
require_relative 'forks/frontier'
|
20
|
+
require_relative 'forks/homestead'
|
25
21
|
|
26
22
|
module Ciri
|
27
23
|
module Forks
|
28
|
-
|
29
|
-
def self.detect_fork(header: nil, number: nil)
|
30
|
-
number ||= header.number
|
31
|
-
Frontier::Config.new
|
32
|
-
end
|
33
|
-
|
34
24
|
end
|
35
25
|
end
|
data/lib/ciri/key.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2018, by Jiang Jinyang. <https://justjjy.com
|
3
|
+
# Copyright (c) 2018, by Jiang Jinyang. <https://justjjy.com>, classicalliu.
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -22,7 +22,9 @@
|
|
22
22
|
|
23
23
|
|
24
24
|
require 'openssl'
|
25
|
-
|
25
|
+
require 'ciri/utils'
|
26
|
+
require 'ciri/crypto'
|
27
|
+
require 'ciri/types/address'
|
26
28
|
|
27
29
|
module Ciri
|
28
30
|
|
@@ -73,8 +75,17 @@ module Ciri
|
|
73
75
|
Crypto.ecies_decrypt(data, ec_key, shared_mac_data)
|
74
76
|
end
|
75
77
|
|
78
|
+
def to_address
|
79
|
+
Types::Address.new(Utils.keccak(public_key)[-20..-1])
|
80
|
+
end
|
81
|
+
|
76
82
|
private
|
77
83
|
|
84
|
+
# public key
|
85
|
+
def public_key
|
86
|
+
raw_public_key[1..-1]
|
87
|
+
end
|
88
|
+
|
78
89
|
def secp256k1_key
|
79
90
|
privkey = ec_key.private_key.to_s(2)
|
80
91
|
# some times below error will occurs, raise error with more detail
|
@@ -84,4 +95,4 @@ module Ciri
|
|
84
95
|
@secp256k1_key ||= Crypto.ensure_secp256k1_key(privkey: privkey)
|
85
96
|
end
|
86
97
|
end
|
87
|
-
end
|
98
|
+
end
|
data/lib/ciri/pow.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 'ciri/utils'
|
@@ -49,7 +43,7 @@ module Ciri
|
|
49
43
|
def get_cache(block_number)
|
50
44
|
epoch = block_number / Ethash::EPOCH_LENGTH
|
51
45
|
while @cache_seeds.size <= epoch
|
52
|
-
@cache_seeds.append(Utils.
|
46
|
+
@cache_seeds.append(Utils.keccak(@cache_seeds[-1]))
|
53
47
|
end
|
54
48
|
|
55
49
|
seed = @cache_seeds[epoch]
|
data/lib/ciri/rlp/decode.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 'stringio'
|
data/lib/ciri/rlp/encode.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
|
@@ -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/utils'
|
data/lib/ciri/serialize.rb
CHANGED
@@ -1,27 +1,24 @@
|
|
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/types/address'
|
19
|
+
require 'ciri/core_ext'
|
20
|
+
|
21
|
+
using Ciri::CoreExt
|
25
22
|
|
26
23
|
module Ciri
|
27
24
|
module Serialize
|
@@ -45,7 +42,7 @@ module Ciri
|
|
45
42
|
elsif type == Types::Address && !item.is_a?(Types::Address)
|
46
43
|
# check if address represent in Integer
|
47
44
|
item = Utils.big_endian_encode(item) if item.is_a?(Integer)
|
48
|
-
Types::Address.new(item.size >= 20 ? item[-20..-1] :
|
45
|
+
Types::Address.new(item.size >= 20 ? item[-20..-1] : item.pad_zero(20))
|
49
46
|
elsif type.nil?
|
50
47
|
# get serialized word
|
51
48
|
serialize(item).rjust(32, "\x00".b)
|
data/lib/ciri/trie/nibbles.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
|
data/lib/ciri/trie/nodes.rb
CHANGED
@@ -1,28 +1,23 @@
|
|
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 'nibbles'
|
25
19
|
require 'forwardable'
|
20
|
+
require 'ciri/utils'
|
26
21
|
|
27
22
|
module Ciri
|
28
23
|
class Trie
|
@@ -180,7 +175,7 @@ module Ciri
|
|
180
175
|
end
|
181
176
|
end
|
182
177
|
|
183
|
-
BLANK_NODE_HASH = Utils.
|
178
|
+
BLANK_NODE_HASH = Utils.keccak(RLP.encode(''.b)).freeze
|
184
179
|
|
185
180
|
end
|
186
181
|
end
|