Skip to content

Commit fd1a18a

Browse files
committed
fix interactive prf
1 parent 75b50c3 commit fd1a18a

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

crates/components/hmac-sha256/src/prf/function/interactive.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub(crate) struct PrfFunction {
1515
start_seed_label: Option<Vec<u8>>,
1616
a: Vec<PHash>,
1717
p: Vec<PHash>,
18+
assigned: bool,
1819
}
1920

2021
impl PrfFunction {
@@ -55,19 +56,24 @@ impl PrfFunction {
5556
}
5657

5758
pub(crate) fn make_progress(&mut self, vm: &mut dyn Vm<Binary>) -> Result<bool, PrfError> {
58-
let a = self.a.first_mut().expect("prf should be allocated");
59-
let msg = a.msg;
59+
let assigned = self.assigned;
6060

61-
let msg_value = self
62-
.start_seed_label
63-
.clone()
64-
.expect("seed should be assigned by now");
61+
if !assigned {
62+
let a = self.a.first_mut().expect("prf should be allocated");
63+
let msg = a.msg;
6564

66-
vm.mark_public(msg).map_err(PrfError::vm)?;
67-
vm.assign(msg, msg_value).map_err(PrfError::vm)?;
68-
vm.commit(msg).map_err(PrfError::vm)?;
65+
let msg_value = self
66+
.start_seed_label
67+
.clone()
68+
.expect("seed should be assigned by now");
6969

70-
Ok(true)
70+
vm.mark_public(msg).map_err(PrfError::vm)?;
71+
vm.assign(msg, msg_value).map_err(PrfError::vm)?;
72+
vm.commit(msg).map_err(PrfError::vm)?;
73+
}
74+
75+
self.assigned = true;
76+
Ok(assigned)
7177
}
7278

7379
pub(crate) fn set_start_seed(&mut self, seed: Vec<u8>) {
@@ -93,6 +99,7 @@ impl PrfFunction {
9399
start_seed_label: None,
94100
a: vec![],
95101
p: vec![],
102+
assigned: false,
96103
};
97104

98105
assert!(

0 commit comments

Comments
 (0)