1 of 17

Rust at Sodot

Encoding security in types

Shachar Langbeheim

2 of 17

Agenda

2

1

Background

2

Strong types

3

Proof types

4

Canonical bytes

3 of 17

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

4 of 17

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

5 of 17

First products

5

MPC SDKs

Threshold signing in your app

Vertex

Self-hosted MPC signer

6 of 17

CryptoVault

6

Client

Orchestrator

Admin A

Key

store

Admin B

Key

store

Admin C

Key

store

One admin compromised → still secure

7 of 17

Let the compiler enforce security

For every engineer, on every PR

8 of 17

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, […]�);

9 of 17

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

10 of 17

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?

11 of 17

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

12 of 17

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

13 of 17

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

14 of 17

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

15 of 17

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

16 of 17

Takeaways

Types ensure:

A value is only used as intended

Every request must be validated

A message has singular encoding and decoding

17 of 17

Questions?

Shachar Langbeheim, Sodot