|
| 1 | +Implementation of Execution Layer Requests |
| 2 | +------------------------------------------ |
| 3 | +```k |
| 4 | +requires "serialization.md" |
| 5 | +``` |
| 6 | + |
| 7 | +```k |
| 8 | +module EVM-REQUESTS |
| 9 | + imports SERIALIZATION |
| 10 | +``` |
| 11 | + |
| 12 | +A `requests` object consists of a `request_type` byte prepended to an opaque byte array `request_data`. |
| 13 | +The `request_data` contains zero or more encoded request objects. |
| 14 | +``` |
| 15 | +requests = request_type ++ request_data |
| 16 | +``` |
| 17 | +Each request type will define its own requests object with its own `request_data` format. |
| 18 | + |
| 19 | +In order to compute the commitment, an intermediate hash list is first built by hashing all non-empty requests elements of the block requests list. |
| 20 | +Items with empty `request_data` are excluded, i.e. the intermediate list skips requests items which contain only the `request_type` (1 byte) and nothing else. |
| 21 | + |
| 22 | +```k |
| 23 | + syntax Int ::= #computeRequestsHash(List) [function, symbol(#computeRequestsHash)] |
| 24 | + // ---------------------------------------------------------------------------------- |
| 25 | + rule #computeRequestsHash(RS) => #parseHexWord(Sha256(#computeRequestsHashIntermediate(RS))) |
| 26 | +
|
| 27 | + syntax Bytes ::= #computeRequestsHashIntermediate(List) [function, symbol(#computeRequestsHashIntermediate)] |
| 28 | + | #computeRequestsHashIntermediate(List, Bytes) [function, symbol(#computeRequestsHashIntermediateAux)] |
| 29 | + // ---------------------------------------------------------------------------------------------------------------------- |
| 30 | + rule #computeRequestsHashIntermediate(RS) => #computeRequestsHashIntermediate(RS, .Bytes) |
| 31 | + rule #computeRequestsHashIntermediate(.List, ACC) => ACC |
| 32 | + rule #computeRequestsHashIntermediate(ListItem(R) RS, ACC) => #computeRequestsHashIntermediate(RS, ACC) |
| 33 | + requires lengthBytes(R) <=Int 1 |
| 34 | + rule #computeRequestsHashIntermediate(ListItem(R) RS, ACC) => #computeRequestsHashIntermediate(RS, ACC +Bytes Sha256raw(R)) |
| 35 | + requires lengthBytes(R) >Int 1 |
| 36 | +``` |
| 37 | + |
| 38 | +Deposit Requests |
| 39 | +---------------- |
| 40 | +The structure denoting the new deposit request consists of the following fields: |
| 41 | + |
| 42 | +1. `pubkey: Bytes48` |
| 43 | +2. `withdrawal_credentials: Bytes32` |
| 44 | +3. `amount: uint64` |
| 45 | +4. `signature: Bytes96` |
| 46 | +5. `index: uint64` |
| 47 | + |
| 48 | +```k |
| 49 | + syntax Int ::= "DEPOSIT_REQUEST_TYPE" [macro] |
| 50 | + | "DEPOSIT_EVENT_LENGTH" [macro] |
| 51 | + | "DEPOSIT_CONTRACT_ADDRESS" [alias] |
| 52 | + | "DEPOSIT_EVENT_SIGNATURE_HASH" [alias] |
| 53 | + // ----------------------------------------------------- |
| 54 | + rule DEPOSIT_REQUEST_TYPE => 0 |
| 55 | + rule DEPOSIT_CONTRACT_ADDRESS => #parseAddr("0x00000000219ab540356cbb839cbe05303d7705fa") |
| 56 | + rule DEPOSIT_EVENT_SIGNATURE_HASH => #parseWord("0x649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5") |
| 57 | + rule DEPOSIT_EVENT_LENGTH => 576 |
| 58 | +
|
| 59 | + syntax Int ::= "PUBKEY_OFFSET" [macro] |
| 60 | + | "WITHDRAWAL_CREDENTIALS_OFFSET"[macro] |
| 61 | + | "AMOUNT_OFFSET" [macro] |
| 62 | + | "SIGNATURE_OFFSET" [macro] |
| 63 | + | "INDEX_OFFSET" [macro] |
| 64 | + | "PUBKEY_SIZE" [macro] |
| 65 | + | "WITHDRAWAL_CREDENTIALS_SIZE" [macro] |
| 66 | + | "AMOUNT_SIZE" [macro] |
| 67 | + | "SIGNATURE_SIZE" [macro] |
| 68 | + | "INDEX_SIZE" [macro] |
| 69 | + // ----------------------------------------------------- |
| 70 | + rule PUBKEY_OFFSET => 160 |
| 71 | + rule WITHDRAWAL_CREDENTIALS_OFFSET => 256 |
| 72 | + rule AMOUNT_OFFSET => 320 |
| 73 | + rule SIGNATURE_OFFSET => 384 |
| 74 | + rule INDEX_OFFSET => 512 |
| 75 | + rule PUBKEY_SIZE => 48 |
| 76 | + rule WITHDRAWAL_CREDENTIALS_SIZE => 32 |
| 77 | + rule AMOUNT_SIZE => 8 |
| 78 | + rule SIGNATURE_SIZE => 96 |
| 79 | + rule INDEX_SIZE => 8 |
| 80 | +``` |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | +```k |
| 85 | + syntax Bytes ::= #extractDepositData ( Bytes ) [function, symbol(#extractDepositData)] |
| 86 | + // -------------------------------------------------------------------------------------- |
| 87 | + rule #extractDepositData(DATA) => substrBytes(DATA, PUBKEY_OFFSET +Int 32, PUBKEY_OFFSET +Int 32 +Int PUBKEY_SIZE) |
| 88 | + +Bytes substrBytes(DATA, WITHDRAWAL_CREDENTIALS_OFFSET +Int 32, WITHDRAWAL_CREDENTIALS_OFFSET +Int 32 +Int WITHDRAWAL_CREDENTIALS_SIZE) |
| 89 | + +Bytes substrBytes(DATA, AMOUNT_OFFSET +Int 32, AMOUNT_OFFSET +Int 32 +Int AMOUNT_SIZE) |
| 90 | + +Bytes substrBytes(DATA, SIGNATURE_OFFSET +Int 32, SIGNATURE_OFFSET +Int 32 +Int SIGNATURE_SIZE) |
| 91 | + +Bytes substrBytes(DATA, INDEX_OFFSET +Int 32, INDEX_OFFSET +Int 32 +Int INDEX_SIZE) |
| 92 | +
|
| 93 | + syntax Bool ::= #isValidDepositEventData ( Bytes ) [function, symbol(#isValidDepositEventData), total] |
| 94 | + // ------------------------------------------------------------------------------------------------------ |
| 95 | + rule #isValidDepositEventData(DATA) => true |
| 96 | + requires lengthBytes(DATA) ==Int DEPOSIT_EVENT_LENGTH |
| 97 | + andBool Bytes2Int(substrBytes(DATA, 0, 32), BE, Unsigned) ==Int PUBKEY_OFFSET |
| 98 | + andBool Bytes2Int(substrBytes(DATA, 32, 64), BE, Unsigned) ==Int WITHDRAWAL_CREDENTIALS_OFFSET |
| 99 | + andBool Bytes2Int(substrBytes(DATA, 64, 96), BE, Unsigned) ==Int AMOUNT_OFFSET |
| 100 | + andBool Bytes2Int(substrBytes(DATA, 96, 128), BE, Unsigned) ==Int SIGNATURE_OFFSET |
| 101 | + andBool Bytes2Int(substrBytes(DATA, 128, 160), BE, Unsigned) ==Int INDEX_OFFSET |
| 102 | + andBool Bytes2Int(substrBytes(DATA, PUBKEY_OFFSET, PUBKEY_OFFSET +Int 32), BE, Unsigned) ==Int PUBKEY_SIZE |
| 103 | + andBool Bytes2Int(substrBytes(DATA, WITHDRAWAL_CREDENTIALS_OFFSET, WITHDRAWAL_CREDENTIALS_OFFSET +Int 32), BE, Unsigned) ==Int WITHDRAWAL_CREDENTIALS_SIZE |
| 104 | + andBool Bytes2Int(substrBytes(DATA, AMOUNT_OFFSET, AMOUNT_OFFSET +Int 32), BE, Unsigned) ==Int AMOUNT_SIZE |
| 105 | + andBool Bytes2Int(substrBytes(DATA, SIGNATURE_OFFSET, SIGNATURE_OFFSET +Int 32), BE, Unsigned) ==Int SIGNATURE_SIZE |
| 106 | + andBool Bytes2Int(substrBytes(DATA, INDEX_OFFSET, INDEX_OFFSET +Int 32), BE, Unsigned) ==Int INDEX_SIZE |
| 107 | +
|
| 108 | + rule #isValidDepositEventData(_) => false [owise] |
| 109 | +``` |
| 110 | + |
| 111 | +```k |
| 112 | +endmodule |
| 113 | +``` |
0 commit comments