Skip to content

Commit 69a2a6e

Browse files
committed
harden special_meeting
1 parent af9d3af commit 69a2a6e

2 files changed

Lines changed: 19 additions & 10 deletions

File tree

ex/lib/consensus/special_meeting/special_meeting_gen.ex

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,23 @@ defmodule SpecialMeetingGen do
112112

113113
def handle_info({:add_slash_trainer_entry_reply, entry_hash, pk, signature}, state = %{slash_trainer: _}) do
114114
st = state.slash_trainer
115-
true = st.entry.hash == entry_hash
116-
if pk in st.validators do
117-
aggsig = BLS12AggSig.add_padded(st.entry.aggsig, st.validators, pk, signature)
118-
state = put_in(state, [:slash_trainer, :entry, :aggsig], aggsig)
119-
IO.inspect {:entry, st.aggsig.mask_set_size / st.aggsig.mask_size}
120-
{:noreply, state}
121-
else
122-
{:noreply, state}
115+
cond do
116+
!st[:entry] or !st.entry[:entry] -> {:noreply, state}
117+
st.entry.entry.hash != entry_hash -> {:noreply, state}
118+
pk not in st.validators -> {:noreply, state}
119+
true ->
120+
aggsig = BLS12AggSig.add_padded(st.entry.aggsig, st.validators, pk, signature)
121+
state = put_in(state, [:slash_trainer, :entry, :aggsig], aggsig)
122+
IO.inspect {:entry, aggsig.mask_set_size / aggsig.mask_size}
123+
{:noreply, state}
123124
end
124125
end
125126

127+
def handle_info(msg, state) do
128+
IO.inspect {:unknown_special_meeting_msg, msg}
129+
{:noreply, state}
130+
end
131+
126132
def tick(state) do
127133
#IO.inspect state[:slash_trainer]
128134
st = state[:slash_trainer]

ex/lib/node/node_state.ex

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,22 +188,25 @@ defmodule NodeState do
188188
def handle(:special_business_reply, istate, term) do
189189
#IO.inspect {:special_business_reply, term.business}
190190
op = term.business.op
191+
validators = DB.Chain.validators_for_height(DB.Chain.height() + 1) || []
191192
cond do
192193
#istate.peer.pk != <<>> -> nil
193194
op == "slash_trainer_tx_reply" ->
194195
b = term.business
195196
msg = <<"slash_trainer", b.epoch::32-little, b.malicious_pk::binary>>
196-
sigValid = BlsEx.verify?(b.pk, b.signature, msg, BLS12AggSig.dst_motion())
197+
sigValid = b.pk in validators and BlsEx.verify?(b.pk, b.signature, msg, BLS12AggSig.dst_motion())
197198
if sigValid do
198199
send(SpecialMeetingGen, {:add_slash_trainer_tx_reply, term.business.pk, term.business.signature})
199200
end
200201

201202
op == "slash_trainer_entry_reply" ->
202203
b = term.business
203-
sigValid = BlsEx.verify?(b.pk, b.signature, b.entry_hash, BLS12AggSig.dst_entry())
204+
sigValid = b.pk in validators and BlsEx.verify?(b.pk, b.signature, b.entry_hash, BLS12AggSig.dst_entry())
204205
if sigValid do
205206
send(SpecialMeetingGen, {:add_slash_trainer_entry_reply, b.entry_hash, b.pk, b.signature})
206207
end
208+
209+
true -> nil
207210
end
208211
end
209212

0 commit comments

Comments
 (0)