From 54951e87fce86b85a4013c3be5cf8bec22deebab Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 12 Aug 2024 21:27:36 +0100 Subject: [PATCH] Update Suave.sol library to https://github.com/flashbots/suave-geth/commit/ad7a8c16e057fc4e3c110b064046c18030e4f697 (#101) Co-authored-by: sukoneck --- src/forge/SuaveAddrs.sol | 44 +++++++++++++++++++++------------------- src/suavelib/Suave.sol | 30 +++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 21 deletions(-) diff --git a/src/forge/SuaveAddrs.sol b/src/forge/SuaveAddrs.sol index 2abbf5f..52c0d7b 100644 --- a/src/forge/SuaveAddrs.sol +++ b/src/forge/SuaveAddrs.sol @@ -6,29 +6,31 @@ import "../suavelib/Suave.sol"; library SuaveAddrs { function getSuaveAddrs() external pure returns (address[] memory) { - address[] memory addrList = new address[](21); + address[] memory addrList = new address[](23); addrList[0] = Suave.IS_CONFIDENTIAL_ADDR; - addrList[1] = Suave.BUILD_ETH_BLOCK; - addrList[2] = Suave.BUILD_ETH_BLOCK_TO; - addrList[3] = Suave.CONFIDENTIAL_RETRIEVE; - addrList[4] = Suave.CONFIDENTIAL_STORE; - addrList[5] = Suave.CONTEXT_GET; - addrList[6] = Suave.DO_HTTPREQUEST; - addrList[7] = Suave.ETHCALL; - addrList[8] = Suave.EXTRACT_HINT; - addrList[9] = Suave.FETCH_DATA_RECORDS; - addrList[10] = Suave.FILL_MEV_SHARE_BUNDLE; - addrList[11] = Suave.NEW_BUILDER; - addrList[12] = Suave.NEW_DATA_RECORD; - addrList[13] = Suave.PRIVATE_KEY_GEN; - addrList[14] = Suave.RANDOM_BYTES; - addrList[15] = Suave.SIGN_ETH_TRANSACTION; - addrList[16] = Suave.SIGN_MESSAGE; - addrList[17] = Suave.SIMULATE_BUNDLE; - addrList[18] = Suave.SIMULATE_TRANSACTION; - addrList[19] = Suave.SUBMIT_BUNDLE_JSON_RPC; - addrList[20] = Suave.SUBMIT_ETH_BLOCK_TO_RELAY; + addrList[1] = Suave.AES_DECRYPT; + addrList[2] = Suave.AES_ENCRYPT; + addrList[3] = Suave.BUILD_ETH_BLOCK; + addrList[4] = Suave.BUILD_ETH_BLOCK_TO; + addrList[5] = Suave.CONFIDENTIAL_RETRIEVE; + addrList[6] = Suave.CONFIDENTIAL_STORE; + addrList[7] = Suave.CONTEXT_GET; + addrList[8] = Suave.DO_HTTPREQUEST; + addrList[9] = Suave.ETHCALL; + addrList[10] = Suave.EXTRACT_HINT; + addrList[11] = Suave.FETCH_DATA_RECORDS; + addrList[12] = Suave.FILL_MEV_SHARE_BUNDLE; + addrList[13] = Suave.NEW_BUILDER; + addrList[14] = Suave.NEW_DATA_RECORD; + addrList[15] = Suave.PRIVATE_KEY_GEN; + addrList[16] = Suave.RANDOM_BYTES; + addrList[17] = Suave.SIGN_ETH_TRANSACTION; + addrList[18] = Suave.SIGN_MESSAGE; + addrList[19] = Suave.SIMULATE_BUNDLE; + addrList[20] = Suave.SIMULATE_TRANSACTION; + addrList[21] = Suave.SUBMIT_BUNDLE_JSON_RPC; + addrList[22] = Suave.SUBMIT_ETH_BLOCK_TO_RELAY; return addrList; } diff --git a/src/suavelib/Suave.sol b/src/suavelib/Suave.sol index 4a69777..3c85c3d 100644 --- a/src/suavelib/Suave.sol +++ b/src/suavelib/Suave.sol @@ -108,6 +108,10 @@ library Suave { address public constant IS_CONFIDENTIAL_ADDR = 0x0000000000000000000000000000000042010000; + address public constant AES_DECRYPT = 0x000000000000000000000000000000005670000D; + + address public constant AES_ENCRYPT = 0x000000000000000000000000000000005670000e; + address public constant BUILD_ETH_BLOCK = 0x0000000000000000000000000000000042100001; address public constant BUILD_ETH_BLOCK_TO = 0x0000000000000000000000000000000042100006; @@ -165,6 +169,32 @@ library Suave { } } + /// @notice Decrypts a message using given bytes as a cipher. + /// @param key Private key used to decrypt the ciphertext + /// @param ciphertext Message to decrypt + /// @return message Decrypted message + function aesDecrypt(bytes memory key, bytes memory ciphertext) internal returns (bytes memory) { + (bool success, bytes memory data) = AES_DECRYPT.call(abi.encode(key, ciphertext)); + if (!success) { + revert PeekerReverted(AES_DECRYPT, data); + } + + return abi.decode(data, (bytes)); + } + + /// @notice Encrypts a message using given bytes as a cipher. + /// @param key Private key used to encrypt the message + /// @param message Message to encrypt + /// @return ciphertext Encrypted message + function aesEncrypt(bytes memory key, bytes memory message) internal returns (bytes memory) { + (bool success, bytes memory data) = AES_ENCRYPT.call(abi.encode(key, message)); + if (!success) { + revert PeekerReverted(AES_ENCRYPT, data); + } + + return abi.decode(data, (bytes)); + } + /// @notice Constructs an Ethereum block based on the provided data records. No blobs are returned. /// @param blockArgs Arguments to build the block /// @param dataId ID of the data record with mev-share bundle data