Rust at Sodot
Encoding security in types
Shachar Langbeheim
Agenda
2
1
Background
2
Strong types
3
Proof types
4
Canonical bytes
Public-key cryptography
3
Encrypt
Public key locks
Private key unlocks
Sign
Private key signs
Public key verifies
Private key ownership is proof of identity
MPC: the key never exists
4
Share 1
Share 2
Share 3
Standard
signature
No single point of compromise
Signature is same as non-MPC
Shares refresh, parties rotate
First products
5
MPC SDKs
Threshold signing in your app
Vertex
Self-hosted MPC signer
CryptoVault
6
Client
Orchestrator
Admin A
Key
store
Admin B
Key
store
Admin C
Key
store
One admin compromised → still secure
Let the compiler enforce security
For every engineer, on every PR
Newtypes: IDs can't be mixed up
8
pub struct KeyId(Uuid);
pub struct VaultId(Uuid);
fn delete_key(id: KeyId) { … }
delete_key(vault_id);
// error: expected `KeyId`, found `VaultId
// easy to define, using the power of macros
create_uuid_type!(� KeyId, VaultId, […]�);
Parse, don't validate
9
threshold: NonZeroU8 // 0-of-N quorum: unrepresentable
let s: NonEmptySlice<u8> = [].into();
// error: slice must not be empty ← at compile time
// also enforced by serde at runtime
//before:
fn foo(items: &[Item])
// has to verify items isn’t empty everywhere
//after:
fn foo(items: NonEmptySlice<Item>)
// no verification needed
Invalid states can't be built
Our problem
10
ORC
Admin A
Key
store
Admin B
Key
store
Admin C
Key
store
How can we be sure that all stores agree?
ApprovedRequest: safe on the wire
11
Tampered body
Forged signer
Duplicate signer
pub struct ApprovedRequest {
approvals: Vec<SignedApproval>, // key store signatures
body: Vec<u8>, // canonical signed bytes
}
Each one fails verification
Proof types: no verify, no request
12
ApprovedRequest
(untrusted wire)
verify()
VerifiedRequest
(private constructor)
fn verify(request: ApprovedRequest,
keys: &[Key])
-> Result<VerifiedRequest, Error>
Skipping verify() doesn't compile
sised, our own serialization crate
13
HashSet + serde
sised
Server A
{b, a, c}
Server A
{a, b, c}
Server B
{c, a, b}
Server B
{a, b, c}
≠
=
One value → exactly one encoding
Frozen wire formats
14
enum SignedContentInner { // private
#[sised(tag = 0)]
V1 { enriched_request: EnrichedRequest },
// V2: new tag, append only
}
pub struct SignedContent(SignedContentInner);
Tags frozen, bytes pinned in tests
Testing the wire format
15
#[test]
fn wire_format_is_pinned() {
let encoded = encode(CloudIdentity {
sub: Some(“foo”),
provider: CloudProvider::Azure
});
assert_eq!(encoded, "0f626f62406578616d706c652e636f6d01057375622d3101”);
// new field or variant = compile error until it has a vector
fn exhaustiveness_guard(id: CloudIdentity) {
match id {
CloudIdentity {
sub: None | Some(String { .. }),
Provider: CloudProvider::Azure | CloudProvider::Google,
} => (), // never `_` or `..`
}
}
}
Bytes pinned, variants counted
Takeaways
Types ensure:
A value is only used as intended
Every request must be validated
A message has singular encoding and decoding
Questions?
Shachar Langbeheim, Sodot