Skip to content

Commit c95ba63

Browse files
committed
fix verify vr segment
1 parent b690b34 commit c95ba63

3 files changed

Lines changed: 6 additions & 4 deletions

File tree

ex/lib/bic/base.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ defmodule BIC.Base do
2828
end)
2929

3030
#parallel verify sols
31+
segment_vr_hash = kv_get("bic:epoch:segment_vr_hash")
3132
steam = Task.async_stream(txus, fn txu ->
3233
sol = Enum.find_value(txu.tx.actions, fn(a)-> a.function == "submit_sol" and length(a.args) != [] and hd(a.args) end)
3334
if sol do
3435
hash = Blake3.hash(sol)
35-
valid = try do BIC.Sol.verify(sol, %{hash: hash, vr_b3: env.entry_vr_b3}) catch _,_ -> false end
36+
valid = try do BIC.Sol.verify(sol, %{hash: hash, vr_b3: env.entry_vr_b3, segment_vr_hash: segment_vr_hash}) catch _,_ -> false end
3637
%{hash: hash, valid: valid}
3738
end
3839
end)

ex/lib/bic/sol.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ defmodule BIC.Sol do
4242
cond do
4343
epoch >= 282 ->
4444
usol = unpack(sol)
45-
if kv_get("bic:epoch:segment_vr_hash") != usol.segment_vr_hash, do: throw %{error: :segment_vr_hash}
45+
if opts.segment_vr_hash != usol.segment_vr_hash, do: throw %{error: :segment_vr_hash}
4646
if byte_size(sol) != @sol_size, do: throw(%{error: :invalid_sol_seed_size})
4747
hash = Map.get_lazy(opts, :hash, fn()-> Blake3.hash(sol) end)
4848
vr_b3 = Map.get_lazy(opts, :vr_b3, fn()-> :crypto.strong_rand_bytes(32) end)

ex/lib/node/node_state.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ defmodule NodeState do
6262
send(NodeGen, {:handle_sync, :ping_ns, istate, term})
6363
catch
6464
e,{:badmatch, %{error: :wrong_epoch}} -> nil
65-
e,r -> IO.inspect {:error_ping, e, r, term, istate.peer.ip}
65+
e,r -> nil
66+
#IO.inspect {:error_ping, e, r, term, istate.peer.ip, __STACKTRACE__}
6667
end
6768
end
6869
def handle(:ping_ns, istate, term) do
@@ -134,7 +135,7 @@ defmodule NodeState do
134135
sol.epoch != Consensus.chain_epoch() ->
135136
#IO.inspect {:broadcasted_sol_invalid_epoch, sol.epoch, Consensus.chain_epoch()}
136137
nil
137-
!BIC.Sol.verify(term.sol, %{vr_b3: :crypto.strong_rand_bytes(32)}) ->
138+
!BIC.Sol.verify(term.sol, %{vr_b3: :crypto.strong_rand_bytes(32), segment_vr_hash: API.Contract.get("bic:epoch:segment_vr_hash")}) ->
138139
IO.inspect {:peer_sent_invalid_sol, :TODO_block_malicious_peer}
139140
nil
140141
!BlsEx.verify?(sol.pk, sol.pop, sol.pk, BLS12AggSig.dst_pop()) ->

0 commit comments

Comments
 (0)