Verify complete Dark Tariff proof commitments
This commit is contained in:
1 parent
20cf14d953
commit
0b98b70bf9
3 files changed
+22
-7
No files matched your search
@@ -61,6 +61,7 @@ begin
|
||||
|| v_y::text || '|' || v_w::text, 'UTF8'), 'base64'), E'\n', '');
|
||||
return jsonb_build_object('n', v_n, 'h', to_jsonb(v_h), 'y', v_y::text, 'w', v_w,
|
||||
'parameters', v_params,
|
||||
'witness', v_s::text,
|
||||
'verification_id', replace(encode(chat.pack(v_s), 'base64'), E'\n', ''));
|
||||
end;
|
||||
$$;
|
||||
@@ -106,10 +107,14 @@ begin
|
||||
else repeat('0', bit_length(p_reading.y))::bit varying end)::text);
|
||||
if p_challenge = 0 then
|
||||
v_b := chat.hash('b|' || chat.permute(v_v, v_p)::text);
|
||||
return v_a = p_values[1] and v_b = p_values[2];
|
||||
return v_a = p_values[1] and v_b = p_values[2]
|
||||
and (p_reading.verification_witness is null
|
||||
or chat.hash('c|' || chat.permute(v_v # p_reading.verification_witness, v_p)::text) = p_values[3]);
|
||||
end if;
|
||||
v_c := chat.hash('c|' || chat.permute(v_v, v_p)::text);
|
||||
return v_a = p_values[1] and v_c = p_values[3];
|
||||
return v_a = p_values[1] and v_c = p_values[3]
|
||||
and (p_reading.verification_witness is null
|
||||
or chat.hash('b|' || chat.permute(v_v # p_reading.verification_witness, v_p)::text) = p_values[2]);
|
||||
elsif p_challenge = 2 then
|
||||
v_text := p_data ->> 't';
|
||||
if v_text is null or length(v_text) <> p_reading.n or v_text !~ '^[01]+$' then
|
||||
@@ -156,7 +161,14 @@ begin
|
||||
or exists (select 1 from unnest(p_values) x where x is null or x !~ '^[0-9a-f]{64}$') then
|
||||
raise exception 'Invalid data format.' using errcode = 'P0400';
|
||||
end if;
|
||||
v_challenge := chat.challenge();
|
||||
-- Both of these challenges let the server check all three commitments.
|
||||
if p_round = 1 and exists (
|
||||
select 1 from billing.reading where id = v_session.reading_id and verification_witness is not null
|
||||
) then
|
||||
v_challenge := get_byte(gen_random_bytes(1), 0) % 2;
|
||||
else
|
||||
v_challenge := chat.challenge();
|
||||
end if;
|
||||
update chat.check_session set data = p_values, challenge = v_challenge where id = p_id;
|
||||
return jsonb_build_object('round', p_round, 'stage', 'answer', 'challenge', v_challenge,
|
||||
'message', format('Step %s of 10. Challenge: %s. Submit an answer.', p_round, v_challenge));
|
||||
|
||||
Reference in new issue
Block a user