-
Notifications
You must be signed in to change notification settings - Fork 120
fix(Secretize): Selective output wrapping in WrapGeneric using SecretnessAnalysis #2577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
e574b35 to
7492928
Compare
7492928 to
03b7ba7
Compare
| } | ||
| } | ||
|
|
||
| // Track which operations are secret-dependent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I think instead of cloning only secret ops in, I think this particular pattern should just be wrapping the entire block in a generic, but modifying just the selective output wrapping that you did with newOutputs.
There are other patterns that would also benefit from taking the solver in this file, but maybe we can go pattern by pattern to integrate the secretness analysis (for example, HoistPlaintextOps would benefit, and that would hoist plaintext ops outside of the secret body if they can be hoisted).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the core issue is that if you secret.yield a plaintext SSA value, it becomes secret according to the secretness analysis and won't be automatically converted to a public value. We had this special behavior back in the CGGI pipeline because we wanted to make an empty memref secret as the initializer for a loop that put secret items inside it.
Maybe the relevant pattern could have an option to control its behavior, and we could have this pass specialize... Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
heir/lib/Dialect/Secret/IR/SecretPatterns.cpp
Line 107 in a6a0414
| if (!op.getOps<memref::AllocOp>().empty()) { |
Right - that's why I think this pattern should also take secretness analysis and we should test if that allocated value will be used for secret storing values later. (That being said, I think that would mean secretness analysis would need a backwards analysis as well). But I think that's why I'd prefer this pass stay minimal and tackle that problem in a later PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we agree, but that would make this issue unresolvable until the secretness analysis is improved.
Per maintainer feedback, this change: - Keeps the original 'wrap entire block' approach - Only changes output type selection based on SecretnessAnalysis - Removes the complex op partitioning (cloning only secret ops) - Fixes google#2553 by not creating generic when no outputs depend on secrets The key insight from maintainers is that hoisting plaintext ops should be handled by HoistPlaintextOps pass, not here.
|
Thanks for the feedback @asraa @j2kun! I've simplified the implementation based on your guidance: Changes
Key Logic// Determine output types based on secretness analysis
for (auto [i, resultType] : llvm::enumerate(op.getResultTypes())) {
Value returnVal = returnOp->getOperand(i);
if (isSecret(returnVal, solver)) {
newOutputs.push_back(secret::SecretType::get(resultType));
hasSecretOutputs = true;
} else {
newOutputs.push_back(resultType);
}
}
// Skip generic if no outputs depend on secrets
if (!hasSecretOutputs) {
return success();
} |
Summary
Fixes #2553 - WrapGeneric was forcing all outputs to secret types, causing downstream crashes for functions that return values not depending on secrets.
Changes
Core Change: Operation Partitioning
Instead of wrapping ALL function body operations in
secret.generic, this PR:SecretnessAnalysis- tracks which values depend on secretssecret.genericKey Algorithm
Edge Cases Handled
return %secret_argstill creates a generic (no ops but secret output)return constantdoes NOT create a genericExample
Before (Issue #2553 - causing crash):
After (This PR):
Testing