File: limited_entropy_randomization.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (67 lines) | stat: -rw-r--r-- 3,511 bytes parent folder | download | duplicates (3)
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
64
65
66
67
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_VARIATIONS_SERVICE_LIMITED_ENTROPY_RANDOMIZATION_H_
#define COMPONENTS_VARIATIONS_SERVICE_LIMITED_ENTROPY_RANDOMIZATION_H_

// Provides functions to validate that the variations seed is
// correctly configured to respect an entropy limit. See below for details.
//
// This limit only applies to field trials configured to use the "limited
// entropy" layer – that is, a layer with `EntropyMode.LIMITED`. For brevity,
// documentation in this file will refer to this layer as the "limited layer".
// There is at most one limited layer in the seed with filters that are
// applicable to the client. For now, it's the server's responsibility to ensure
// this invariant. As an optimization, the client code should be updated to
// consider the filters when calculating entropy (TODO(b/319681288)).
//
// Consider each client's chosen groups across all studies which use limited
// entropy. While some group combinations may be more likely than others (based
// on group percentages), the combination with the minimum probability must have
// a probability above an entropy limit we define (see below). For brevity,
// documentation in this file will refer to information revealed by these chosen
// groups as "entropy".
//
// The entropy limit defined here is analogous to the "low entropy source" used
// elsewhere in the variations codebase, but uses a different implementation
// approach to achieve the result of limiting the total entropy.
//
// See https://en.wikipedia.org/wiki/Entropy_(information_theory) for more
// information about "entropy" as a mathematical concept.
namespace variations {

class VariationsLayers;
class VariationsSeed;

// The maximum amount of total entropy, in bits, for field trials with Google
// web experiment ids.
//
// Precisely, the cumulative probability of group assignments across all such
// field trials on the client must be at least 1 / (2 ^
// `kGoogleWebEntropyLimitInBits`). This constant is expressed as a double so
// that any such fraction can be represented. A limit of 1 bit means at a
// minimum 50% of clients will have the same group assignment combinations
// across studies referencing the limited layer. This setting is used during the
// time when `LimitedEntropySyntheticTrial` is active to control the number of
// studies using the limited entropy mode.
// TODO(crbug.com/422222582): Duly update this.
inline constexpr double kGoogleWebEntropyLimitInBits = 1.0;

// Returns true iff the entropy from the field trials in the seed is
// misconfigured, or entropy cannot be computed. The caller is expected to
// handle the return value and reject the seed if necessary.
bool SeedHasMisconfiguredEntropy(const VariationsLayers& layers,
                                 const VariationsSeed& seed);

// A test-only accessor for a function that checks if there is enough entropy
// for all studies constrained to the limited layer. This allows tests to
// validate the entropy calculation logic, independently of the value of
// `kGoogleWebEntropyLimitInBits`.
bool IsEnoughLimitedEntropyAvailableForTesting(const VariationsLayers& layers,
                                               const VariationsSeed& seed,
                                               double entropy_limit);

}  // namespace variations

#endif  // COMPONENTS_VARIATIONS_SERVICE_LIMITED_ENTROPY_RANDOMIZATION_H_