Skip to content
This repository has been archived by the owner on Nov 17, 2022. It is now read-only.

Commit

Permalink
fix account_db#fetch, WIP #18
Browse files Browse the repository at this point in the history
  • Loading branch information
jjyr committed Jul 7, 2018
1 parent 1b254c6 commit 1fc740b
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/ciri/db/account_db.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def fetch(address, key)
converted_key = convert_key Utils.big_endian_encode(key, size: 32)
account = find_account address
trie = Trie.new(db: @db, root_hash: account.storage_root)
trie[converted_key] || ''.b
value = trie[converted_key]
value.empty? ? 0 : RLP.decode(value, Integer)
end

def set_nonce(address, nonce)
Expand Down
2 changes: 1 addition & 1 deletion lib/ciri/evm/forks/frontier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def cost_of_sstore(vm)
key = ms.get_stack(0, Integer)
value = ms.get_stack(1, Integer)

stored_is_empty = vm.fetch(instruction.address, key).empty?
stored_is_empty = vm.fetch(instruction.address, key).zero?
value_is_non_zero = value && !value.zero?

if value_is_non_zero && stored_is_empty
Expand Down
4 changes: 2 additions & 2 deletions spec/ciri/db/account_db_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
address, account = account1

account_db = Ciri::DB::AccountDB.new({})
account_db.store(address, "hello", "nihao")
expect(account_db.fetch(address, "hello")).to eq "nihao".rjust(32, "\x00")
account_db.store(address, 42, 1530984410)
expect(account_db.fetch(address, 42)).to eq 1530984410
end

end
2 changes: 1 addition & 1 deletion spec/ciri/fixtures_tests/evm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
balance = Ciri::Utils.big_endian_decode Ciri::Utils.to_bytes(v["balance"])
nonce = Ciri::Utils.big_endian_decode Ciri::Utils.to_bytes(v["nonce"])
storage = v["storage"].map do |k, v|
[Ciri::Utils.to_bytes(k), Ciri::Utils.to_bytes(v).rjust(32, "\x00".b)]
[Ciri::Utils.hex_to_number(k), Ciri::Utils.hex_to_number(v)]
end.to_h
[Ciri::Types::Account.new(balance: balance, nonce: nonce), storage]
end
Expand Down
2 changes: 1 addition & 1 deletion spec/ciri/fixtures_tests/evm_state_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
nonce = Ciri::Utils.hex_to_number(v["nonce"])
code = Ciri::Utils.to_bytes(v["code"])
storage = v["storage"].map do |k, v|
[Ciri::Utils.to_bytes(k), Ciri::Utils.to_bytes(v).rjust(32, "\x00".b)]
[Ciri::Utils.hex_to_number(k), Ciri::Utils.hex_to_number(v)]
end.to_h
[Ciri::Types::Account.new(balance: balance, nonce: nonce), code, storage]
end
Expand Down

0 comments on commit 1fc740b

Please sign in to comment.