Skip to content

Commit ae06ba3

Browse files
authored
fix: correct computed file callback data and result digest calculations (#11)
1 parent e0186d8 commit ae06ba3

File tree

3 files changed

+15
-19
lines changed

3 files changed

+15
-19
lines changed

post-compute/src/compute/computed_file.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ pub fn read_computed_file(
161161
///
162162
/// let mut computed_file = ComputedFile {
163163
/// task_id: Some("0x123".to_string()),
164-
/// callback_data: Some("0xabc...".to_string()),
164+
/// callback_data: Some("0x0000000000000000000000000000000000000000000000000000000000000001".to_string()),
165165
/// deterministic_output_path: None,
166166
/// result_digest: None,
167167
/// enclave_signature: None,
@@ -170,7 +170,13 @@ pub fn read_computed_file(
170170
///
171171
/// // For a web3 callback task
172172
/// match build_result_digest_in_computed_file(&mut computed_file, true) {
173-
/// Ok(()) => println!("Result digest: {:?}", computed_file.result_digest),
173+
/// Ok(()) => {
174+
/// assert_eq!(
175+
/// computed_file.result_digest,
176+
/// Some("0xb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6".to_string())
177+
/// );
178+
/// println!("Result digest: {:?}", computed_file.result_digest);
179+
/// },
174180
/// Err(e) => eprintln!("Error computing digest: {:?}", e),
175181
/// }
176182
/// ```
@@ -442,7 +448,7 @@ mod tests {
442448
assert!(result.is_ok());
443449
assert_eq!(
444450
computed_file.result_digest,
445-
Some("0xcb371be217faa47dab94e0d0ff0840c6cbf41645f0dc1a6ae3f34447155a76f3".to_string())
451+
Some("0xb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6".to_string())
446452
);
447453
}
448454

post-compute/src/compute/utils/hash_utils.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ pub fn sha256<D: Sha256Digest>(input: D) -> String {
4444
format!("0x{}", digest(input))
4545
}
4646

47-
pub fn keccak256(input: &str) -> String {
48-
format!("0x{:x}", Keccak256::digest(input))
49-
}
50-
5147
#[cfg(test)]
5248
mod tests {
5349
use super::*;
@@ -105,12 +101,4 @@ mod tests {
105101
sha256(String::from("utf8String"))
106102
)
107103
}
108-
109-
#[test]
110-
fn get_keccak256_digest() {
111-
assert_eq!(
112-
"0x234b7550275b36696569d306216e035df78db522674abecff884c64e7558ef17",
113-
keccak256("utf8String")
114-
);
115-
}
116104
}

post-compute/src/compute/utils/result_utils.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
use crate::compute::utils::hash_utils::{concatenate_and_hash, sha256};
2-
use crate::compute::{computed_file::ComputedFile, utils::hash_utils::keccak256};
1+
use crate::compute::{
2+
computed_file::ComputedFile,
3+
utils::hash_utils::{concatenate_and_hash, sha256},
4+
};
35
use log::error;
46
use std::{
57
fs::{self, DirEntry},
@@ -62,7 +64,7 @@ pub fn compute_web3_result_digest(computed_file: &ComputedFile) -> String {
6264
}
6365
};
6466

65-
keccak256(callback_data)
67+
concatenate_and_hash(&[callback_data])
6668
}
6769

6870
/// Computes the result digest for web2 tasks using SHA256 hashing of output files.
@@ -299,7 +301,7 @@ mod tests {
299301

300302
assert_eq!(
301303
result,
302-
"0xcb371be217faa47dab94e0d0ff0840c6cbf41645f0dc1a6ae3f34447155a76f3"
304+
"0xb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6"
303305
);
304306
}
305307

0 commit comments

Comments
 (0)