1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use crate::default_hook::{ArgumentKind, is_or_points_to_secret};
use crate::secret;
use haybale::function_hooks::{IsCall, generic_stub_hook};
use haybale::{Error, Result, ReturnValue, State};
use llvm_ir::Type;
pub fn return_public_unconstrained(
state: &mut State<secret::Backend>,
call: &dyn IsCall,
) -> Result<ReturnValue<secret::BV>> {
generic_stub_hook(state, call)
}
pub fn return_secret(
state: &mut State<secret::Backend>,
call: &dyn IsCall,
) -> Result<ReturnValue<secret::BV>> {
match state.type_of(call).as_ref() {
Type::VoidType => Ok(ReturnValue::ReturnVoid),
ty => {
let width = state.size_in_bits(&ty)
.ok_or_else(|| Error::OtherError("Call return type is an opaque struct type".into()))?;
assert_ne!(width, 0, "Call return type has size 0 bits but isn't void type");
let bv = secret::BV::Secret {
btor: state.solver.clone(),
width,
symbol: Some("return_secret_retval".into()),
};
Ok(ReturnValue::Return(bv))
},
}
}
pub fn propagate_taint(
state: &mut State<secret::Backend>,
call: &dyn IsCall,
) -> Result<ReturnValue<secret::BV>> {
for arg in call.get_arguments().iter().map(|(arg, _)| arg) {
let arg_bv = state.operand_to_bv(arg)?;
match is_or_points_to_secret(state, &arg_bv, &state.type_of(arg))? {
ArgumentKind::Public | ArgumentKind::Unknown => {},
ArgumentKind::Secret => return return_secret(state, call),
}
}
return_public_unconstrained(state, call)
}