Skip to content

Commit 2fac140

Browse files
committed
almost fix verification
1 parent ee868b0 commit 2fac140

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

DynamoDbEncryption/dafny/DynamoDbEncryption/src/ConfigToInfo.dfy

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ module SearchConfigToInfo {
3838
method Convert(outer : DynamoDbTableEncryptionConfig)
3939
returns (output : Result<Option<I.ValidSearchInfo>, Error>)
4040
requires ValidSearchConfig(outer.search)
41+
requires outer.search.Some? ==> ValidSharedCache(outer.search.value.versions[0].keySource)
4142
ensures output.Success? && output.value.Some? ==>
4243
&& output.value.value.ValidState()
4344
&& fresh(output.value.value.versions[0].keySource.client)
@@ -74,6 +75,19 @@ module SearchConfigToInfo {
7475
forall b <- config.value.versions :: ValidBeaconVersion(b)
7576
}
7677

78+
// Valid state of the provided shared cache, if it exists
79+
predicate {:opaque} ValidSharedCache(config: BeaconKeySource)
80+
{
81+
&& (&& config.single?
82+
&& config.single.cache.Some?
83+
&& config.single.cache.value.Shared?
84+
==> && config.single.cache.value.Shared.ValidState())
85+
&& (&& config.multi?
86+
&& config.multi.cache.Some?
87+
&& config.multi.cache.value.Shared?
88+
==> && config.multi.cache.value.Shared.ValidState())
89+
}
90+
7791
// return true if, `keyFieldName` should be deleted from an item before writing
7892
function method ShouldDeleteKeyField(outer : DynamoDbTableEncryptionConfig, keyFieldName : string)
7993
: (ret : Result<bool, Error>)
@@ -102,6 +116,7 @@ module SearchConfigToInfo {
102116
returns (output : Result<I.KeySource, Error>)
103117
modifies client.Modifies
104118
requires client.ValidState()
119+
requires ValidSharedCache(config)
105120
ensures client.ValidState()
106121
ensures output.Success? ==>
107122
&& output.value.ValidState()
@@ -149,6 +164,11 @@ module SearchConfigToInfo {
149164
var cache;
150165
if cacheType.Shared? {
151166
cache := cacheType.Shared;
167+
reveal ValidSharedCache(config, keyStore);
168+
169+
// This axiom is important because it is not easy to prove
170+
// keyStore.Modifies !! cache.Modifies for a shared cache.
171+
assume {:axiom} keyStore.Modifies !! cache.Modifies;
152172
} else {
153173
//= specification/searchable-encryption/search-config.md#key-store-cache
154174
//# For a Beacon Key Source a [CMC](../../submodules/MaterialProviders/aws-encryption-sdk-specification/framework/cryptographic-materials-cache.md)
@@ -196,6 +216,7 @@ module SearchConfigToInfo {
196216
method ConvertVersion(outer : DynamoDbTableEncryptionConfig, config : BeaconVersion)
197217
returns (output : Result<I.ValidBeaconVersion, Error>)
198218
requires ValidBeaconVersion(config)
219+
requires ValidSharedCache(config.keySource)
199220
ensures output.Success? ==>
200221
&& output.value.ValidState()
201222
&& fresh(output.value.keySource.client)

DynamoDbEncryption/dafny/DynamoDbEncryption/src/SearchInfo.dfy

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,11 @@ module SearchableEncryptionInfo {
274274
&& var oldPutHistory := old(cache.History.PutCacheEntry);
275275
&& var newPutHistory := cache.History.PutCacheEntry;
276276
&& |newPutHistory| == |oldPutHistory|+1
277+
&& (
278+
var storeOutput := Seq.Last(newPutHistory).output;
279+
|| storeOutput.Success?
280+
|| storeOutput.error.EntryAlreadyExists?
281+
)
277282
&& var storeInput := Seq.Last(newPutHistory).input;
278283
&& var storeOutput := Seq.Last(newPutHistory).output;
279284
//= specification/searchable-encryption/search-config.md#get-beacon-key-materials
@@ -333,14 +338,11 @@ module SearchableEncryptionInfo {
333338
var keyMap :- getAllKeys(stdNames, key.value);
334339
var beaconKeyMaterials := rawBeaconKeyMaterials.beaconKeyMaterials.(beaconKey := None, hmacKeys := Some(keyMap));
335340

341+
expect now < UInt.BoundedInts.INT64_MAX - cacheTTL;
336342
//= specification/searchable-encryption/search-config.md#get-beacon-key-materials
337343
//# These materials MUST be put into the associated [Key Store Cache](#key-store-cache)
338344
//# with an [Expiry Time](../../submodules/MaterialProviders/aws-encryption-sdk-specification/framework/cryptographic-materials-cache.md#expiry-time)
339345
//# equal to now + configured [cacheTTL](#cachettl).
340-
:- expect Need(
341-
(now as int + cacheTTL as int) < UInt.INT64_MAX_LIMIT,
342-
MP.AwsCryptographicMaterialProvidersException(message := "INT64 Overflow when putting cache entry.")
343-
);
344346
var putCacheEntryInput:= MP.PutCacheEntryInput(
345347
identifier := identifier,
346348
materials := MP.Materials.BeaconKey(beaconKeyMaterials),

DynamoDbEncryption/dafny/DynamoDbEncryption/test/BeaconTestFixtures.dfy

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ module BeaconTestFixtures {
231231
ensures output.ValidState()
232232
ensures version.keyStore == output.store
233233
ensures fresh(output.client.Modifies)
234+
ensures
235+
&& fresh(output.cache)
236+
&& fresh(output.cache.Modifies)
234237
{
235238
var client :- expect Primitives.AtomicPrimitives();
236239

@@ -252,6 +255,9 @@ module BeaconTestFixtures {
252255
ensures output.ValidState()
253256
ensures version.keyStore == output.store
254257
ensures fresh(output.client.Modifies)
258+
ensures
259+
&& fresh(output.cache)
260+
&& fresh(output.cache.Modifies)
255261
{
256262
var client :- expect Primitives.AtomicPrimitives();
257263
var mpl :- expect MaterialProviders.MaterialProviders();

DynamoDbEncryption/dafny/DynamoDbEncryptionTransforms/src/Index.dfy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ module
154154

155155
assert SearchConfigToInfo.ValidSearchConfig(inputConfig.search);
156156
SearchInModifies(config, tableName);
157+
reveal SearchConfigToInfo.ValidSharedCache();
158+
assume {:axiom} inputConfig.search.Some? ==> SearchConfigToInfo.ValidSharedCache(inputConfig.search.value.versions[0].keySource);
157159
var searchR := SearchConfigToInfo.Convert(inputConfig);
158160
var search :- searchR.MapFailure(e => AwsCryptographyDbEncryptionSdkDynamoDb(e));
159161
assert search.None? || search.value.ValidState();

0 commit comments

Comments
 (0)