From 6815c7b1903bf0384a4ebec89c5f1c0691e16e70 Mon Sep 17 00:00:00 2001 From: Kasper Ziemianek Date: Thu, 6 Jun 2024 10:29:45 +0200 Subject: [PATCH 01/10] handle evm http precompile errors (#2790) --- .../src/dynamic/contracts/A1.sol | 22 +- .../src/dynamic/contracts/A20.sol | 50 ++-- .../src/dynamic/contracts/A6.sol | 27 +-- .../dynamic/contracts/DynamicAssertion.sol | 219 +++++++++--------- .../src/dynamic/contracts/tests/GetBool.sol | 19 +- .../src/dynamic/contracts/tests/GetI64.sol | 13 +- .../src/dynamic/contracts/tests/ToHex.sol | 6 +- .../core/assertion-build/src/dynamic/mod.rs | 130 +++++++++-- .../assertion-build/src/dynamic/repository.rs | 6 +- .../src/precompiles/http_get.rs | 103 ++++---- .../src/precompiles/macros.rs | 131 +++++++---- .../src/precompiles/to_hex.rs | 30 ++- 12 files changed, 482 insertions(+), 274 deletions(-) diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/A1.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/A1.sol index bc657bf958..1028305481 100644 --- a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/A1.sol +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/A1.sol @@ -18,22 +18,22 @@ pragma solidity ^0.8.8; -import {DynamicAssertion, Identity} from "DynamicAssertion.sol"; +import {DynamicAssertion, Identity} from "./DynamicAssertion.sol"; contract A1 is DynamicAssertion { function execute(Identity[] memory identities, string[] memory secrets) - public - override - returns ( - string memory, - string memory, - string[] memory, - string memory, - bool - ) + public + override + returns ( + string memory, + string memory, + string[] memory, + string memory, + bool + ) { string - memory description = "You've identified at least one account/address in both Web2 and Web3."; + memory description = "You've identified at least one account/address in both Web2 and Web3."; string memory assertion_type = "Basic Identity Verification"; assertions.push( '{"and": [{ "src": "$has_web2_account", "op": "==", "dst": "true" }, { "src": "$has_web3_account", "op": "==", "dst": "true" } ] }' diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/A20.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/A20.sol index 77bbaac1ed..bccbf6783d 100644 --- a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/A20.sol +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/A20.sol @@ -18,22 +18,22 @@ pragma solidity ^0.8.8; -import {DynamicAssertion, Identity, HttpHeader} from "DynamicAssertion.sol"; +import {DynamicAssertion, Identity, HttpHeader} from "./DynamicAssertion.sol"; contract A20 is DynamicAssertion { function execute(Identity[] memory identities, string[] memory secrets) - public - override - returns ( - string memory, - string memory, - string[] memory, - string memory, - bool - ) + public + override + returns ( + string memory, + string memory, + string[] memory, + string memory, + bool + ) { string - memory description = "The user is an early bird user of the IdentityHub EVM version and has generated at least 1 credential during 2023 Aug 14th ~ Aug 21st."; + memory description = "The user is an early bird user of the IdentityHub EVM version and has generated at least 1 credential during 2023 Aug 14th ~ Aug 21st."; string memory assertion_type = "IDHub EVM Version Early Bird"; assertions.push('{ "src": "$has_joined", "op": "==", "dst": "true" }'); schema_url = "https://raw.githubusercontent.com/litentry/vc-jsonschema/main/dist/schemas/12-idhub-evm-version-early-bird/1-0-0.json"; @@ -41,16 +41,28 @@ contract A20 is DynamicAssertion { for (uint256 i = 0; i < identities.length; i++) { if (is_web3(identities[i])) { - string memory res = toHex(identities[i].value); + (bool success, string memory res) = toHex(identities[i].value); + if (success) { + if (!success) { + continue; + } + string memory url = concatenateStrings( + "http://localhost:19527/events/does-user-joined-evm-campaign?account=", + res + ); + string memory jsonPointer = "/hasJoined"; + HttpHeader[] memory headers = new HttpHeader[](0); - string memory url = concatenateStrings( - "http://localhost:19527/events/does-user-joined-evm-campaign?account=", - res - ); - string memory jsonPointer = "/hasJoined"; - HttpHeader[] memory headers = new HttpHeader[](0); + (bool get_success, bool get_result) = GetBool( + url, + jsonPointer, + headers + ); + if (get_success) { + result = get_result; + } + } - result = GetBool(url, jsonPointer, headers); if (result) { break; } diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/A6.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/A6.sol index f7d5793c3d..1156a3546a 100644 --- a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/A6.sol +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/A6.sol @@ -23,19 +23,18 @@ import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.9.0/contr contract A6 is DynamicAssertion { function execute(Identity[] memory identities, string[] memory secrets) - public - override - returns ( - - string memory, - string memory, - string[] memory, - string memory, - bool - ) + public + override + returns ( + string memory, + string memory, + string[] memory, + string memory, + bool + ) { string - memory description = "The range of the user's Twitter follower count"; + memory description = "The range of the user's Twitter follower count"; string memory assertion_type = "Twitter Follower Amount"; schema_url = "https://raw.githubusercontent.com/litentry/vc-jsonschema/main/dist/schemas/6-twitter-follower-amount/1-0-0.json"; @@ -58,13 +57,15 @@ contract A6 is DynamicAssertion { // we expect first secret to be twitter api key headers[0] = HttpHeader("authorization", secrets[0]); - int64 followers_count = GetI64( + (bool get_success, int64 followers_count) = GetI64( full_url, "/data/public_metrics/followers_count", headers ); - sum += followers_count; + if (get_success) { + sum += followers_count; + } } } diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/DynamicAssertion.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/DynamicAssertion.sol index c83cf52d2b..a1d6f84b7d 100644 --- a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/DynamicAssertion.sol +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/DynamicAssertion.sol @@ -18,36 +18,36 @@ pragma solidity ^0.8.8; - struct Identity { - uint32 identity_type; - bytes value; - uint32[] networks; - } +struct Identity { + uint32 identity_type; + bytes value; + uint32[] networks; +} - struct HttpHeader { - string name; - string value; - } +struct HttpHeader { + string name; + string value; +} abstract contract DynamicAssertion { string[] assertions; string schema_url; function execute(Identity[] memory identities, string[] memory secrets) - public - virtual - returns ( - string memory, - string memory, - string[] memory, - string memory, - bool - ); + public + virtual + returns ( + string memory, + string memory, + string[] memory, + string memory, + bool + ); function encode_params(string memory url, string memory jsonPointer) - internal - pure - returns (bytes memory) + internal + pure + returns (bytes memory) { return abi.encode(url, jsonPointer); } @@ -56,7 +56,8 @@ abstract contract DynamicAssertion { string memory url, string memory jsonPointer, HttpHeader[] memory headers - ) internal returns (int64) { + ) internal returns (bool, int64) { + bool success; int64 value; bytes memory encoded_params = abi.encode(url, jsonPointer, headers); @@ -71,22 +72,25 @@ abstract contract DynamicAssertion { add(encoded_params, 0x20), encoded_params_len, memPtr, - 0x20 + 0x40 ) ) { revert(0, 0) } - value := mload(memPtr) + success := mload(memPtr) + value := mload(add(memPtr, 0x20)) + mstore(0x40, add(memPtr, 0x40)) } - return (value); + return (success, value); } function GetBool( string memory url, string memory jsonPointer, HttpHeader[] memory headers - ) internal returns (bool) { + ) internal returns (bool, bool) { + bool success; bool value; bytes memory encoded_params = abi.encode(url, jsonPointer, headers); @@ -102,29 +106,31 @@ abstract contract DynamicAssertion { add(encoded_params, 0x20), encoded_params_len, memPtr, - 0x20 + 0x40 ) ) { revert(0, 0) } - value := mload(memPtr) + success := mload(memPtr) + value := mload(add(memPtr, 0x20)) + mstore(0x40, add(memPtr, 0x40)) } - return (value); + return (success, value); } function concatenateStrings(string memory a, string memory b) - internal - pure - returns (string memory) + internal + pure + returns (string memory) { bytes memory concatenatedBytes = abi.encodePacked(a, b); return string(concatenatedBytes); } function toHex(bytes memory bytes_value) - internal - returns (string memory returnVal) + internal + returns (bool success, string memory value) { bytes memory encoded = abi.encode(bytes_value); uint256 encoded_len = encoded.length; @@ -138,13 +144,18 @@ abstract contract DynamicAssertion { 0, add(encoded, 0x20), encoded_len, - returnVal, - 0x82 + memPtr, + 0x1000 ) ) { revert(0, 0) } + success := memPtr + value := add(memPtr, 0x40) + mstore(0x40, add(memPtr, 0x1000)) } + + return (success, value); } function from( @@ -156,22 +167,22 @@ abstract contract DynamicAssertion { } function is_web3(Identity memory identity_type) - internal - pure - returns (bool) + internal + pure + returns (bool) { return (is_substrate(identity_type) || - is_evm(identity_type) || + is_evm(identity_type) || is_bitcoin(identity_type)); } function is_web2(Identity memory identity_type) - internal - pure - returns (bool) + internal + pure + returns (bool) { return (is_twitter(identity_type) || - is_discord(identity_type) || + is_discord(identity_type) || is_github(identity_type)); } @@ -188,9 +199,9 @@ abstract contract DynamicAssertion { } function is_substrate(Identity memory identity) - internal - pure - returns (bool) + internal + pure + returns (bool) { return is_of_type(identity, 3); } @@ -208,9 +219,9 @@ abstract contract DynamicAssertion { } function is_of_type(Identity memory identity, uint32 identity_type) - internal - pure - returns (bool) + internal + pure + returns (bool) { if (identity.identity_type == identity_type) { return (true); @@ -220,145 +231,145 @@ abstract contract DynamicAssertion { } function has_polkadot_network(Identity memory identity_type) - internal - pure - returns (bool) + internal + pure + returns (bool) { return has_network(identity_type, 0); } function has_kusama_network(Identity memory identity_type) - internal - pure - returns (bool) + internal + pure + returns (bool) { return has_network(identity_type, 1); } function has_litentry_network(Identity memory identity_type) - internal - pure - returns (bool) + internal + pure + returns (bool) { return has_network(identity_type, 2); } function has_litmus_network(Identity memory identity_type) - internal - pure - returns (bool) + internal + pure + returns (bool) { return has_network(identity_type, 3); } function has_litentry_rococo_network(Identity memory identity_type) - internal - pure - returns (bool) + internal + pure + returns (bool) { return has_network(identity_type, 4); } function has_khala_network(Identity memory identity_type) - internal - pure - returns (bool) + internal + pure + returns (bool) { return has_network(identity_type, 5); } function has_substrate_testnet_network(Identity memory identity_type) - internal - pure - returns (bool) + internal + pure + returns (bool) { return has_network(identity_type, 6); } function has_ethereum_network(Identity memory identity_type) - internal - pure - returns (bool) + internal + pure + returns (bool) { return has_network(identity_type, 7); } function has_bsc_network(Identity memory identity_type) - internal - pure - returns (bool) + internal + pure + returns (bool) { return has_network(identity_type, 8); } function has_bitcoin_p2tr_network(Identity memory identity_type) - internal - pure - returns (bool) + internal + pure + returns (bool) { return has_network(identity_type, 9); } function has_bitcoin_p2pkh_network(Identity memory identity_type) - internal - pure - returns (bool) + internal + pure + returns (bool) { return has_network(identity_type, 10); } function has_bitcoin_p2sh_network(Identity memory identity_type) - internal - pure - returns (bool) + internal + pure + returns (bool) { return has_network(identity_type, 11); } function has_bitcoin_p2wpkh_network(Identity memory identity_type) - internal - pure - returns (bool) + internal + pure + returns (bool) { return has_network(identity_type, 12); } function has_bitcoin_p2wsh_network(Identity memory identity_type) - internal - pure - returns (bool) + internal + pure + returns (bool) { return has_network(identity_type, 13); } function has_polygon_network(Identity memory identity_type) - internal - pure - returns (bool) + internal + pure + returns (bool) { return has_network(identity_type, 14); } function has_arbitrum_network(Identity memory identity_type) - internal - pure - returns (bool) + internal + pure + returns (bool) { return has_network(identity_type, 15); } function has_solana_network(Identity memory identity_type) - internal - pure - returns (bool) + internal + pure + returns (bool) { return has_network(identity_type, 16); } function has_network(Identity memory identity_type, uint32 network) - internal - pure - returns (bool) + internal + pure + returns (bool) { for (uint256 i = 0; i < identity_type.networks.length; i++) { if (identity_type.networks[i] == network) { diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/GetBool.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/GetBool.sol index 3b63bff3b1..1e977eed81 100644 --- a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/GetBool.sol +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/GetBool.sol @@ -20,7 +20,7 @@ pragma solidity ^0.8.8; import {DynamicAssertion, Identity, HttpHeader} from "./DynamicAssertion.sol"; -contract GetBool is DynamicAssertion { +contract GetI64 is DynamicAssertion { function execute(Identity[] memory identities, string[] memory secrets) public override @@ -41,9 +41,22 @@ contract GetBool is DynamicAssertion { function callGetBool(string memory url, string memory jsonPointer) public - returns (bool) + returns (bool, bool) { HttpHeader[] memory headers = new HttpHeader[](0); - return GetBool(url, jsonPointer, headers);(url, jsonPointer, headers); + return GetBool(url, jsonPointer, headers); + (url, jsonPointer, headers); + } + + function callGetBoolTwiceAndReturnSecondResult( + string memory firstUrl, + string memory firstJsonPointer, + string memory secondUrl, + string memory secondJsonPointer + ) public returns (bool, bool) { + HttpHeader[] memory headers = new HttpHeader[](0); + GetBool(firstUrl, firstJsonPointer, headers); + (firstUrl, firstJsonPointer, headers); + return GetBool(secondUrl, secondJsonPointer, headers); } } diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/GetI64.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/GetI64.sol index 6445bc8067..a0246c8570 100644 --- a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/GetI64.sol +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/GetI64.sol @@ -41,9 +41,20 @@ contract GetI64 is DynamicAssertion { function callGetI64(string memory url, string memory jsonPointer) public - returns (int64) + returns (bool, int64) { HttpHeader[] memory headers = new HttpHeader[](0); return GetI64(url, jsonPointer, headers); } + + function callGetI64TwiceAndReturnSecondResult( + string memory firstUrl, + string memory firstJsonPointer, + string memory secondUrl, + string memory secondJsonPointer + ) public returns (bool, int64) { + HttpHeader[] memory headers = new HttpHeader[](0); + GetI64(firstUrl, firstJsonPointer, headers); + return GetI64(secondUrl, secondJsonPointer, headers); + } } diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/ToHex.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/ToHex.sol index 74defcd087..76874099b7 100644 --- a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/ToHex.sol +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/ToHex.sol @@ -39,8 +39,10 @@ contract ToHex is DynamicAssertion { return (description, assertion_type, assertions, schema_url, result); } - function callToHex(string memory text) public returns (string memory) { + function callToHex(string memory text) + public + returns (bool, string memory) + { return toHex(bytes(text)); } - } diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/mod.rs b/tee-worker/litentry/core/assertion-build/src/dynamic/mod.rs index e02e6074ce..a1ead2686e 100644 --- a/tee-worker/litentry/core/assertion-build/src/dynamic/mod.rs +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/mod.rs @@ -85,34 +85,34 @@ pub mod dynamic_assertion_test { use primitive_types::U256; // ToHex.sol bytecode - const TO_HEX_BYTE_CODE: &str = "608060405234801561001057600080fd5b506107df806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80638876183c1461003b578063e256184614610064575b600080fd5b61004e6100493660046103ac565b610088565b60405161005b9190610436565b60405180910390f35b610077610072366004610516565b610099565b60405161005b9594939291906106c4565b606061009382610272565b92915050565b6060806060806000806040518060400160405280600b81526020016a3232b9b1b934b83a34b7b760a91b815250905060006040518060400160405280600e81526020016d617373657274696f6e207479706560901b815250905060008282600060018482805480602002602001604051908101604052809291908181526020016000905b828210156101c957838290600052602060002001805461013c9061076e565b80601f01602080910402602001604051908101604052809291908181526020018280546101689061076e565b80156101b55780601f1061018a576101008083540402835291602001916101b5565b820191906000526020600020905b81548152906001019060200180831161019857829003601f168201915b50505050508152602001906001019061011d565b5050505092508180546101db9061076e565b80601f01602080910402602001604051908101604052809291908181526020018280546102079061076e565b80156102545780601f1061022957610100808354040283529160200191610254565b820191906000526020600020905b81548152906001019060200180831161023757829003601f168201915b50505050509150975097509750975097505050509295509295909350565b60606000826040516020016102879190610436565b60408051601f1981840301815291905280519091506082838260208501600061041b600019f16102b657600080fd5b5050919050565b634e487b7160e01b600052604160045260246000fd5b6040516060810167ffffffffffffffff811182821017156102f6576102f66102bd565b60405290565b604051601f8201601f1916810167ffffffffffffffff81118282101715610325576103256102bd565b604052919050565b600067ffffffffffffffff831115610347576103476102bd565b61035a601f8401601f19166020016102fc565b905082815283838301111561036e57600080fd5b828260208301376000602084830101529392505050565b600082601f83011261039657600080fd5b6103a58383356020850161032d565b9392505050565b6000602082840312156103be57600080fd5b813567ffffffffffffffff8111156103d557600080fd5b6103e184828501610385565b949350505050565b6000815180845260005b8181101561040f576020818501810151868301820152016103f3565b81811115610421576000602083870101525b50601f01601f19169290920160200192915050565b6020815260006103a560208301846103e9565b600067ffffffffffffffff821115610463576104636102bd565b5060051b60200190565b803563ffffffff8116811461048157600080fd5b919050565b600082601f83011261049757600080fd5b813560206104ac6104a783610449565b6102fc565b82815260059290921b840181019181810190868411156104cb57600080fd5b8286015b8481101561050b57803567ffffffffffffffff8111156104ef5760008081fd5b6104fd8986838b0101610385565b8452509183019183016104cf565b509695505050505050565b6000806040838503121561052957600080fd5b823567ffffffffffffffff8082111561054157600080fd5b818501915085601f83011261055557600080fd5b813560206105656104a783610449565b82815260059290921b8401810191818101908984111561058457600080fd5b8286015b848110156106965780358681111561059f57600080fd5b87016060818d03601f190112156105b557600080fd5b6105bd6102d3565b6105c886830161046d565b81526040820135888111156105dc57600080fd5b8201603f81018e136105ed57600080fd5b6105fe8e888301356040840161032d565b878301525060608201358881111561061557600080fd5b8083019250508c603f83011261062a57600080fd5b8582013561063a6104a782610449565b81815260059190911b830160400190878101908f83111561065a57600080fd5b6040850194505b82851015610681576106728561046d565b82529388019390880190610661565b60408401525050845250918301918301610588565b50965050860135925050808211156106ad57600080fd5b506106ba85828601610486565b9150509250929050565b60a0815260006106d760a08301886103e9565b6020838203818501526106ea82896103e9565b915083820360408501528187518084528284019150828160051b850101838a0160005b8381101561073b57601f198784030185526107298383516103e9565b9486019492509085019060010161070d565b5050868103606088015261074f818a6103e9565b95505050505050610764608083018415159052565b9695505050505050565b600181811c9082168061078257607f821691505b602082108114156107a357634e487b7160e01b600052602260045260246000fd5b5091905056fea26469706673582212203cf1d6eb7c4fe44d326d0a5d386646fdef08a68cccb3ed1500f49aabb85b780664736f6c634300080b0033"; + const TO_HEX_BYTE_CODE: &str = "608060405234801561001057600080fd5b50610817806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80638876183c1461003b578063e256184614610065575b600080fd5b61004e6100493660046103c9565b610089565b60405161005c929190610453565b60405180910390f35b61007861007336600461053b565b61009f565b60405161005c9594939291906106e9565b6000606061009683610278565b91509150915091565b6060806060806000806040518060400160405280600b81526020016a3232b9b1b934b83a34b7b760a91b815250905060006040518060400160405280600e81526020016d617373657274696f6e207479706560901b815250905060008282600060018482805480602002602001604051908101604052809291908181526020016000905b828210156101cf57838290600052602060002001805461014290610793565b80601f016020809104026020016040519081016040528092919081815260200182805461016e90610793565b80156101bb5780601f10610190576101008083540402835291602001916101bb565b820191906000526020600020905b81548152906001019060200180831161019e57829003601f168201915b505050505081526020019060010190610123565b5050505092508180546101e190610793565b80601f016020809104026020016040519081016040528092919081815260200182805461020d90610793565b801561025a5780601f1061022f5761010080835404028352916020019161025a565b820191906000526020600020905b81548152906001019060200180831161023d57829003601f168201915b50505050509150975097509750975097505050509295509295909350565b6000606060008360405160200161028f91906107ce565b60408051601f1981840301815290829052805190925090611000818360208601600061041b600019f16102c157600080fd5b8094506040810193506110008101604052505050915091565b634e487b7160e01b600052604160045260246000fd5b6040516060810167ffffffffffffffff81118282101715610313576103136102da565b60405290565b604051601f8201601f1916810167ffffffffffffffff81118282101715610342576103426102da565b604052919050565b600067ffffffffffffffff831115610364576103646102da565b610377601f8401601f1916602001610319565b905082815283838301111561038b57600080fd5b828260208301376000602084830101529392505050565b600082601f8301126103b357600080fd5b6103c28383356020850161034a565b9392505050565b6000602082840312156103db57600080fd5b813567ffffffffffffffff8111156103f257600080fd5b6103fe848285016103a2565b949350505050565b6000815180845260005b8181101561042c57602081850181015186830182015201610410565b8181111561043e576000602083870101525b50601f01601f19169290920160200192915050565b82151581526040602082015260006103fe6040830184610406565b600067ffffffffffffffff821115610488576104886102da565b5060051b60200190565b803563ffffffff811681146104a657600080fd5b919050565b600082601f8301126104bc57600080fd5b813560206104d16104cc8361046e565b610319565b82815260059290921b840181019181810190868411156104f057600080fd5b8286015b8481101561053057803567ffffffffffffffff8111156105145760008081fd5b6105228986838b01016103a2565b8452509183019183016104f4565b509695505050505050565b6000806040838503121561054e57600080fd5b823567ffffffffffffffff8082111561056657600080fd5b818501915085601f83011261057a57600080fd5b8135602061058a6104cc8361046e565b82815260059290921b840181019181810190898411156105a957600080fd5b8286015b848110156106bb578035868111156105c457600080fd5b87016060818d03601f190112156105da57600080fd5b6105e26102f0565b6105ed868301610492565b815260408201358881111561060157600080fd5b8201603f81018e1361061257600080fd5b6106238e888301356040840161034a565b878301525060608201358881111561063a57600080fd5b8083019250508c603f83011261064f57600080fd5b8582013561065f6104cc8261046e565b81815260059190911b830160400190878101908f83111561067f57600080fd5b6040850194505b828510156106a65761069785610492565b82529388019390880190610686565b604084015250508452509183019183016105ad565b50965050860135925050808211156106d257600080fd5b506106df858286016104ab565b9150509250929050565b60a0815260006106fc60a0830188610406565b60208382038185015261070f8289610406565b915083820360408501528187518084528284019150828160051b850101838a0160005b8381101561076057601f1987840301855261074e838351610406565b94860194925090850190600101610732565b50508681036060880152610774818a610406565b95505050505050610789608083018415159052565b9695505050505050565b600181811c908216806107a757607f821691505b602082108114156107c857634e487b7160e01b600052602260045260246000fd5b50919050565b6020815260006103c2602083018461040656fea26469706673582212202bc48bafd887e8c048a6dd3bfe6528691288f0a4158ec3c7f543773204e9991564736f6c634300080b0033"; // ConcatenateStrings.sol bytecode - const CONCATENATE_STRINGS_BYTE_CODE: &str = "608060405234801561001057600080fd5b5061081a806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063e25618461461003b578063f2baa36e14610068575b600080fd5b61004e610049366004610458565b610088565b60405161005f959493929190610663565b60405180910390f35b61007b61007636600461070d565b610261565b60405161005f9190610767565b6060806060806000806040518060400160405280600b81526020016a3232b9b1b934b83a34b7b760a91b815250905060006040518060400160405280600e81526020016d617373657274696f6e207479706560901b815250905060008282600060018482805480602002602001604051908101604052809291908181526020016000905b828210156101b857838290600052602060002001805461012b9061077a565b80601f01602080910402602001604051908101604052809291908181526020018280546101579061077a565b80156101a45780601f10610179576101008083540402835291602001916101a4565b820191906000526020600020905b81548152906001019060200180831161018757829003601f168201915b50505050508152602001906001019061010c565b5050505092508180546101ca9061077a565b80601f01602080910402602001604051908101604052809291908181526020018280546101f69061077a565b80156102435780601f1061021857610100808354040283529160200191610243565b820191906000526020600020905b81548152906001019060200180831161022657829003601f168201915b50505050509150975097509750975097505050509295509295909350565b606061026d8383610274565b9392505050565b60606000838360405160200161028b9291906107b5565b60408051808303601f19018152919052949350505050565b634e487b7160e01b600052604160045260246000fd5b6040516060810167ffffffffffffffff811182821017156102dc576102dc6102a3565b60405290565b604051601f8201601f1916810167ffffffffffffffff8111828210171561030b5761030b6102a3565b604052919050565b600067ffffffffffffffff82111561032d5761032d6102a3565b5060051b60200190565b803563ffffffff8116811461034b57600080fd5b919050565b600067ffffffffffffffff83111561036a5761036a6102a3565b61037d601f8401601f19166020016102e2565b905082815283838301111561039157600080fd5b828260208301376000602084830101529392505050565b600082601f8301126103b957600080fd5b61026d83833560208501610350565b600082601f8301126103d957600080fd5b813560206103ee6103e983610313565b6102e2565b82815260059290921b8401810191818101908684111561040d57600080fd5b8286015b8481101561044d57803567ffffffffffffffff8111156104315760008081fd5b61043f8986838b01016103a8565b845250918301918301610411565b509695505050505050565b6000806040838503121561046b57600080fd5b823567ffffffffffffffff8082111561048357600080fd5b818501915085601f83011261049757600080fd5b813560206104a76103e983610313565b82815260059290921b840181019181810190898411156104c657600080fd5b8286015b848110156105d9578035868111156104e157600080fd5b87016060818d03601f190112156104f757600080fd5b6104ff6102b9565b61050a868301610337565b815260408201358881111561051e57600080fd5b8201603f81018e1361052f57600080fd5b6105408e8883013560408401610350565b878301525060608201358881111561055757600080fd5b8083019250508c603f83011261056c57600080fd5b8582013561057c6103e982610313565b81815260059190911b83018701870190878101908f83111561059d57600080fd5b6040850194505b828510156105c4576105b585610337565b825293880193908801906105a4565b604084015250508452509183019183016104ca565b50965050860135925050808211156105f057600080fd5b506105fd858286016103c8565b9150509250929050565b60005b8381101561062257818101518382015260200161060a565b83811115610631576000848401525b50505050565b6000815180845261064f816020860160208601610607565b601f01601f19169290920160200192915050565b60a08152600061067660a0830188610637565b6020838203818501526106898289610637565b915083820360408501528187518084528284019150828160051b850101838a0160005b838110156106da57601f198784030185526106c8838351610637565b948601949250908501906001016106ac565b505086810360608801526106ee818a610637565b95505050505050610703608083018415159052565b9695505050505050565b6000806040838503121561072057600080fd5b823567ffffffffffffffff8082111561073857600080fd5b610744868387016103a8565b9350602085013591508082111561075a57600080fd5b506105fd858286016103a8565b60208152600061026d6020830184610637565b600181811c9082168061078e57607f821691505b602082108114156107af57634e487b7160e01b600052602260045260246000fd5b50919050565b600083516107c7818460208801610607565b8351908301906107db818360208801610607565b0194935050505056fea26469706673582212207f15f6f9a5e2fb439abd419e86363251711d69b4eaa101d644a892bb32736a1c64736f6c634300080b0033"; + const CONCATENATE_STRINGS_BYTE_CODE: &str = "608060405234801561001057600080fd5b5061081a806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063e25618461461003b578063f2baa36e14610068575b600080fd5b61004e610049366004610458565b610088565b60405161005f959493929190610663565b60405180910390f35b61007b61007636600461070d565b610261565b60405161005f9190610767565b6060806060806000806040518060400160405280600b81526020016a3232b9b1b934b83a34b7b760a91b815250905060006040518060400160405280600e81526020016d617373657274696f6e207479706560901b815250905060008282600060018482805480602002602001604051908101604052809291908181526020016000905b828210156101b857838290600052602060002001805461012b9061077a565b80601f01602080910402602001604051908101604052809291908181526020018280546101579061077a565b80156101a45780601f10610179576101008083540402835291602001916101a4565b820191906000526020600020905b81548152906001019060200180831161018757829003601f168201915b50505050508152602001906001019061010c565b5050505092508180546101ca9061077a565b80601f01602080910402602001604051908101604052809291908181526020018280546101f69061077a565b80156102435780601f1061021857610100808354040283529160200191610243565b820191906000526020600020905b81548152906001019060200180831161022657829003601f168201915b50505050509150975097509750975097505050509295509295909350565b606061026d8383610274565b9392505050565b60606000838360405160200161028b9291906107b5565b60408051808303601f19018152919052949350505050565b634e487b7160e01b600052604160045260246000fd5b6040516060810167ffffffffffffffff811182821017156102dc576102dc6102a3565b60405290565b604051601f8201601f1916810167ffffffffffffffff8111828210171561030b5761030b6102a3565b604052919050565b600067ffffffffffffffff82111561032d5761032d6102a3565b5060051b60200190565b803563ffffffff8116811461034b57600080fd5b919050565b600067ffffffffffffffff83111561036a5761036a6102a3565b61037d601f8401601f19166020016102e2565b905082815283838301111561039157600080fd5b828260208301376000602084830101529392505050565b600082601f8301126103b957600080fd5b61026d83833560208501610350565b600082601f8301126103d957600080fd5b813560206103ee6103e983610313565b6102e2565b82815260059290921b8401810191818101908684111561040d57600080fd5b8286015b8481101561044d57803567ffffffffffffffff8111156104315760008081fd5b61043f8986838b01016103a8565b845250918301918301610411565b509695505050505050565b6000806040838503121561046b57600080fd5b823567ffffffffffffffff8082111561048357600080fd5b818501915085601f83011261049757600080fd5b813560206104a76103e983610313565b82815260059290921b840181019181810190898411156104c657600080fd5b8286015b848110156105d9578035868111156104e157600080fd5b87016060818d03601f190112156104f757600080fd5b6104ff6102b9565b61050a868301610337565b815260408201358881111561051e57600080fd5b8201603f81018e1361052f57600080fd5b6105408e8883013560408401610350565b878301525060608201358881111561055757600080fd5b8083019250508c603f83011261056c57600080fd5b8582013561057c6103e982610313565b81815260059190911b83018701870190878101908f83111561059d57600080fd5b6040850194505b828510156105c4576105b585610337565b825293880193908801906105a4565b604084015250508452509183019183016104ca565b50965050860135925050808211156105f057600080fd5b506105fd858286016103c8565b9150509250929050565b60005b8381101561062257818101518382015260200161060a565b83811115610631576000848401525b50505050565b6000815180845261064f816020860160208601610607565b601f01601f19169290920160200192915050565b60a08152600061067660a0830188610637565b6020838203818501526106898289610637565b915083820360408501528187518084528284019150828160051b850101838a0160005b838110156106da57601f198784030185526106c8838351610637565b948601949250908501906001016106ac565b505086810360608801526106ee818a610637565b95505050505050610703608083018415159052565b9695505050505050565b6000806040838503121561072057600080fd5b823567ffffffffffffffff8082111561073857600080fd5b610744868387016103a8565b9350602085013591508082111561075a57600080fd5b506105fd858286016103a8565b60208152600061026d6020830184610637565b600181811c9082168061078e57607f821691505b602082108114156107af57634e487b7160e01b600052602260045260246000fd5b50919050565b600083516107c7818460208801610607565b8351908301906107db818360208801610607565b0194935050505056fea2646970667358221220d4508ca4edbbc299296fc8dfc0223e54a63c733d541d0f6109c778d0af6539b064736f6c634300080b0033"; // GetI64.sol bytecode - const GET_I64_BYTE_CODE: &str = "608060405234801561001057600080fd5b506108e9806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063e25618461461003b578063f5e19bc014610068575b600080fd5b61004e6100493660046104ce565b61008e565b60405161005f9594939291906106c9565b60405180910390f35b61007b610076366004610773565b610267565b60405160079190910b815260200161005f565b6060806060806000806040518060400160405280600b81526020016a3232b9b1b934b83a34b7b760a91b815250905060006040518060400160405280600e81526020016d617373657274696f6e207479706560901b815250905060008282600060018482805480602002602001604051908101604052809291908181526020016000905b828210156101be578382906000526020600020018054610131906107cd565b80601f016020809104026020016040519081016040528092919081815260200182805461015d906107cd565b80156101aa5780601f1061017f576101008083540402835291602001916101aa565b820191906000526020600020905b81548152906001019060200180831161018d57829003601f168201915b505050505081526020019060010190610112565b5050505092508180546101d0906107cd565b80601f01602080910402602001604051908101604052809291908181526020018280546101fc906107cd565b80156102495780601f1061021e57610100808354040283529160200191610249565b820191906000526020600020905b81548152906001019060200180831161022c57829003601f168201915b50505050509150975097509750975097505050509295509295909350565b604080516000808252602082019092528190816102a6565b604080518082019091526060808252602082015281526020019060019003908161027f5790505b5090506102b48484836102bc565b949350505050565b60008060008585856040516020016102d693929190610808565b60408051601f19818403018152908290528051909250906020818382860160006103e8600019f161030657600080fd5b51979650505050505050565b634e487b7160e01b600052604160045260246000fd5b6040516060810167ffffffffffffffff8111828210171561034b5761034b610312565b60405290565b604051601f8201601f1916810167ffffffffffffffff8111828210171561037a5761037a610312565b604052919050565b600067ffffffffffffffff82111561039c5761039c610312565b5060051b60200190565b803563ffffffff811681146103ba57600080fd5b919050565b600067ffffffffffffffff8311156103d9576103d9610312565b6103ec601f8401601f1916602001610351565b905082815283838301111561040057600080fd5b828260208301376000602084830101529392505050565b600082601f83011261042857600080fd5b610437838335602085016103bf565b9392505050565b600082601f83011261044f57600080fd5b8135602061046461045f83610382565b610351565b82815260059290921b8401810191818101908684111561048357600080fd5b8286015b848110156104c357803567ffffffffffffffff8111156104a75760008081fd5b6104b58986838b0101610417565b845250918301918301610487565b509695505050505050565b600080604083850312156104e157600080fd5b823567ffffffffffffffff808211156104f957600080fd5b818501915085601f83011261050d57600080fd5b8135602061051d61045f83610382565b82815260059290921b8401810191818101908984111561053c57600080fd5b8286015b8481101561064e5780358681111561055757600080fd5b87016060818d03601f1901121561056d57600080fd5b610575610328565b6105808683016103a6565b815260408201358881111561059457600080fd5b8201603f81018e136105a557600080fd5b6105b68e88830135604084016103bf565b87830152506060820135888111156105cd57600080fd5b8083019250508c603f8301126105e257600080fd5b858201356105f261045f82610382565b81815260059190911b830160400190878101908f83111561061257600080fd5b6040850194505b828510156106395761062a856103a6565b82529388019390880190610619565b60408401525050845250918301918301610540565b509650508601359250508082111561066557600080fd5b506106728582860161043e565b9150509250929050565b6000815180845260005b818110156106a257602081850181015186830182015201610686565b818111156106b4576000602083870101525b50601f01601f19169290920160200192915050565b60a0815260006106dc60a083018861067c565b6020838203818501526106ef828961067c565b915083820360408501528187518084528284019150828160051b850101838a0160005b8381101561074057601f1987840301855261072e83835161067c565b94860194925090850190600101610712565b50508681036060880152610754818a61067c565b95505050505050610769608083018415159052565b9695505050505050565b6000806040838503121561078657600080fd5b823567ffffffffffffffff8082111561079e57600080fd5b6107aa86838701610417565b935060208501359150808211156107c057600080fd5b5061067285828601610417565b600181811c908216806107e157607f821691505b6020821081141561080257634e487b7160e01b600052602260045260246000fd5b50919050565b60608152600061081b606083018661067c565b60208382038185015261082e828761067c565b91506040848303818601528286518085528385019150838160051b86010184890160005b838110156108a257878303601f19018552815180518785526108768886018261067c565b91890151858303868b015291905061088e818361067c565b968901969450505090860190600101610852565b50909b9a505050505050505050505056fea264697066735822122035da2ee79319d441d7fbe78fea2e2f89ade1a191a99a3ab42ffd5fda370d630a64736f6c634300080b0033"; + const GET_I64_BYTE_CODE: &str = "608060405234801561001057600080fd5b50610a3f806100206000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063e256184614610046578063ed043e0f14610073578063f5e19bc0146100a0575b600080fd5b610059610054366004610577565b6100b3565b60405161006a959493929190610772565b60405180910390f35b61008661008136600461081c565b61028c565b60408051921515835260079190910b60208301520161006a565b6100866100ae3660046108c9565b6102f6565b6060806060806000806040518060400160405280600b81526020016a3232b9b1b934b83a34b7b760a91b815250905060006040518060400160405280600e81526020016d617373657274696f6e207479706560901b815250905060008282600060018482805480602002602001604051908101604052809291908181526020016000905b828210156101e357838290600052602060002001805461015690610923565b80601f016020809104026020016040519081016040528092919081815260200182805461018290610923565b80156101cf5780601f106101a4576101008083540402835291602001916101cf565b820191906000526020600020905b8154815290600101906020018083116101b257829003601f168201915b505050505081526020019060010190610137565b5050505092508180546101f590610923565b80601f016020809104026020016040519081016040528092919081815260200182805461022190610923565b801561026e5780601f106102435761010080835404028352916020019161026e565b820191906000526020600020905b81548152906001019060200180831161025157829003601f168201915b50505050509150975097509750975097505050509295509295909350565b6040805160008082526020820190925281908190816102cd565b60408051808201909152606080825260208201528152602001906001900390816102a65790505b5090506102db878783610351565b50506102e8858583610351565b925092505094509492505050565b604080516000808252602082019092528190819081610337565b60408051808201909152606080825260208201528152602001906001900390816103105790505b509050610345858583610351565b92509250509250929050565b600080600080600087878760405160200161036e9392919061095e565b60408051601f198184030181528282528051909350919081836020860160006103e8600019f161039d57600080fd5b8051602082015160409283019092529a909950975050505050505050565b634e487b7160e01b600052604160045260246000fd5b6040516060810167ffffffffffffffff811182821017156103f4576103f46103bb565b60405290565b604051601f8201601f1916810167ffffffffffffffff81118282101715610423576104236103bb565b604052919050565b600067ffffffffffffffff821115610445576104456103bb565b5060051b60200190565b803563ffffffff8116811461046357600080fd5b919050565b600067ffffffffffffffff831115610482576104826103bb565b610495601f8401601f19166020016103fa565b90508281528383830111156104a957600080fd5b828260208301376000602084830101529392505050565b600082601f8301126104d157600080fd5b6104e083833560208501610468565b9392505050565b600082601f8301126104f857600080fd5b8135602061050d6105088361042b565b6103fa565b82815260059290921b8401810191818101908684111561052c57600080fd5b8286015b8481101561056c57803567ffffffffffffffff8111156105505760008081fd5b61055e8986838b01016104c0565b845250918301918301610530565b509695505050505050565b6000806040838503121561058a57600080fd5b823567ffffffffffffffff808211156105a257600080fd5b818501915085601f8301126105b657600080fd5b813560206105c66105088361042b565b82815260059290921b840181019181810190898411156105e557600080fd5b8286015b848110156106f75780358681111561060057600080fd5b87016060818d03601f1901121561061657600080fd5b61061e6103d1565b61062986830161044f565b815260408201358881111561063d57600080fd5b8201603f81018e1361064e57600080fd5b61065f8e8883013560408401610468565b878301525060608201358881111561067657600080fd5b8083019250508c603f83011261068b57600080fd5b8582013561069b6105088261042b565b81815260059190911b830160400190878101908f8311156106bb57600080fd5b6040850194505b828510156106e2576106d38561044f565b825293880193908801906106c2565b604084015250508452509183019183016105e9565b509650508601359250508082111561070e57600080fd5b5061071b858286016104e7565b9150509250929050565b6000815180845260005b8181101561074b5760208185018101518683018201520161072f565b8181111561075d576000602083870101525b50601f01601f19169290920160200192915050565b60a08152600061078560a0830188610725565b6020838203818501526107988289610725565b915083820360408501528187518084528284019150828160051b850101838a0160005b838110156107e957601f198784030185526107d7838351610725565b948601949250908501906001016107bb565b505086810360608801526107fd818a610725565b95505050505050610812608083018415159052565b9695505050505050565b6000806000806080858703121561083257600080fd5b843567ffffffffffffffff8082111561084a57600080fd5b610856888389016104c0565b9550602087013591508082111561086c57600080fd5b610878888389016104c0565b9450604087013591508082111561088e57600080fd5b61089a888389016104c0565b935060608701359150808211156108b057600080fd5b506108bd878288016104c0565b91505092959194509250565b600080604083850312156108dc57600080fd5b823567ffffffffffffffff808211156108f457600080fd5b610900868387016104c0565b9350602085013591508082111561091657600080fd5b5061071b858286016104c0565b600181811c9082168061093757607f821691505b6020821081141561095857634e487b7160e01b600052602260045260246000fd5b50919050565b6060815260006109716060830186610725565b6020838203818501526109848287610725565b91506040848303818601528286518085528385019150838160051b86010184890160005b838110156109f857878303601f19018552815180518785526109cc88860182610725565b91890151858303868b01529190506109e48183610725565b9689019694505050908601906001016109a8565b50909b9a505050505050505050505056fea2646970667358221220dc347f537bd4447b1735029849707e20da3e7d2b936a4d52101bb4c795e2cb9e64736f6c634300080b0033"; - const GET_BOOL_BYTE_CODE: &str = "608060405234801561001057600080fd5b506108e6806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063e25618461461003b578063fe59859114610068575b600080fd5b61004e6100493660046104cb565b61008b565b60405161005f9594939291906106c6565b60405180910390f35b61007b610076366004610770565b610264565b604051901515815260200161005f565b6060806060806000806040518060400160405280600b81526020016a3232b9b1b934b83a34b7b760a91b815250905060006040518060400160405280600e81526020016d617373657274696f6e207479706560901b815250905060008282600060018482805480602002602001604051908101604052809291908181526020016000905b828210156101bb57838290600052602060002001805461012e906107ca565b80601f016020809104026020016040519081016040528092919081815260200182805461015a906107ca565b80156101a75780601f1061017c576101008083540402835291602001916101a7565b820191906000526020600020905b81548152906001019060200180831161018a57829003601f168201915b50505050508152602001906001019061010f565b5050505092508180546101cd906107ca565b80601f01602080910402602001604051908101604052809291908181526020018280546101f9906107ca565b80156102465780601f1061021b57610100808354040283529160200191610246565b820191906000526020600020905b81548152906001019060200180831161022957829003601f168201915b50505050509150975097509750975097505050509295509295909350565b604080516000808252602082019092528190816102a3565b604080518082019091526060808252602082015281526020019060019003908161027c5790505b5090506102b18484836102b9565b949350505050565b60008060008585856040516020016102d393929190610805565b60408051601f19818403018152908290528051909250906020818382860160006103e9600019f161030357600080fd5b51979650505050505050565b634e487b7160e01b600052604160045260246000fd5b6040516060810167ffffffffffffffff811182821017156103485761034861030f565b60405290565b604051601f8201601f1916810167ffffffffffffffff811182821017156103775761037761030f565b604052919050565b600067ffffffffffffffff8211156103995761039961030f565b5060051b60200190565b803563ffffffff811681146103b757600080fd5b919050565b600067ffffffffffffffff8311156103d6576103d661030f565b6103e9601f8401601f191660200161034e565b90508281528383830111156103fd57600080fd5b828260208301376000602084830101529392505050565b600082601f83011261042557600080fd5b610434838335602085016103bc565b9392505050565b600082601f83011261044c57600080fd5b8135602061046161045c8361037f565b61034e565b82815260059290921b8401810191818101908684111561048057600080fd5b8286015b848110156104c057803567ffffffffffffffff8111156104a45760008081fd5b6104b28986838b0101610414565b845250918301918301610484565b509695505050505050565b600080604083850312156104de57600080fd5b823567ffffffffffffffff808211156104f657600080fd5b818501915085601f83011261050a57600080fd5b8135602061051a61045c8361037f565b82815260059290921b8401810191818101908984111561053957600080fd5b8286015b8481101561064b5780358681111561055457600080fd5b87016060818d03601f1901121561056a57600080fd5b610572610325565b61057d8683016103a3565b815260408201358881111561059157600080fd5b8201603f81018e136105a257600080fd5b6105b38e88830135604084016103bc565b87830152506060820135888111156105ca57600080fd5b8083019250508c603f8301126105df57600080fd5b858201356105ef61045c8261037f565b81815260059190911b830160400190878101908f83111561060f57600080fd5b6040850194505b8285101561063657610627856103a3565b82529388019390880190610616565b6040840152505084525091830191830161053d565b509650508601359250508082111561066257600080fd5b5061066f8582860161043b565b9150509250929050565b6000815180845260005b8181101561069f57602081850181015186830182015201610683565b818111156106b1576000602083870101525b50601f01601f19169290920160200192915050565b60a0815260006106d960a0830188610679565b6020838203818501526106ec8289610679565b915083820360408501528187518084528284019150828160051b850101838a0160005b8381101561073d57601f1987840301855261072b838351610679565b9486019492509085019060010161070f565b50508681036060880152610751818a610679565b95505050505050610766608083018415159052565b9695505050505050565b6000806040838503121561078357600080fd5b823567ffffffffffffffff8082111561079b57600080fd5b6107a786838701610414565b935060208501359150808211156107bd57600080fd5b5061066f85828601610414565b600181811c908216806107de57607f821691505b602082108114156107ff57634e487b7160e01b600052602260045260246000fd5b50919050565b6060815260006108186060830186610679565b60208382038185015261082b8287610679565b91506040848303818601528286518085528385019150838160051b86010184890160005b8381101561089f57878303601f190185528151805187855261087388860182610679565b91890151858303868b015291905061088b8183610679565b96890196945050509086019060010161084f565b50909b9a505050505050505050505056fea2646970667358221220b2ad3ffe6885fdb9a48d32c730598d524106c0325bc62d87075c4ad4d4a5801464736f6c634300080b0033"; + // GetBool.sol bytecode + const GET_BOOL_BYTE_CODE: &str = "608060405234801561001057600080fd5b50610a38806100206000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c80637083d8ec14610046578063e256184614610075578063fe59859114610099575b600080fd5b6100596100543660046104a3565b6100ac565b6040805192151583529015156020830152015b60405180910390f35b61008861008336600461061d565b610116565b60405161006c959493929190610818565b6100596100a73660046108c2565b6102ef565b6040805160008082526020820190925281908190816100ed565b60408051808201909152606080825260208201528152602001906001900390816100c65790505b5090506100fb87878361034a565b505061010885858361034a565b925092505094509492505050565b6060806060806000806040518060400160405280600b81526020016a3232b9b1b934b83a34b7b760a91b815250905060006040518060400160405280600e81526020016d617373657274696f6e207479706560901b815250905060008282600060018482805480602002602001604051908101604052809291908181526020016000905b828210156102465783829060005260206000200180546101b99061091c565b80601f01602080910402602001604051908101604052809291908181526020018280546101e59061091c565b80156102325780601f1061020757610100808354040283529160200191610232565b820191906000526020600020905b81548152906001019060200180831161021557829003601f168201915b50505050508152602001906001019061019a565b5050505092508180546102589061091c565b80601f01602080910402602001604051908101604052809291908181526020018280546102849061091c565b80156102d15780601f106102a6576101008083540402835291602001916102d1565b820191906000526020600020905b8154815290600101906020018083116102b457829003601f168201915b50505050509150975097509750975097505050509295509295909350565b604080516000808252602082019092528190819081610330565b60408051808201909152606080825260208201528152602001906001900390816103095790505b50905061033e85858361034a565b92509250509250929050565b600080600080600087878760405160200161036793929190610957565b60408051601f198184030181528282528051909350919081836020860160006103e9600019f161039657600080fd5b8051602082015160409283019092529a909950975050505050505050565b634e487b7160e01b600052604160045260246000fd5b6040516060810167ffffffffffffffff811182821017156103ed576103ed6103b4565b60405290565b604051601f8201601f1916810167ffffffffffffffff8111828210171561041c5761041c6103b4565b604052919050565b600067ffffffffffffffff83111561043e5761043e6103b4565b610451601f8401601f19166020016103f3565b905082815283838301111561046557600080fd5b828260208301376000602084830101529392505050565b600082601f83011261048d57600080fd5b61049c83833560208501610424565b9392505050565b600080600080608085870312156104b957600080fd5b843567ffffffffffffffff808211156104d157600080fd5b6104dd8883890161047c565b955060208701359150808211156104f357600080fd5b6104ff8883890161047c565b9450604087013591508082111561051557600080fd5b6105218883890161047c565b9350606087013591508082111561053757600080fd5b506105448782880161047c565b91505092959194509250565b600067ffffffffffffffff82111561056a5761056a6103b4565b5060051b60200190565b803563ffffffff8116811461058857600080fd5b919050565b600082601f83011261059e57600080fd5b813560206105b36105ae83610550565b6103f3565b82815260059290921b840181019181810190868411156105d257600080fd5b8286015b8481101561061257803567ffffffffffffffff8111156105f65760008081fd5b6106048986838b010161047c565b8452509183019183016105d6565b509695505050505050565b6000806040838503121561063057600080fd5b823567ffffffffffffffff8082111561064857600080fd5b818501915085601f83011261065c57600080fd5b8135602061066c6105ae83610550565b82815260059290921b8401810191818101908984111561068b57600080fd5b8286015b8481101561079d578035868111156106a657600080fd5b87016060818d03601f190112156106bc57600080fd5b6106c46103ca565b6106cf868301610574565b81526040820135888111156106e357600080fd5b8201603f81018e136106f457600080fd5b6107058e8883013560408401610424565b878301525060608201358881111561071c57600080fd5b8083019250508c603f83011261073157600080fd5b858201356107416105ae82610550565b81815260059190911b830160400190878101908f83111561076157600080fd5b6040850194505b828510156107885761077985610574565b82529388019390880190610768565b6040840152505084525091830191830161068f565b50965050860135925050808211156107b457600080fd5b506107c18582860161058d565b9150509250929050565b6000815180845260005b818110156107f1576020818501810151868301820152016107d5565b81811115610803576000602083870101525b50601f01601f19169290920160200192915050565b60a08152600061082b60a08301886107cb565b60208382038185015261083e82896107cb565b915083820360408501528187518084528284019150828160051b850101838a0160005b8381101561088f57601f1987840301855261087d8383516107cb565b94860194925090850190600101610861565b505086810360608801526108a3818a6107cb565b955050505050506108b8608083018415159052565b9695505050505050565b600080604083850312156108d557600080fd5b823567ffffffffffffffff808211156108ed57600080fd5b6108f98683870161047c565b9350602085013591508082111561090f57600080fd5b506107c18582860161047c565b600181811c9082168061093057607f821691505b6020821081141561095157634e487b7160e01b600052602260045260246000fd5b50919050565b60608152600061096a60608301866107cb565b60208382038185015261097d82876107cb565b91506040848303818601528286518085528385019150838160051b86010184890160005b838110156109f157878303601f19018552815180518785526109c5888601826107cb565b91890151858303868b01529190506109dd81836107cb565b9689019694505050908601906001016109a1565b50909b9a505050505050505050505056fea2646970667358221220d32b94fab7696bf8cf3fc9b2184f1a396acbf4974cf49a325d576a241e12569564736f6c634300080b0033"; #[test] pub fn test_to_hex() { // given + let text = "test"; let byte_code = hex::decode(TO_HEX_BYTE_CODE).unwrap(); let input_data = - prepare_function_call_input("8876183c", encode(&[Token::String("test".to_string())])) + prepare_function_call_input("8876183c", encode(&[Token::String(text.to_string())])) .unwrap(); let (_, return_data) = execute_smart_contract(byte_code, input_data); - let types = vec![ethabi::ParamType::String]; + let types = vec![ethabi::ParamType::Bool, ethabi::ParamType::String]; // when let decoded = ethabi::decode(&types, &return_data).unwrap(); // then - assert_eq!( - "0x".to_owned() + &hex::encode("test"), - decoded[0].clone().into_string().unwrap() - ); + assert_eq!(true, decoded[0].clone().into_bool().unwrap()); + assert_eq!("0x".to_owned() + &hex::encode(text), decoded[1].clone().into_string().unwrap()); } #[test] @@ -142,30 +142,132 @@ pub mod dynamic_assertion_test { let byte_code = hex::decode(GET_I64_BYTE_CODE).unwrap(); let input_data = prepare_function_call_input("f5e19bc0", encode(&[Token::String("http://localhost:19530/2/users/by/username/twitterdev?user.fields=public_metrics".to_string()), Token::String("/data/public_metrics/followers_count".to_string())])).unwrap(); let (_, return_data) = execute_smart_contract(byte_code, input_data); - let types = vec![ethabi::ParamType::Int(2)]; + let types = vec![ethabi::ParamType::Bool, ethabi::ParamType::Int(2)]; + + // when + let decoded = ethabi::decode(&types, &return_data).unwrap(); + + // then + assert_eq!(true, decoded[0].clone().into_bool().unwrap()); + assert_eq!(U256::from(100), decoded[1].clone().into_int().unwrap()); + } + + #[test] + pub fn test_get_i64_with_failure() { + // given + let byte_code = hex::decode(GET_I64_BYTE_CODE).unwrap(); + let input_data = prepare_function_call_input( + "f5e19bc0", + encode(&[ + Token::String( + "http://localhost:1/2/users/by/username/twitterdev?user.fields=public_metrics" + .to_string(), + ), + Token::String("/data/public_metrics/followers_count".to_string()), + ]), + ) + .unwrap(); + let (_, return_data) = execute_smart_contract(byte_code, input_data); + let types = vec![ethabi::ParamType::Bool, ethabi::ParamType::Int(2)]; // when let decoded = ethabi::decode(&types, &return_data).unwrap(); // then - assert_eq!(U256::from(100), decoded[0].clone().into_int().unwrap()); + assert_eq!(false, decoded[0].clone().into_bool().unwrap()); + assert_eq!(U256::from(0), decoded[1].clone().into_int().unwrap()); } + //we want to check here that execution is not interrupted by http error #[test] - pub fn test_get_bool() { + pub fn test_get_i64_returns_second_error_in_case_of_first_request_failure() { + run(19532).unwrap(); + + // given + let byte_code = hex::decode(GET_I64_BYTE_CODE).unwrap(); + let input_data = prepare_function_call_input("ed043e0f", + encode( + &[ + // this one uses different port so service is unavailable + Token::String("http://localhost:1/2/users/by/username/twitterdev?user.fields=public_metrics".to_string()), + Token::String("/data/public_metrics/followers_count".to_string()), + Token::String("http://localhost:19532/2/users/by/username/twitterdev?user.fields=public_metrics".to_string()), + Token::String("/data/public_metrics/followers_count".to_string()) + ] + ) + ).unwrap(); + let (_, return_data) = execute_smart_contract(byte_code, input_data); + let types = vec![ethabi::ParamType::Bool, ethabi::ParamType::Int(2)]; + + // when + let decoded = ethabi::decode(&types, &return_data).unwrap(); + + // then + assert_eq!(true, decoded[0].clone().into_bool().unwrap()); + assert_eq!(U256::from(100), decoded[1].clone().into_int().unwrap()); + } + + #[test] + pub fn test_get_bool_with_success_and_true_result() { run(19531).unwrap(); // given let byte_code = hex::decode(GET_BOOL_BYTE_CODE).unwrap(); let input_data = prepare_function_call_input("fe598591", encode(&[Token::String("http://localhost:19531/events/does-user-joined-evm-campaign?account=0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d".to_string()), Token::String("/hasJoined".to_string())])).unwrap(); let (_, return_data) = execute_smart_contract(byte_code, input_data); - let types = vec![ethabi::ParamType::Bool]; + let types = vec![ethabi::ParamType::Bool, ethabi::ParamType::Bool]; + + // when + let decoded = ethabi::decode(&types, &return_data).unwrap(); + + // then + assert_eq!(true, decoded[0].clone().into_bool().unwrap()); + assert_eq!(true, decoded[1].clone().into_bool().unwrap()); + } + + #[test] + pub fn test_get_bool_with_failure() { + // given + let byte_code = hex::decode(GET_BOOL_BYTE_CODE).unwrap(); + let input_data = prepare_function_call_input("fe598591", encode(&[Token::String("http://localhost:1/events/does-user-joined-evm-campaign?account=0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d".to_string()), Token::String("/hasJoined".to_string())])).unwrap(); + let (_, return_data) = execute_smart_contract(byte_code, input_data); + let types = vec![ethabi::ParamType::Bool, ethabi::ParamType::Bool]; + + // when + let decoded = ethabi::decode(&types, &return_data).unwrap(); + + // then + assert_eq!(false, decoded[0].clone().into_bool().unwrap()); + assert_eq!(false, decoded[1].clone().into_bool().unwrap()); + } + + //we want to check here that execution is not interrupted by http error + #[test] + pub fn test_get_bool_returns_second_error_in_case_of_first_request_failure() { + run(19533).unwrap(); + + // given + let byte_code = hex::decode(GET_BOOL_BYTE_CODE).unwrap(); + let input_data = prepare_function_call_input("7083d8ec", + encode( + &[ + // this one uses different port so service is unavailable + Token::String("http://localhost:1/events/does-user-joined-evm-campaign?account=0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d".to_string()), + Token::String("/hasJoined".to_string()), + Token::String("http://localhost:19533/events/does-user-joined-evm-campaign?account=0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d".to_string()), + Token::String("/hasJoined".to_string()) + ] + ) + ).unwrap(); + let (_, return_data) = execute_smart_contract(byte_code, input_data); + let types = vec![ethabi::ParamType::Bool, ethabi::ParamType::Bool]; // when let decoded = ethabi::decode(&types, &return_data).unwrap(); // then assert_eq!(true, decoded[0].clone().into_bool().unwrap()); + assert_eq!(true, decoded[1].clone().into_bool().unwrap()); } } diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/repository.rs b/tee-worker/litentry/core/assertion-build/src/dynamic/repository.rs index 91d6cbe322..15551f3e18 100644 --- a/tee-worker/litentry/core/assertion-build/src/dynamic/repository.rs +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/repository.rs @@ -49,7 +49,7 @@ impl InMemorySmartContractRepo { map.insert( hash(0), ( - hex::decode("608060405234801561001057600080fd5b50610af2806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063e256184614610030575b600080fd5b61004361003e366004610661565b61005d565b60405161005495949392919061085f565b60405180910390f35b60608060608060008060405180608001604052806045815260200161098460459139604080518082018252601b81527f4261736963204964656e7469747920566572696669636174696f6e000000000060208083019190915260008054600181018255818052845160c08101909552608180865295965092947f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e56390930193909290916109c990830139805161011993925060209091019061041e565b506040518060a0016040528060738152602001610a4a6073913980516101479160019160209091019061041e565b5060008080805b8c518110156101c5576101798d828151811061016c5761016c610909565b6020026020010151610351565b1561018757600191506101b3565b6101a98d828151811061019c5761019c610909565b6020026020010151610380565b156101b357600192505b806101bd8161091f565b91505061014e565b508080156101d05750815b92508484600060018682805480602002602001604051908101604052809291908181526020016000905b828210156102a657838290600052602060002001805461021990610948565b80601f016020809104026020016040519081016040528092919081815260200182805461024590610948565b80156102925780601f1061026757610100808354040283529160200191610292565b820191906000526020600020905b81548152906001019060200180831161027557829003601f168201915b5050505050815260200190600101906101fa565b5050505092508180546102b890610948565b80601f01602080910402602001604051908101604052809291908181526020018280546102e490610948565b80156103315780601f1061030657610100808354040283529160200191610331565b820191906000526020600020905b81548152906001019060200180831161031457829003601f168201915b505050505091509950995099509950995050505050509295509295909350565b600061035c826103a9565b8061036b575061036b826103b6565b8061037a575061037a826103c3565b92915050565b600061038b826103d0565b8061039a575061039a826103dd565b8061037a575061037a826103ea565b600061037a8260006103f3565b600061037a8260016103f3565b600061037a8260026103f3565b600061037a8260036103f3565b600061037a8260046103f3565b600061037a8260055b60008163ffffffff16836000015163ffffffff1614156104155750600161037a565b50600092915050565b82805461042a90610948565b90600052602060002090601f01602090048101928261044c5760008555610492565b82601f1061046557805160ff1916838001178555610492565b82800160010185558215610492579182015b82811115610492578251825591602001919060010190610477565b5061049e9291506104a2565b5090565b5b8082111561049e57600081556001016104a3565b634e487b7160e01b600052604160045260246000fd5b6040516060810167ffffffffffffffff811182821017156104f0576104f06104b7565b60405290565b604051601f8201601f1916810167ffffffffffffffff8111828210171561051f5761051f6104b7565b604052919050565b600067ffffffffffffffff821115610541576105416104b7565b5060051b60200190565b803563ffffffff8116811461055f57600080fd5b919050565b600067ffffffffffffffff83111561057e5761057e6104b7565b610591601f8401601f19166020016104f6565b90508281528383830111156105a557600080fd5b828260208301376000602084830101529392505050565b600082601f8301126105cd57600080fd5b813560206105e26105dd83610527565b6104f6565b82815260059290921b8401810191818101908684111561060157600080fd5b8286015b8481101561065657803567ffffffffffffffff8111156106255760008081fd5b8701603f810189136106375760008081fd5b610648898683013560408401610564565b845250918301918301610605565b509695505050505050565b6000806040838503121561067457600080fd5b823567ffffffffffffffff8082111561068c57600080fd5b818501915085601f8301126106a057600080fd5b813560206106b06105dd83610527565b82815260059290921b840181019181810190898411156106cf57600080fd5b8286015b848110156107e2578035868111156106ea57600080fd5b87016060818d03601f1901121561070057600080fd5b6107086104cd565b61071386830161054b565b815260408201358881111561072757600080fd5b8201603f81018e1361073857600080fd5b6107498e8883013560408401610564565b878301525060608201358881111561076057600080fd5b8083019250508c603f83011261077557600080fd5b858201356107856105dd82610527565b81815260059190911b83018701870190878101908f8311156107a657600080fd5b6040850194505b828510156107cd576107be8561054b565b825293880193908801906107ad565b604084015250508452509183019183016106d3565b50965050860135925050808211156107f957600080fd5b50610806858286016105bc565b9150509250929050565b60008151808452602060005b8281101561083757848101820151868201830152810161081c565b828111156108485760008284880101525b5080601f19601f8401168601019250505092915050565b60a08152600061087260a0830188610810565b6020838203818501526108858289610810565b915083820360408501528187518084528284019150828160051b850101838a0160005b838110156108d657601f198784030185526108c4838351610810565b948601949250908501906001016108a8565b505086810360608801526108ea818a610810565b955050505050506108ff608083018415159052565b9695505050505050565b634e487b7160e01b600052603260045260246000fd5b600060001982141561094157634e487b7160e01b600052601160045260246000fd5b5060010190565b600181811c9082168061095c57607f821691505b6020821081141561097d57634e487b7160e01b600052602260045260246000fd5b5091905056fe596f75277665206964656e746966696564206174206c65617374206f6e65206163636f756e742f6164647265737320696e20626f7468205765623220616e6420576562332e7b22616e64223a205b7b2022737263223a2022246861735f776562325f6163636f756e74222c20226f70223a20223d3d222c2022647374223a20227472756522207d2c207b2022737263223a2022246861735f776562335f6163636f756e74222c20226f70223a20223d3d222c2022647374223a20227472756522207d205d207d68747470733a2f2f7261772e67697468756275736572636f6e74656e742e636f6d2f6c6974656e7472792f76632d6a736f6e736368656d612f6d61696e2f646973742f736368656d61732f312d62617369632d6964656e746974792d766572696669636174696f6e2f312d302d302e6a736f6ea26469706673582212201c295fa832769ae2bab11a8c0dc35724f60650f2710135a9453d55ffe206b1e664736f6c634300080b0033").unwrap(), + hex::decode("608060405234801561001057600080fd5b50610af2806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063e256184614610030575b600080fd5b61004361003e366004610661565b61005d565b60405161005495949392919061085f565b60405180910390f35b60608060608060008060405180608001604052806045815260200161098460459139604080518082018252601b81527f4261736963204964656e7469747920566572696669636174696f6e000000000060208083019190915260008054600181018255818052845160c08101909552608180865295965092947f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e56390930193909290916109c990830139805161011993925060209091019061041e565b506040518060a0016040528060738152602001610a4a6073913980516101479160019160209091019061041e565b5060008080805b8c518110156101c5576101798d828151811061016c5761016c610909565b6020026020010151610351565b1561018757600191506101b3565b6101a98d828151811061019c5761019c610909565b6020026020010151610380565b156101b357600192505b806101bd8161091f565b91505061014e565b508080156101d05750815b92508484600060018682805480602002602001604051908101604052809291908181526020016000905b828210156102a657838290600052602060002001805461021990610948565b80601f016020809104026020016040519081016040528092919081815260200182805461024590610948565b80156102925780601f1061026757610100808354040283529160200191610292565b820191906000526020600020905b81548152906001019060200180831161027557829003601f168201915b5050505050815260200190600101906101fa565b5050505092508180546102b890610948565b80601f01602080910402602001604051908101604052809291908181526020018280546102e490610948565b80156103315780601f1061030657610100808354040283529160200191610331565b820191906000526020600020905b81548152906001019060200180831161031457829003601f168201915b505050505091509950995099509950995050505050509295509295909350565b600061035c826103a9565b8061036b575061036b826103b6565b8061037a575061037a826103c3565b92915050565b600061038b826103d0565b8061039a575061039a826103dd565b8061037a575061037a826103ea565b600061037a8260006103f3565b600061037a8260016103f3565b600061037a8260026103f3565b600061037a8260036103f3565b600061037a8260046103f3565b600061037a8260055b60008163ffffffff16836000015163ffffffff1614156104155750600161037a565b50600092915050565b82805461042a90610948565b90600052602060002090601f01602090048101928261044c5760008555610492565b82601f1061046557805160ff1916838001178555610492565b82800160010185558215610492579182015b82811115610492578251825591602001919060010190610477565b5061049e9291506104a2565b5090565b5b8082111561049e57600081556001016104a3565b634e487b7160e01b600052604160045260246000fd5b6040516060810167ffffffffffffffff811182821017156104f0576104f06104b7565b60405290565b604051601f8201601f1916810167ffffffffffffffff8111828210171561051f5761051f6104b7565b604052919050565b600067ffffffffffffffff821115610541576105416104b7565b5060051b60200190565b803563ffffffff8116811461055f57600080fd5b919050565b600067ffffffffffffffff83111561057e5761057e6104b7565b610591601f8401601f19166020016104f6565b90508281528383830111156105a557600080fd5b828260208301376000602084830101529392505050565b600082601f8301126105cd57600080fd5b813560206105e26105dd83610527565b6104f6565b82815260059290921b8401810191818101908684111561060157600080fd5b8286015b8481101561065657803567ffffffffffffffff8111156106255760008081fd5b8701603f810189136106375760008081fd5b610648898683013560408401610564565b845250918301918301610605565b509695505050505050565b6000806040838503121561067457600080fd5b823567ffffffffffffffff8082111561068c57600080fd5b818501915085601f8301126106a057600080fd5b813560206106b06105dd83610527565b82815260059290921b840181019181810190898411156106cf57600080fd5b8286015b848110156107e2578035868111156106ea57600080fd5b87016060818d03601f1901121561070057600080fd5b6107086104cd565b61071386830161054b565b815260408201358881111561072757600080fd5b8201603f81018e1361073857600080fd5b6107498e8883013560408401610564565b878301525060608201358881111561076057600080fd5b8083019250508c603f83011261077557600080fd5b858201356107856105dd82610527565b81815260059190911b83018701870190878101908f8311156107a657600080fd5b6040850194505b828510156107cd576107be8561054b565b825293880193908801906107ad565b604084015250508452509183019183016106d3565b50965050860135925050808211156107f957600080fd5b50610806858286016105bc565b9150509250929050565b60008151808452602060005b8281101561083757848101820151868201830152810161081c565b828111156108485760008284880101525b5080601f19601f8401168601019250505092915050565b60a08152600061087260a0830188610810565b6020838203818501526108858289610810565b915083820360408501528187518084528284019150828160051b850101838a0160005b838110156108d657601f198784030185526108c4838351610810565b948601949250908501906001016108a8565b505086810360608801526108ea818a610810565b955050505050506108ff608083018415159052565b9695505050505050565b634e487b7160e01b600052603260045260246000fd5b600060001982141561094157634e487b7160e01b600052601160045260246000fd5b5060010190565b600181811c9082168061095c57607f821691505b6020821081141561097d57634e487b7160e01b600052602260045260246000fd5b5091905056fe596f75277665206964656e746966696564206174206c65617374206f6e65206163636f756e742f6164647265737320696e20626f7468205765623220616e6420576562332e7b22616e64223a205b7b2022737263223a2022246861735f776562325f6163636f756e74222c20226f70223a20223d3d222c2022647374223a20227472756522207d2c207b2022737263223a2022246861735f776562335f6163636f756e74222c20226f70223a20223d3d222c2022647374223a20227472756522207d205d207d68747470733a2f2f7261772e67697468756275736572636f6e74656e742e636f6d2f6c6974656e7472792f76632d6a736f6e736368656d612f6d61696e2f646973742f736368656d61732f312d62617369632d6964656e746974792d766572696669636174696f6e2f312d302d302e6a736f6ea264697066735822122008b51c7962c3c5639c7c2aac2c98e97f666aa49e961a5e962f030f4ac4a9a47d64736f6c634300080b0033").unwrap(), vec![] ) ); @@ -57,7 +57,7 @@ impl InMemorySmartContractRepo { map.insert( hash(1), ( - hex::decode("608060405234801561001057600080fd5b50610d41806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063e256184614610030575b600080fd5b61004361003e366004610777565b61005d565b604051610054959493929190610981565b60405180910390f35b6060806060806000806040518060c0016040528060868152602001610c0f60869139604080518082018252601c81527f49444875622045564d2056657273696f6e204561726c7920426972640000000060208083019190915260008054600181018255818052845160608101909552603380865295965092947f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e5639093019390929091610c95908301398051610119939250602090910190610534565b506040518060a0016040528060758152602001610b9a60759139805161014791600191602090910190610534565b506000805b8a51811015610263576101778b828151811061016a5761016a610a2b565b60200260200101516103e1565b156102515760006101a48c838151811061019357610193610a2b565b602002602001015160200151610410565b905060006101ca604051806080016040528060448152602001610cc8604491398361045b565b604080518082018252600a8152690bda185cd29bda5b995960b21b6020808301919091528251600080825291810190935292935091908161022d565b60408051808201909152606080825260208201528152602001906001900390816102065790505b50905061023b83838361048a565b9550851561024c5750505050610263565b505050505b8061025b81610a41565b91505061014c565b508282600060018482805480602002602001604051908101604052809291908181526020016000905b828210156103385783829060005260206000200180546102ab90610a6a565b80601f01602080910402602001604051908101604052809291908181526020018280546102d790610a6a565b80156103245780601f106102f957610100808354040283529160200191610324565b820191906000526020600020905b81548152906001019060200180831161030757829003601f168201915b50505050508152602001906001019061028c565b50505050925081805461034a90610a6a565b80601f016020809104026020016040519081016040528092919081815260200182805461037690610a6a565b80156103c35780601f10610398576101008083540402835291602001916103c3565b820191906000526020600020905b8154815290600101906020018083116103a657829003601f168201915b50505050509150975097509750975097505050509295509295909350565b60006103ec826104e7565b806103fb57506103fb826104f4565b8061040a575061040a82610501565b92915050565b60606000826040516020016104259190610aa5565b60408051601f1981840301815291905280519091506082838260208501600061041b600019f161045457600080fd5b5050919050565b606060008383604051602001610472929190610abf565b60408051808303601f19018152919052949350505050565b60008060008585856040516020016104a493929190610aee565b60408051601f19818403018152908290528051909250906020818382860160006103e9600019f16104d457600080fd5b6020810160405251979650505050505050565b600061040a82600361050a565b600061040a82600461050a565b600061040a8260055b60008163ffffffff16836000015163ffffffff16141561052c5750600161040a565b50600061040a565b82805461054090610a6a565b90600052602060002090601f01602090048101928261056257600085556105a8565b82601f1061057b57805160ff19168380011785556105a8565b828001600101855582156105a8579182015b828111156105a857825182559160200191906001019061058d565b506105b49291506105b8565b5090565b5b808211156105b457600081556001016105b9565b634e487b7160e01b600052604160045260246000fd5b6040516060810167ffffffffffffffff81118282101715610606576106066105cd565b60405290565b604051601f8201601f1916810167ffffffffffffffff81118282101715610635576106356105cd565b604052919050565b600067ffffffffffffffff821115610657576106576105cd565b5060051b60200190565b803563ffffffff8116811461067557600080fd5b919050565b600067ffffffffffffffff831115610694576106946105cd565b6106a7601f8401601f191660200161060c565b90508281528383830111156106bb57600080fd5b828260208301376000602084830101529392505050565b600082601f8301126106e357600080fd5b813560206106f86106f38361063d565b61060c565b82815260059290921b8401810191818101908684111561071757600080fd5b8286015b8481101561076c57803567ffffffffffffffff81111561073b5760008081fd5b8701603f8101891361074d5760008081fd5b61075e89868301356040840161067a565b84525091830191830161071b565b509695505050505050565b6000806040838503121561078a57600080fd5b823567ffffffffffffffff808211156107a257600080fd5b818501915085601f8301126107b657600080fd5b813560206107c66106f38361063d565b82815260059290921b840181019181810190898411156107e557600080fd5b8286015b848110156108f75780358681111561080057600080fd5b87016060818d03601f1901121561081657600080fd5b61081e6105e3565b610829868301610661565b815260408201358881111561083d57600080fd5b8201603f81018e1361084e57600080fd5b61085f8e888301356040840161067a565b878301525060608201358881111561087657600080fd5b8083019250508c603f83011261088b57600080fd5b8582013561089b6106f38261063d565b81815260059190911b830160400190878101908f8311156108bb57600080fd5b6040850194505b828510156108e2576108d385610661565b825293880193908801906108c2565b604084015250508452509183019183016107e9565b509650508601359250508082111561090e57600080fd5b5061091b858286016106d2565b9150509250929050565b60005b83811015610940578181015183820152602001610928565b8381111561094f576000848401525b50505050565b6000815180845261096d816020860160208601610925565b601f01601f19169290920160200192915050565b60a08152600061099460a0830188610955565b6020838203818501526109a78289610955565b915083820360408501528187518084528284019150828160051b850101838a0160005b838110156109f857601f198784030185526109e6838351610955565b948601949250908501906001016109ca565b50508681036060880152610a0c818a610955565b95505050505050610a21608083018415159052565b9695505050505050565b634e487b7160e01b600052603260045260246000fd5b6000600019821415610a6357634e487b7160e01b600052601160045260246000fd5b5060010190565b600181811c90821680610a7e57607f821691505b60208210811415610a9f57634e487b7160e01b600052602260045260246000fd5b50919050565b602081526000610ab86020830184610955565b9392505050565b60008351610ad1818460208801610925565b835190830190610ae5818360208801610925565b01949350505050565b606081526000610b016060830186610955565b602083820381850152610b148287610955565b91506040848303818601528286518085528385019150838160051b86010184890160005b83811015610b8857878303601f1901855281518051878552610b5c88860182610955565b91890151858303868b0152919050610b748183610955565b968901969450505090860190600101610b38565b50909b9a505050505050505050505056fe68747470733a2f2f7261772e67697468756275736572636f6e74656e742e636f6d2f6c6974656e7472792f76632d6a736f6e736368656d612f6d61696e2f646973742f736368656d61732f31322d69646875622d65766d2d76657273696f6e2d6561726c792d626972642f312d302d302e6a736f6e546865207573657220697320616e206561726c7920626972642075736572206f6620746865204964656e746974794875622045564d2076657273696f6e20616e64206861732067656e657261746564206174206c6561737420312063726564656e7469616c20647572696e672032303233204175672031347468207e2041756720323173742e7b2022737263223a2022246861735f6a6f696e6564222c20226f70223a20223d3d222c2022647374223a20227472756522207d687474703a2f2f6c6f63616c686f73743a31393532372f6576656e74732f646f65732d757365722d6a6f696e65642d65766d2d63616d706169676e3f6163636f756e743da26469706673582212206f2898c546b7b586d3e8172e5f011fc6d1d1f39f955ea5da2b58f62d9a332e2264736f6c634300080b0033").unwrap(), + hex::decode("608060405234801561001057600080fd5b50610d8b806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063e256184614610030575b600080fd5b61004361003e3660046107c1565b61005d565b6040516100549594939291906109cb565b60405180910390f35b6060806060806000806040518060c0016040528060868152602001610c5960869139604080518082018252601c81527f49444875622045564d2056657273696f6e204561726c7920426972640000000060208083019190915260008054600181018255818052845160608101909552603380865295965092947f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e5639093019390929091610cdf90830139805161011993925060209091019061057e565b506040518060a0016040528060758152602001610be46075913980516101479160019160209091019061057e565b506000805b8a51811015610289576101778b828151811061016a5761016a610a75565b6020026020010151610407565b15610277576000806101a58d848151811061019457610194610a75565b602002602001015160200151610436565b91509150811561026757816101bb575050610277565b60006101df604051806080016040528060448152602001610d126044913983610498565b604080518082018252600a8152690bda185cd29bda5b995960b21b60208083019190915282516000808252918101909352929350919081610242565b604080518082019091526060808252602082015281526020019060019003908161021b5790505b5090506000806102538585856104c7565b915091508115610261578098505b50505050505b8315610274575050610289565b50505b8061028181610a8b565b91505061014c565b508282600060018482805480602002602001604051908101604052809291908181526020016000905b8282101561035e5783829060005260206000200180546102d190610ab4565b80601f01602080910402602001604051908101604052809291908181526020018280546102fd90610ab4565b801561034a5780601f1061031f5761010080835404028352916020019161034a565b820191906000526020600020905b81548152906001019060200180831161032d57829003601f168201915b5050505050815260200190600101906102b2565b50505050925081805461037090610ab4565b80601f016020809104026020016040519081016040528092919081815260200182805461039c90610ab4565b80156103e95780601f106103be576101008083540402835291602001916103e9565b820191906000526020600020905b8154815290600101906020018083116103cc57829003601f168201915b50505050509150975097509750975097505050509295509295909350565b600061041282610531565b8061042157506104218261053e565b8061043057506104308261054b565b92915050565b6000606060008360405160200161044d9190610aef565b60408051601f1981840301815290829052805190925090611000818360208601600061041b600019f161047f57600080fd5b8094506040810193506110008101604052505050915091565b6060600083836040516020016104af929190610b09565b60408051808303601f19018152919052949350505050565b60008060008060008787876040516020016104e493929190610b38565b60408051601f198184030181528282528051909350919081836020860160006103e9600019f161051357600080fd5b8051602082015160409283019092529a909950975050505050505050565b6000610430826003610554565b6000610430826004610554565b60006104308260055b60008163ffffffff16836000015163ffffffff16141561057657506001610430565b506000610430565b82805461058a90610ab4565b90600052602060002090601f0160209004810192826105ac57600085556105f2565b82601f106105c557805160ff19168380011785556105f2565b828001600101855582156105f2579182015b828111156105f25782518255916020019190600101906105d7565b506105fe929150610602565b5090565b5b808211156105fe5760008155600101610603565b634e487b7160e01b600052604160045260246000fd5b6040516060810167ffffffffffffffff8111828210171561065057610650610617565b60405290565b604051601f8201601f1916810167ffffffffffffffff8111828210171561067f5761067f610617565b604052919050565b600067ffffffffffffffff8211156106a1576106a1610617565b5060051b60200190565b803563ffffffff811681146106bf57600080fd5b919050565b600067ffffffffffffffff8311156106de576106de610617565b6106f1601f8401601f1916602001610656565b905082815283838301111561070557600080fd5b828260208301376000602084830101529392505050565b600082601f83011261072d57600080fd5b8135602061074261073d83610687565b610656565b82815260059290921b8401810191818101908684111561076157600080fd5b8286015b848110156107b657803567ffffffffffffffff8111156107855760008081fd5b8701603f810189136107975760008081fd5b6107a88986830135604084016106c4565b845250918301918301610765565b509695505050505050565b600080604083850312156107d457600080fd5b823567ffffffffffffffff808211156107ec57600080fd5b818501915085601f83011261080057600080fd5b8135602061081061073d83610687565b82815260059290921b8401810191818101908984111561082f57600080fd5b8286015b848110156109415780358681111561084a57600080fd5b87016060818d03601f1901121561086057600080fd5b61086861062d565b6108738683016106ab565b815260408201358881111561088757600080fd5b8201603f81018e1361089857600080fd5b6108a98e88830135604084016106c4565b87830152506060820135888111156108c057600080fd5b8083019250508c603f8301126108d557600080fd5b858201356108e561073d82610687565b81815260059190911b830160400190878101908f83111561090557600080fd5b6040850194505b8285101561092c5761091d856106ab565b8252938801939088019061090c565b60408401525050845250918301918301610833565b509650508601359250508082111561095857600080fd5b506109658582860161071c565b9150509250929050565b60005b8381101561098a578181015183820152602001610972565b83811115610999576000848401525b50505050565b600081518084526109b781602086016020860161096f565b601f01601f19169290920160200192915050565b60a0815260006109de60a083018861099f565b6020838203818501526109f1828961099f565b915083820360408501528187518084528284019150828160051b850101838a0160005b83811015610a4257601f19878403018552610a3083835161099f565b94860194925090850190600101610a14565b50508681036060880152610a56818a61099f565b95505050505050610a6b608083018415159052565b9695505050505050565b634e487b7160e01b600052603260045260246000fd5b6000600019821415610aad57634e487b7160e01b600052601160045260246000fd5b5060010190565b600181811c90821680610ac857607f821691505b60208210811415610ae957634e487b7160e01b600052602260045260246000fd5b50919050565b602081526000610b02602083018461099f565b9392505050565b60008351610b1b81846020880161096f565b835190830190610b2f81836020880161096f565b01949350505050565b606081526000610b4b606083018661099f565b602083820381850152610b5e828761099f565b91506040848303818601528286518085528385019150838160051b86010184890160005b83811015610bd257878303601f1901855281518051878552610ba68886018261099f565b91890151858303868b0152919050610bbe818361099f565b968901969450505090860190600101610b82565b50909b9a505050505050505050505056fe68747470733a2f2f7261772e67697468756275736572636f6e74656e742e636f6d2f6c6974656e7472792f76632d6a736f6e736368656d612f6d61696e2f646973742f736368656d61732f31322d69646875622d65766d2d76657273696f6e2d6561726c792d626972642f312d302d302e6a736f6e546865207573657220697320616e206561726c7920626972642075736572206f6620746865204964656e746974794875622045564d2076657273696f6e20616e64206861732067656e657261746564206174206c6561737420312063726564656e7469616c20647572696e672032303233204175672031347468207e2041756720323173742e7b2022737263223a2022246861735f6a6f696e6564222c20226f70223a20223d3d222c2022647374223a20227472756522207d687474703a2f2f6c6f63616c686f73743a31393532372f6576656e74732f646f65732d757365722d6a6f696e65642d65766d2d63616d706169676e3f6163636f756e743da26469706673582212204f649e301bd283e006c1969af8be484a752224ee88424af5f91820ad5acb4e4464736f6c634300080b0033").unwrap(), vec![] ) ); @@ -65,7 +65,7 @@ impl InMemorySmartContractRepo { map.insert( hash(2), ( - hex::decode("608060405234801561001057600080fd5b506110ed806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063e256184614610030575b600080fd5b61004361003e366004610af6565b61005d565b604051610054959493929190610d00565b60405180910390f35b6060806060806000806040518060600160405280602e815260200161108a602e9139905060006040518060400160405280601781526020017f5477697474657220466f6c6c6f77657220416d6f756e7400000000000000000081525090506040518060a0016040528060738152602001610fde6073913980516100e8916001916020909101906108bc565b50600080805b8b518110156102a2576101198c828151811061010c5761010c610daa565b60200260200101516105f5565b1561029057600061015f6040518060600160405280602b8152602001610fb3602b91398e848151811061014e5761014e610daa565b602002602001015160200151610608565b905060006101a2826040518060400160405280601b81526020017f3f757365722e6669656c64733d7075626c69635f6d6574726963730000000000815250610608565b60408051600180825281830190925291925060009190816020015b60408051808201909152606080825260208201528152602001906001900390816101bd57905050905060405180604001604052806040518060400160405280600d81526020016c30baba3437b934bd30ba34b7b760991b81525081526020018f60008151811061022f5761022f610daa565b60200260200101518152508160008151811061024d5761024d610daa565b6020026020010181905250600061027d83604051806060016040528060248152602001610f586024913984610637565b90506102898187610dd6565b9550505050505b8061029a81610e27565b9150506100ee565b5060008060008360070b121580156102be575060018360070b13155b156102cf575060009050600161039a565b60018360070b1380156102e6575060648360070b13155b156102f7575060019050606461039a565b60648360070b13801561030f57506103e88360070b13155b156103215750606490506103e861039a565b6103e88360070b13801561033a57506127108360070b13155b1561034d57506103e8905061271061039a565b6127108360070b1380156103675750620186a08360070b13155b1561037b57506127109050620186a061039a565b620186a08360070b131561039a5750620186a09050677fffffffffffffff5b6001935060006103cd604051806060016040528060398152602001611051603991396103c88560070b610694565b610608565b90506103f181604051806060016040528060378152602001610f7c60379139610608565b9050610403816103c88460070b610694565b905061042e816040518060400160405280600781526020016622207d205d207d60c81b815250610608565b600080546001810182559080528151919250610473917f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e5639091019060208401906108bc565b508686600060018882805480602002602001604051908101604052809291908181526020016000905b828210156105485783829060005260206000200180546104bb90610e42565b80601f01602080910402602001604051908101604052809291908181526020018280546104e790610e42565b80156105345780601f1061050957610100808354040283529160200191610534565b820191906000526020600020905b81548152906001019060200180831161051757829003601f168201915b50505050508152602001906001019061049c565b50505050925081805461055a90610e42565b80601f016020809104026020016040519081016040528092919081815260200182805461058690610e42565b80156105d35780601f106105a8576101008083540402835291602001916105d3565b820191906000526020600020905b8154815290600101906020018083116105b657829003601f168201915b505050505091509b509b509b509b509b50505050505050509295509295909350565b6000610602826000610706565b92915050565b60606000838360405160200161061f929190610e7d565b60408051808303601f19018152919052949350505050565b600080600085858560405160200161065193929190610eac565b60408051601f19818403018152908290528051909250906020818382860160006103e8600019f161068157600080fd5b6020810160405251979650505050505050565b6060600082126106b357604051806020016040528060008152506106ce565b604051806040016040528060018152602001602d60f81b8152505b6106df6106da84610730565b610747565b6040516020016106f0929190610e7d565b6040516020818303038152906040529050919050565b60008163ffffffff16836000015163ffffffff16141561072857506001610602565b506000610602565b6000808212156107435781600003610602565b5090565b60606000610754836107e4565b600101905060008167ffffffffffffffff8111156107745761077461094c565b6040519080825280601f01601f19166020018201604052801561079e576020820181803683370190505b5090508181016020015b600019016f181899199a1a9b1b9c1cb0b131b232b360811b600a86061a8153600a85049450846107d7576107dc565b6107a8565b509392505050565b60008072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b83106108235772184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b830492506040015b6d04ee2d6d415b85acef8100000000831061084f576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc10000831061086d57662386f26fc10000830492506010015b6305f5e1008310610885576305f5e100830492506008015b612710831061089957612710830492506004015b606483106108ab576064830492506002015b600a83106106025760010192915050565b8280546108c890610e42565b90600052602060002090601f0160209004810192826108ea5760008555610930565b82601f1061090357805160ff1916838001178555610930565b82800160010185558215610930579182015b82811115610930578251825591602001919060010190610915565b506107439291505b808211156107435760008155600101610938565b634e487b7160e01b600052604160045260246000fd5b6040516060810167ffffffffffffffff811182821017156109855761098561094c565b60405290565b604051601f8201601f1916810167ffffffffffffffff811182821017156109b4576109b461094c565b604052919050565b600067ffffffffffffffff8211156109d6576109d661094c565b5060051b60200190565b803563ffffffff811681146109f457600080fd5b919050565b600067ffffffffffffffff831115610a1357610a1361094c565b610a26601f8401601f191660200161098b565b9050828152838383011115610a3a57600080fd5b828260208301376000602084830101529392505050565b600082601f830112610a6257600080fd5b81356020610a77610a72836109bc565b61098b565b82815260059290921b84018101918181019086841115610a9657600080fd5b8286015b84811015610aeb57803567ffffffffffffffff811115610aba5760008081fd5b8701603f81018913610acc5760008081fd5b610add8986830135604084016109f9565b845250918301918301610a9a565b509695505050505050565b60008060408385031215610b0957600080fd5b823567ffffffffffffffff80821115610b2157600080fd5b818501915085601f830112610b3557600080fd5b81356020610b45610a72836109bc565b82815260059290921b84018101918181019089841115610b6457600080fd5b8286015b84811015610c7657803586811115610b7f57600080fd5b87016060818d03601f19011215610b9557600080fd5b610b9d610962565b610ba88683016109e0565b8152604082013588811115610bbc57600080fd5b8201603f81018e13610bcd57600080fd5b610bde8e88830135604084016109f9565b8783015250606082013588811115610bf557600080fd5b8083019250508c603f830112610c0a57600080fd5b85820135610c1a610a72826109bc565b81815260059190911b830160400190878101908f831115610c3a57600080fd5b6040850194505b82851015610c6157610c52856109e0565b82529388019390880190610c41565b60408401525050845250918301918301610b68565b5096505086013592505080821115610c8d57600080fd5b50610c9a85828601610a51565b9150509250929050565b60005b83811015610cbf578181015183820152602001610ca7565b83811115610cce576000848401525b50505050565b60008151808452610cec816020860160208601610ca4565b601f01601f19169290920160200192915050565b60a081526000610d1360a0830188610cd4565b602083820381850152610d268289610cd4565b915083820360408501528187518084528284019150828160051b850101838a0160005b83811015610d7757601f19878403018552610d65838351610cd4565b94860194925090850190600101610d49565b50508681036060880152610d8b818a610cd4565b95505050505050610da0608083018415159052565b9695505050505050565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b60008160070b8360070b6000821282677fffffffffffffff03821381151615610e0157610e01610dc0565b82677fffffffffffffff19038212811615610e1e57610e1e610dc0565b50019392505050565b6000600019821415610e3b57610e3b610dc0565b5060010190565b600181811c90821680610e5657607f821691505b60208210811415610e7757634e487b7160e01b600052602260045260246000fd5b50919050565b60008351610e8f818460208801610ca4565b835190830190610ea3818360208801610ca4565b01949350505050565b606081526000610ebf6060830186610cd4565b602083820381850152610ed28287610cd4565b91506040848303818601528286518085528385019150838160051b86010184890160005b83811015610f4657878303601f1901855281518051878552610f1a88860182610cd4565b91890151858303868b0152919050610f328183610cd4565b968901969450505090860190600101610ef6565b50909b9a505050505050505050505056fe2f646174612f7075626c69635f6d6574726963732f666f6c6c6f776572735f636f756e7422207d2c207b2022737263223a2022246861735f776562335f6163636f756e74222c20226f70223a20223c3d222c2022647374223a2022687474703a2f2f6c6f63616c686f73743a31393532382f322f75736572732f62792f757365726e616d652f68747470733a2f2f7261772e67697468756275736572636f6e74656e742e636f6d2f6c6974656e7472792f76632d6a736f6e736368656d612f6d61696e2f646973742f736368656d61732f312d62617369632d6964656e746974792d766572696669636174696f6e2f312d302d302e6a736f6e7b22616e64223a205b7b2022737263223a202224746f74616c5f666f6c6c6f77657273222c20226f70223a20223e222c2022647374223a20225468652072616e6765206f662074686520757365722773205477697474657220666f6c6c6f77657220636f756e74a26469706673582212205477d94cb65333aa196b3b3039e3869eddc3644cc3d257895803d4f6809bbac264736f6c634300080b0033").unwrap(), + hex::decode("608060405234801561001057600080fd5b50611101806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063e256184614610030575b600080fd5b61004361003e366004610b0e565b61005d565b604051610054959493929190610d18565b60405180910390f35b6060806060806000806040518060600160405280602e815260200161109e602e9139905060006040518060400160405280601781526020017f5477697474657220466f6c6c6f77657220416d6f756e7400000000000000000081525090506040518060a00160405280606f8152602001610f70606f913980516100e8916001916020909101906108d4565b50600080805b8b518110156102ad576101198c828151811061010c5761010c610dc2565b6020026020010151610600565b1561029b57600061015f6040518060600160405280602b815260200161103a602b91398e848151811061014e5761014e610dc2565b602002602001015160200151610613565b905060006101a2826040518060400160405280601b81526020017f3f757365722e6669656c64733d7075626c69635f6d6574726963730000000000815250610613565b60408051600180825281830190925291925060009190816020015b60408051808201909152606080825260208201528152602001906001900390816101bd57905050905060405180604001604052806040518060400160405280600d81526020016c30baba3437b934bd30ba34b7b760991b81525081526020018f60008151811061022f5761022f610dc2565b60200260200101518152508160008151811061024d5761024d610dc2565b602002602001018190525060008061027e84604051806060016040528060248152602001610fdf6024913985610642565b915091508115610295576102928188610dee565b96505b50505050505b806102a581610e3f565b9150506100ee565b5060008060008360070b121580156102c9575060018360070b13155b156102da57506000905060016103a5565b60018360070b1380156102f1575060648360070b13155b1561030257506001905060646103a5565b60648360070b13801561031a57506103e88360070b13155b1561032c5750606490506103e86103a5565b6103e88360070b13801561034557506127108360070b13155b1561035857506103e890506127106103a5565b6127108360070b1380156103725750620186a08360070b13155b1561038657506127109050620186a06103a5565b620186a08360070b13156103a55750620186a09050677fffffffffffffff5b6001935060006103d8604051806060016040528060398152602001611065603991396103d38560070b6106ac565b610613565b90506103fc8160405180606001604052806037815260200161100360379139610613565b905061040e816103d38460070b6106ac565b9050610439816040518060400160405280600781526020016622207d205d207d60c81b815250610613565b60008054600181018255908052815191925061047e917f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e5639091019060208401906108d4565b508686600060018882805480602002602001604051908101604052809291908181526020016000905b828210156105535783829060005260206000200180546104c690610e5a565b80601f01602080910402602001604051908101604052809291908181526020018280546104f290610e5a565b801561053f5780601f106105145761010080835404028352916020019161053f565b820191906000526020600020905b81548152906001019060200180831161052257829003601f168201915b5050505050815260200190600101906104a7565b50505050925081805461056590610e5a565b80601f016020809104026020016040519081016040528092919081815260200182805461059190610e5a565b80156105de5780601f106105b3576101008083540402835291602001916105de565b820191906000526020600020905b8154815290600101906020018083116105c157829003601f168201915b505050505091509b509b509b509b509b50505050505050509295509295909350565b600061060d82600061071e565b92915050565b60606000838360405160200161062a929190610e95565b60408051808303601f19018152919052949350505050565b600080600080600087878760405160200161065f93929190610ec4565b60408051601f198184030181528282528051909350919081836020860160006103e8600019f161068e57600080fd5b8051602082015160409283019092529a909950975050505050505050565b6060600082126106cb57604051806020016040528060008152506106e6565b604051806040016040528060018152602001602d60f81b8152505b6106f76106f284610748565b61075f565b604051602001610708929190610e95565b6040516020818303038152906040529050919050565b60008163ffffffff16836000015163ffffffff1614156107405750600161060d565b50600061060d565b60008082121561075b578160000361060d565b5090565b6060600061076c836107fc565b600101905060008167ffffffffffffffff81111561078c5761078c610964565b6040519080825280601f01601f1916602001820160405280156107b6576020820181803683370190505b5090508181016020015b600019016f181899199a1a9b1b9c1cb0b131b232b360811b600a86061a8153600a85049450846107ef576107f4565b6107c0565b509392505050565b60008072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b831061083b5772184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b830492506040015b6d04ee2d6d415b85acef81000000008310610867576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc10000831061088557662386f26fc10000830492506010015b6305f5e100831061089d576305f5e100830492506008015b61271083106108b157612710830492506004015b606483106108c3576064830492506002015b600a831061060d5760010192915050565b8280546108e090610e5a565b90600052602060002090601f0160209004810192826109025760008555610948565b82601f1061091b57805160ff1916838001178555610948565b82800160010185558215610948579182015b8281111561094857825182559160200191906001019061092d565b5061075b9291505b8082111561075b5760008155600101610950565b634e487b7160e01b600052604160045260246000fd5b6040516060810167ffffffffffffffff8111828210171561099d5761099d610964565b60405290565b604051601f8201601f1916810167ffffffffffffffff811182821017156109cc576109cc610964565b604052919050565b600067ffffffffffffffff8211156109ee576109ee610964565b5060051b60200190565b803563ffffffff81168114610a0c57600080fd5b919050565b600067ffffffffffffffff831115610a2b57610a2b610964565b610a3e601f8401601f19166020016109a3565b9050828152838383011115610a5257600080fd5b828260208301376000602084830101529392505050565b600082601f830112610a7a57600080fd5b81356020610a8f610a8a836109d4565b6109a3565b82815260059290921b84018101918181019086841115610aae57600080fd5b8286015b84811015610b0357803567ffffffffffffffff811115610ad25760008081fd5b8701603f81018913610ae45760008081fd5b610af5898683013560408401610a11565b845250918301918301610ab2565b509695505050505050565b60008060408385031215610b2157600080fd5b823567ffffffffffffffff80821115610b3957600080fd5b818501915085601f830112610b4d57600080fd5b81356020610b5d610a8a836109d4565b82815260059290921b84018101918181019089841115610b7c57600080fd5b8286015b84811015610c8e57803586811115610b9757600080fd5b87016060818d03601f19011215610bad57600080fd5b610bb561097a565b610bc08683016109f8565b8152604082013588811115610bd457600080fd5b8201603f81018e13610be557600080fd5b610bf68e8883013560408401610a11565b8783015250606082013588811115610c0d57600080fd5b8083019250508c603f830112610c2257600080fd5b85820135610c32610a8a826109d4565b81815260059190911b830160400190878101908f831115610c5257600080fd5b6040850194505b82851015610c7957610c6a856109f8565b82529388019390880190610c59565b60408401525050845250918301918301610b80565b5096505086013592505080821115610ca557600080fd5b50610cb285828601610a69565b9150509250929050565b60005b83811015610cd7578181015183820152602001610cbf565b83811115610ce6576000848401525b50505050565b60008151808452610d04816020860160208601610cbc565b601f01601f19169290920160200192915050565b60a081526000610d2b60a0830188610cec565b602083820381850152610d3e8289610cec565b915083820360408501528187518084528284019150828160051b850101838a0160005b83811015610d8f57601f19878403018552610d7d838351610cec565b94860194925090850190600101610d61565b50508681036060880152610da3818a610cec565b95505050505050610db8608083018415159052565b9695505050505050565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b60008160070b8360070b6000821282677fffffffffffffff03821381151615610e1957610e19610dd8565b82677fffffffffffffff19038212811615610e3657610e36610dd8565b50019392505050565b6000600019821415610e5357610e53610dd8565b5060010190565b600181811c90821680610e6e57607f821691505b60208210811415610e8f57634e487b7160e01b600052602260045260246000fd5b50919050565b60008351610ea7818460208801610cbc565b835190830190610ebb818360208801610cbc565b01949350505050565b606081526000610ed76060830186610cec565b602083820381850152610eea8287610cec565b91506040848303818601528286518085528385019150838160051b86010184890160005b83811015610f5e57878303601f1901855281518051878552610f3288860182610cec565b91890151858303868b0152919050610f4a8183610cec565b968901969450505090860190600101610f0e565b50909b9a505050505050505050505056fe68747470733a2f2f7261772e67697468756275736572636f6e74656e742e636f6d2f6c6974656e7472792f76632d6a736f6e736368656d612f6d61696e2f646973742f736368656d61732f362d747769747465722d666f6c6c6f7765722d616d6f756e742f312d302d302e6a736f6e2f646174612f7075626c69635f6d6574726963732f666f6c6c6f776572735f636f756e7422207d2c207b2022737263223a2022246861735f776562335f6163636f756e74222c20226f70223a20223c3d222c2022647374223a2022687474703a2f2f6c6f63616c686f73743a31393532382f322f75736572732f62792f757365726e616d652f7b22616e64223a205b7b2022737263223a202224746f74616c5f666f6c6c6f77657273222c20226f70223a20223e222c2022647374223a20225468652072616e6765206f662074686520757365722773205477697474657220666f6c6c6f77657220636f756e74a26469706673582212205ac73b1873ac9a973d745ba779b9bfcef50026b13042b0bf6c8546142feec36a64736f6c634300080b0033").unwrap(), vec!["twitter_api_key".to_string()] ) ); diff --git a/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/http_get.rs b/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/http_get.rs index f1d803c13c..978af45cc1 100644 --- a/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/http_get.rs +++ b/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/http_get.rs @@ -26,10 +26,9 @@ pub mod test { use crate::precompiles::{ http_get::{http_get_bool, http_get_i64, http_get_string}, mocks::MockedHttpClient, - PrecompileResult, }; use ethabi::ethereum_types::U256; - use evm::{executor::stack::PrecompileFailure, ExitError, ExitSucceed}; + use evm::ExitSucceed; #[test] pub fn test_get_bool() { @@ -42,7 +41,10 @@ pub mod test { // then assert!(matches!(result.exit_status, ExitSucceed::Returned)); - assert_eq!(ethabi::encode(&[ethabi::Token::Bool(true)]), result.output) + assert_eq!( + ethabi::encode(&[ethabi::Token::Bool(true), ethabi::Token::Bool(true)]), + result.output + ) } #[test] @@ -57,7 +59,10 @@ pub mod test { // then assert!(matches!(result.exit_status, ExitSucceed::Returned)); assert_eq!( - ethabi::encode(&[ethabi::Token::Uint(U256::try_from(10).unwrap())]), + ethabi::encode(&[ + ethabi::Token::Bool(true), + ethabi::Token::Uint(U256::try_from(10).unwrap()) + ]), result.output ) } @@ -73,78 +78,98 @@ pub mod test { // then assert!(matches!(result.exit_status, ExitSucceed::Returned)); - assert_eq!(ethabi::encode(&[ethabi::Token::String("string".to_string())]), result.output) + assert_eq!( + ethabi::encode(&[ + ethabi::Token::Bool(true), + ethabi::Token::String("string".to_string()) + ]), + result.output + ) } #[test] - pub fn returns_error_for_invalid_url() { + pub fn returns_failure_for_invalid_url() { // given let client = MockedHttpClient::default(); let data = prepare_input_data("invalid_url", "/string"); // when - let result = http_get_string(data, client); + let result = http_get_string(data, client).unwrap(); // then - assert_exit_status_reason( - &result, - "Could not parse url \"invalid_url\", reason: RelativeUrlWithoutBase", - ); + assert!(matches!(result.exit_status, ExitSucceed::Returned)); + assert_eq!( + ethabi::encode(&[ethabi::Token::Bool(false), ethabi::Token::String("".to_string())]), + result.output + ) } #[test] - pub fn returns_error_for_invalid_json_pointer() { + pub fn returns_failure_for_invalid_json_pointer() { // given let client = MockedHttpClient::default(); let data = prepare_input_data("https://www.litentry.com/", "invalid_pointer"); // when - let result = http_get_string(data, client); + let result = http_get_string(data, client).unwrap(); // then - assert_exit_status_reason(&result, "No value under given pointer: :\"invalid_pointer\""); + assert!(matches!(result.exit_status, ExitSucceed::Returned)); + assert_eq!( + ethabi::encode(&[ethabi::Token::Bool(false), ethabi::Token::String("".to_string())]), + result.output + ) } #[test] - pub fn returns_error_for_malformed_json() { + pub fn returns_failure_for_malformed_json() { // given let client = MockedHttpClient::malformed_json(); let data = prepare_input_data("https://www.litentry.com/", "string"); // when - let result = http_get_string(data, client); + let result = http_get_string(data, client).unwrap(); // then - assert_exit_status_reason(&result, "Could not parse json [123, 123], reason: Error(\"key must be a string\", line: 1, column: 2)"); + assert!(matches!(result.exit_status, ExitSucceed::Returned)); + assert_eq!( + ethabi::encode(&[ethabi::Token::Bool(false), ethabi::Token::String("".to_string())]), + result.output + ) } #[test] - pub fn returns_error_for_value_of_type_other_than_expected() { + pub fn returns_failure_for_value_of_type_other_than_expected() { // given let client = MockedHttpClient::default(); let data = prepare_input_data("https://www.litentry.com/", "/not_bool"); // when - let result = http_get_bool(data, client); + let result = http_get_bool(data, client).unwrap(); // then - assert_exit_status_reason( - &result, - "There is no value or it might be of different type, pointer: $\"/not_bool\"", - ); + assert!(matches!(result.exit_status, ExitSucceed::Returned)); + assert_eq!( + ethabi::encode(&[ethabi::Token::Bool(false), ethabi::Token::Bool(false)]), + result.output + ) } #[test] - pub fn returns_error_for_invalid_input_data() { + pub fn returns_failure_for_invalid_input_data() { // given let client = MockedHttpClient::default(); let data = [0u8, 11]; // when - let result = http_get_bool(data.to_vec(), client); + let result = http_get_bool(data.to_vec(), client).unwrap(); // then - assert_exit_status_reason(&result, "Could not decode bytes [0, 11], reason: InvalidData"); + assert!(matches!(result.exit_status, ExitSucceed::Returned)); + assert_eq!( + ethabi::encode(&[ethabi::Token::Bool(false), ethabi::Token::Bool(false)]), + result.output + ) } #[test] @@ -154,28 +179,14 @@ pub mod test { let data = prepare_input_data("https://www.litentry.com/", "string"); // when - let result = http_get_string(data, client); + let result = http_get_string(data, client).unwrap(); // then - assert_exit_status_reason( - &result, - "Error while performing http call: HttpError(404, \"Not found\")", - ); - } - - fn assert_exit_status_reason(result: &PrecompileResult, expected_reason: &str) { - match result { - Err(e) => match e { - PrecompileFailure::Error { exit_status } => match exit_status { - ExitError::Other(reason) => { - assert_eq!(reason.to_string(), expected_reason) - }, - _ => panic!("Different exit status"), - }, - _ => panic!("Different failure"), - }, - _ => panic!("Expected err"), - } + assert!(matches!(result.exit_status, ExitSucceed::Returned)); + assert_eq!( + ethabi::encode(&[ethabi::Token::Bool(false), ethabi::Token::String("".to_string())]), + result.output + ) } fn prepare_input_data(url: &str, pointer: &str) -> Vec { diff --git a/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/macros.rs b/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/macros.rs index 9b86f79508..e7780c9032 100644 --- a/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/macros.rs +++ b/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/macros.rs @@ -14,13 +14,6 @@ // You should have received a copy of the GNU General Public License // along with Litentry. If not, see . -use evm::{executor::stack::PrecompileFailure, ExitError}; -use std::{borrow::Cow, string::String}; - -pub fn prepare_custom_failure(reason: String) -> PrecompileFailure { - PrecompileFailure::Error { exit_status: ExitError::Other(Cow::Owned(reason)) } -} - #[macro_export] macro_rules! http_get_precompile_fn { ($name:ident, $token:ident, $parse_fn_name:ident) => { @@ -28,7 +21,7 @@ macro_rules! http_get_precompile_fn { input: Vec, client: T, ) -> $crate::precompiles::PrecompileResult { - let decoded = ethabi::decode( + let decoded = match ethabi::decode( &[ ethabi::ParamType::String, ethabi::ParamType::String, @@ -41,21 +34,34 @@ macro_rules! http_get_precompile_fn { ), ], &input, - ) - .map_err(|e| { - $crate::precompiles::macros::prepare_custom_failure(std::format!( - "Could not decode bytes {:?}, reason: {:?}", - input, e - )) - })?; + ) { + Ok(d) => d, + Err(e) => { + log::debug!("Could not decode bytes {:?}, reason: {:?}", input, e); + return Ok(evm::executor::stack::PrecompileOutput { + exit_status: evm::ExitSucceed::Returned, + output: ethabi::encode(&[ + ethabi::Token::Bool(false), + ethabi::Token::$token(Default::default()), + ]), + }) + }, + }; // safe to unwrap let url = decoded.get(0).unwrap().clone().into_string().unwrap(); - let url = itc_rest_client::rest_client::Url::parse(&url).map_err(|e| { - $crate::precompiles::macros::prepare_custom_failure(std::format!( - "Could not parse url {:?}, reason: {:?}", - url, e - )) - })?; + let url = match itc_rest_client::rest_client::Url::parse(&url) { + Ok(v) => v, + Err(e) => { + log::debug!("Could not parse url {:?}, reason: {:?}", url, e); + return Ok(evm::executor::stack::PrecompileOutput { + exit_status: evm::ExitSucceed::Returned, + output: ethabi::encode(&[ + ethabi::Token::Bool(false), + ethabi::Token::$token(Default::default()), + ]), + }) + }, + }; // safe to unwrap let pointer = decoded.get(1).unwrap().clone().into_string().unwrap(); @@ -89,41 +95,68 @@ macro_rules! http_get_precompile_fn { (name, value) }) .collect(); - let resp = client - .send_request_raw( - url, - itc_rest_client::rest_client::Method::GET, - None, - http_headers, - ) - .map_err(|e| { - $crate::precompiles::macros::prepare_custom_failure(std::format!( - "Error while performing http call: {:?}", - e - )) - })?; - let value: serde_json::Value = serde_json::from_slice(&resp.1).map_err(|e| { - $crate::precompiles::macros::prepare_custom_failure(std::format!( - "Could not parse json {:?}, reason: {:?}", - resp.1, e - )) - })?; + let resp = match client.send_request_raw( + url, + itc_rest_client::rest_client::Method::GET, + None, + http_headers, + ) { + Ok(resp) => resp, + Err(e) => { + log::debug!("Error while performing http call: {:?}", e); + + return Ok(evm::executor::stack::PrecompileOutput { + exit_status: evm::ExitSucceed::Returned, + output: ethabi::encode(&[ + ethabi::Token::Bool(false), + ethabi::Token::$token(Default::default()), + ]), + }) + }, + }; + let value: serde_json::Value = match serde_json::from_slice(&resp.1) { + Ok(v) => v, + Err(e) => { + log::debug!("Could not parse json {:?}, reason: {:?}", resp.1, e); + return Ok(evm::executor::stack::PrecompileOutput { + exit_status: evm::ExitSucceed::Returned, + output: ethabi::encode(&[ + ethabi::Token::Bool(false), + ethabi::Token::$token(Default::default()), + ]), + }) + }, + }; let result = match value.pointer(&pointer) { Some(v) => v, - None => - return Err($crate::precompiles::macros::prepare_custom_failure(std::format!( - "No value under given pointer: :{:?}", - pointer - ))), + None => { + log::debug!("No value under given pointer: :{:?}", pointer); + return Ok(evm::executor::stack::PrecompileOutput { + exit_status: evm::ExitSucceed::Returned, + output: ethabi::encode(&[ + ethabi::Token::Bool(false), + ethabi::Token::$token(Default::default()), + ]), + }) + }, }; let encoded = match result.$parse_fn_name() { - Some(v) => ethabi::encode(&[ethabi::Token::$token(v.into())]), - None => - return Err($crate::precompiles::macros::prepare_custom_failure(std::format!( + Some(v) => + ethabi::encode(&[ethabi::Token::Bool(true), ethabi::Token::$token(v.into())]), + None => { + log::debug!( "There is no value or it might be of different type, pointer: ${:?}", pointer - ))), + ); + return Ok(evm::executor::stack::PrecompileOutput { + exit_status: evm::ExitSucceed::Returned, + output: ethabi::encode(&[ + ethabi::Token::Bool(false), + ethabi::Token::$token(Default::default()), + ]), + }) + }, }; Ok(evm::executor::stack::PrecompileOutput { exit_status: evm::ExitSucceed::Returned, diff --git a/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/to_hex.rs b/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/to_hex.rs index 3cb8a8421f..64123ac6ea 100644 --- a/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/to_hex.rs +++ b/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/to_hex.rs @@ -14,22 +14,31 @@ // You should have received a copy of the GNU General Public License // along with Litentry. If not, see . -use crate::precompiles::{macros::prepare_custom_failure, PrecompileResult}; +use crate::precompiles::PrecompileResult; use std::{format, vec::Vec}; pub fn to_hex(input: Vec) -> PrecompileResult { - let decoded = ethabi::decode(&[ethabi::ParamType::Bytes], &input).map_err(|e| { - prepare_custom_failure(format!("Could not decode bytes {:?}, reason: {:?}", input, e)) - })?; - + let decoded = match ethabi::decode(&[ethabi::ParamType::Bytes], &input) { + Ok(d) => d, + Err(e) => { + log::debug!("Could not decode bytes {:?}, reason: {:?}", input, e); + let encoded = ethabi::encode(&[ + ethabi::Token::Bool(true), + ethabi::Token::String(Default::default()), + ]); + return Ok(evm::executor::stack::PrecompileOutput { + exit_status: evm::ExitSucceed::Returned, + output: encoded, + }) + }, + }; // safe to unwrap let bytes = decoded.get(0).unwrap().clone().into_bytes().unwrap(); - let hex_encoded = format!("0x{}", hex::encode(&bytes)); - let encoded = ethabi::encode(&[ethabi::Token::String(hex_encoded)]); + let encoded = ethabi::encode(&[ethabi::Token::Bool(true), ethabi::Token::String(hex_encoded)]); Ok(evm::executor::stack::PrecompileOutput { exit_status: evm::ExitSucceed::Returned, - output: encoded[32..encoded.len()].to_vec(), + output: encoded, }) } @@ -50,7 +59,10 @@ pub mod test { //then assert!(matches!(result.exit_status, ExitSucceed::Returned)); assert_eq!( - ethabi::encode(&[ethabi::Token::String("0x01020304".to_string())])[32..].to_vec(), + ethabi::encode(&[ + ethabi::Token::Bool(true), + ethabi::Token::String("0x01020304".to_string()) + ]), result.output ) } From 62f5b3ad964f2783b368f149194466121ab38f13 Mon Sep 17 00:00:00 2001 From: Kai <7630809+Kailai-Wang@users.noreply.github.com> Date: Thu, 6 Jun 2024 12:17:12 +0200 Subject: [PATCH 02/10] Use `skip_filtering` when getting eligible identities (#2789) * add skip filtering * update unit test --- primitives/core/src/assertion/mod.rs | 13 ++---- .../app-libs/stf/src/trusted_call_litentry.rs | 2 +- .../litentry/core/vc-task/receiver/src/lib.rs | 2 +- .../src/identity_context.rs | 13 +++--- .../pallets/identity-management/src/tests.rs | 43 ++++++++----------- 5 files changed, 32 insertions(+), 41 deletions(-) diff --git a/primitives/core/src/assertion/mod.rs b/primitives/core/src/assertion/mod.rs index f084a16d7a..ca76165fb9 100644 --- a/primitives/core/src/assertion/mod.rs +++ b/primitives/core/src/assertion/mod.rs @@ -190,17 +190,12 @@ impl Assertion { } } - // Given an assertion, normally either "web2" or "web3" identities are expected to be used - // to build the assertion, but not both. - // However, there's one exception: A1, which requires at least 1 web2 identity and 1 web3 - // identity. - // - // This fn is used in `get_eligible_identities` to decide if we should keep web2 identities - // regardless of the value of `get_supported_web3networks` + // Used in `get_eligible_identities` to decide if we should pass identities through + // and let assertion logic handle them #[allow(clippy::match_like_matches_macro)] - pub fn force_retain_web2_identity(&self) -> bool { + pub fn skip_identity_filtering(&self) -> bool { match self { - Self::A1 => true, + Self::A1 | Self::Dynamic(_) => true, _ => false, } } diff --git a/tee-worker/app-libs/stf/src/trusted_call_litentry.rs b/tee-worker/app-libs/stf/src/trusted_call_litentry.rs index fa92fcf177..dc53e6a9ab 100644 --- a/tee-worker/app-libs/stf/src/trusted_call_litentry.rs +++ b/tee-worker/app-libs/stf/src/trusted_call_litentry.rs @@ -197,7 +197,7 @@ impl TrustedCallSigned { let identities = get_eligible_identities( id_graph.as_ref(), assertion_networks, - assertion.force_retain_web2_identity(), + assertion.skip_identity_filtering(), ); ensure!( diff --git a/tee-worker/litentry/core/vc-task/receiver/src/lib.rs b/tee-worker/litentry/core/vc-task/receiver/src/lib.rs index 47d93cb994..20423d0c0f 100644 --- a/tee-worker/litentry/core/vc-task/receiver/src/lib.rs +++ b/tee-worker/litentry/core/vc-task/receiver/src/lib.rs @@ -531,7 +531,7 @@ where let identities = get_eligible_identities( id_graph.as_ref(), assertion_networks, - assertion.force_retain_web2_identity(), + assertion.skip_identity_filtering(), ); ensure!(!identities.is_empty(), "No eligible identity".to_string()); diff --git a/tee-worker/litentry/pallets/identity-management/src/identity_context.rs b/tee-worker/litentry/pallets/identity-management/src/identity_context.rs index 0babde42d6..9bad2014cf 100644 --- a/tee-worker/litentry/pallets/identity-management/src/identity_context.rs +++ b/tee-worker/litentry/pallets/identity-management/src/identity_context.rs @@ -86,17 +86,24 @@ pub fn sort_id_graph(id_graph: &mut [(Identity, IdentityContext)]) // get the active identities in the `id_graph` whose web3networks match the `desired_web3networks`, // return a `Vec<(Identity, Vec)` with retained web3networks +// +// if `skip_filtering` is true, the **active** identities will be passed through regardless of the value +// of `desired_web3networks`, which basically let assertion logic itself to handle those identities. #[allow(clippy::collapsible_else_if)] pub fn get_eligible_identities( id_graph: &IDGraph, desired_web3networks: Vec, - force_retain_web2_identity: bool, + skip_filtering: bool, ) -> Vec { id_graph .iter() .filter_map(|item| { if item.1.is_active() { let mut networks = item.0.default_web3networks(); + + if skip_filtering { + return Some((item.0.clone(), networks)) + } // filter out identities whose web3networks are not supported by this specific `assertion`. // We do it here before every request sending because: // - it's a common step for all assertion buildings, for those assertions which only @@ -104,10 +111,6 @@ pub fn get_eligible_identities( // - it helps to reduce the request size a bit networks.retain(|n| desired_web3networks.contains(n)); - if force_retain_web2_identity && item.0.is_web2() { - return Some((item.0.clone(), Vec::new())) - } - // differentiate between web2 and web3 assertions: // desired_web3networks.is_empty() means it's a web2 assertion, // otherwise web2 identities might survive to be unexpectedly "eligible" for web3 assertions. diff --git a/tee-worker/litentry/pallets/identity-management/src/tests.rs b/tee-worker/litentry/pallets/identity-management/src/tests.rs index 20315adc50..b40c07d1e3 100644 --- a/tee-worker/litentry/pallets/identity-management/src/tests.rs +++ b/tee-worker/litentry/pallets/identity-management/src/tests.rs @@ -19,6 +19,7 @@ use crate::{ IdentityContext, IdentityStatus, Web3Network, }; use frame_support::{assert_err, assert_noop, assert_ok, traits::Get}; +use litentry_primitives::all_substrate_web3networks; use sp_runtime::AccountId32; pub const ALICE: AccountId32 = AccountId32::new([1u8; 32]); pub const BOB: AccountId32 = AccountId32::new([2u8; 32]); @@ -27,31 +28,22 @@ pub const CHARLIE: AccountId32 = AccountId32::new([3u8; 32]); #[test] fn get_eligible_identities_works() { let mut id_graph = IDGraph::::default(); - id_graph.push(( - alice_substrate_identity(), - IdentityContext::new(1u64, vec![Web3Network::Litentry, Web3Network::Khala]), - )); + id_graph.push((alice_substrate_identity(), IdentityContext::new(1u64, vec![]))); + id_graph.push((alice_evm_identity(), IdentityContext::new(1u64, vec![]))); id_graph.push((alice_twitter_identity(1), IdentityContext::new(2u64, vec![]))); + + // only `alice_substrate_identity` is left let mut desired_web3networks = vec![Web3Network::Litentry, Web3Network::Polkadot]; let mut identities = - get_eligible_identities(id_graph.as_ref(), desired_web3networks.clone(), true); - assert_eq!(identities.len(), 2); - assert_eq!(identities[0].1, vec![Web3Network::Polkadot, Web3Network::Litentry]); - assert_eq!(identities[1].1, vec![]); - - // `alice_evm_identity` should be filtered out - id_graph.push((alice_evm_identity(), IdentityContext::new(1u64, vec![]))); - identities = get_eligible_identities(id_graph.as_ref(), desired_web3networks, true); - assert_eq!(identities.len(), 2); + get_eligible_identities(id_graph.as_ref(), desired_web3networks.clone(), false); + assert_eq!(identities.len(), 1); assert_eq!(identities[0].1, vec![Web3Network::Polkadot, Web3Network::Litentry]); - assert_eq!(identities[1].1, vec![]); - // `alice_substrate_identity` should be filtered out - desired_web3networks = all_evm_web3networks(); - identities = get_eligible_identities(id_graph.as_ref(), desired_web3networks, true); - assert_eq!(identities.len(), 2); - assert_eq!(identities[0].1, vec![]); - assert_eq!(identities[1].1, all_evm_web3networks()); + // only `alice_evm_identity` is left + desired_web3networks = vec![Web3Network::Arbitrum]; + identities = get_eligible_identities(id_graph.as_ref(), desired_web3networks, false); + assert_eq!(identities.len(), 1); + assert_eq!(identities[0].1, vec![Web3Network::Arbitrum]); // only twitter identity is left desired_web3networks = vec![]; @@ -62,11 +54,12 @@ fn get_eligible_identities_works() { desired_web3networks = vec![Web3Network::Arbitrum]; - // only `alice_evm_identity` is left - identities = get_eligible_identities(id_graph.as_ref(), desired_web3networks, false); - assert_eq!(identities.len(), 1); - assert_eq!(identities[0].1, vec![Web3Network::Arbitrum]); - assert_eq!(identities[0].0, alice_evm_identity()); + // no identity is filtered out, note the networks are reset to the default networks + identities = get_eligible_identities(id_graph.as_ref(), desired_web3networks, true); + assert_eq!(identities.len(), 3); + assert_eq!(identities[0].1, all_substrate_web3networks()); + assert_eq!(identities[1].1, all_evm_web3networks()); + assert_eq!(identities[2].1, vec![]); } #[test] From 6f2443bd2a57b3963f82c7490a8d74539c8901fe Mon Sep 17 00:00:00 2001 From: Kai <7630809+Kailai-Wang@users.noreply.github.com> Date: Fri, 7 Jun 2024 09:27:01 +0200 Subject: [PATCH 03/10] Avoid nested ErrorDetail in assertion building (#2791) * No nested ErrorDetail * simplify it --- .../src/token_holding_amount/mod.rs | 48 ++++++++----------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/tee-worker/litentry/core/assertion-build-v2/src/token_holding_amount/mod.rs b/tee-worker/litentry/core/assertion-build-v2/src/token_holding_amount/mod.rs index 5376809747..b5cc3d9811 100644 --- a/tee-worker/litentry/core/assertion-build-v2/src/token_holding_amount/mod.rs +++ b/tee-worker/litentry/core/assertion-build-v2/src/token_holding_amount/mod.rs @@ -47,36 +47,26 @@ pub fn build( let result = get_token_balance(token_type.clone(), addresses, data_provider_config).map_err(|e| { - Error::RequestVCFailed( - Assertion::TokenHoldingAmount(token_type.clone()), - ErrorDetail::DataProviderError(ErrorString::truncate_from( - format!("{e:?}").as_bytes().to_vec(), - )), - ) - }); - - match result { - Ok(value) => { - let runtime_version = IssuerRuntimeVersion { - parachain: req.parachain_runtime_version, - sidechain: req.sidechain_runtime_version, - }; - - match Credential::new(&req.who, &req.shard, &runtime_version) { - Ok(mut credential_unsigned) => { - credential_unsigned.update_token_holding_amount_assertion(token_type, value); - Ok(credential_unsigned) - }, - Err(e) => { - error!("Generate unsigned credential failed {:?}", e); - Err(Error::RequestVCFailed( - Assertion::TokenHoldingAmount(token_type), - e.into_error_detail(), - )) - }, - } + Error::RequestVCFailed(Assertion::TokenHoldingAmount(token_type.clone()), e) + })?; + + let runtime_version = IssuerRuntimeVersion { + parachain: req.parachain_runtime_version, + sidechain: req.sidechain_runtime_version, + }; + + match Credential::new(&req.who, &req.shard, &runtime_version) { + Ok(mut credential_unsigned) => { + credential_unsigned.update_token_holding_amount_assertion(token_type, result); + Ok(credential_unsigned) + }, + Err(e) => { + error!("Generate unsigned credential failed {:?}", e); + Err(Error::RequestVCFailed( + Assertion::TokenHoldingAmount(token_type), + e.into_error_detail(), + )) }, - Err(e) => Err(e), } } From 03a3e084f7687fc10779b4f0e0df35b2eb707d6c Mon Sep 17 00:00:00 2001 From: Kasper Ziemianek Date: Fri, 7 Jun 2024 10:07:01 +0200 Subject: [PATCH 04/10] A6 solidity adjustments and fixes before dev deploy (#2792) Co-authored-by: Kai <7630809+Kailai-Wang@users.noreply.github.com> --- .../src/dynamic/contracts/A6.sol | 30 +++++++++++++++---- .../assertion-build/src/dynamic/repository.rs | 2 +- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/A6.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/A6.sol index 1156a3546a..1adceb5a6e 100644 --- a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/A6.sol +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/A6.sol @@ -36,7 +36,7 @@ contract A6 is DynamicAssertion { string memory description = "The range of the user's Twitter follower count"; string memory assertion_type = "Twitter Follower Amount"; - schema_url = "https://raw.githubusercontent.com/litentry/vc-jsonschema/main/dist/schemas/6-twitter-follower-amount/1-0-0.json"; + schema_url = "https://raw.githubusercontent.com/litentry/vc-jsonschema/main/dist/schemas/6-twitter-follower-amount/1-1-1.json"; bool result; @@ -44,8 +44,9 @@ contract A6 is DynamicAssertion { for (uint256 i = 0; i < identities.length; i++) { if (is_twitter(identities[i])) { + /// "http://localhost:19528/2/users/by/username/" mock address used in dev env string memory url = concatenateStrings( - "http://localhost:19528/2/users/by/username/", + "https://api.twitter.com/2/users/by/username/", string(identities[i].value) ); string memory full_url = concatenateStrings( @@ -53,9 +54,7 @@ contract A6 is DynamicAssertion { "?user.fields=public_metrics" ); - HttpHeader[] memory headers = new HttpHeader[](1); - // we expect first secret to be twitter api key - headers[0] = HttpHeader("authorization", secrets[0]); + HttpHeader[] memory headers = prepareHeaders(secrets[0]); (bool get_success, int64 followers_count) = GetI64( full_url, @@ -91,7 +90,7 @@ contract A6 is DynamicAssertion { min = 100000; max = 9223372036854775807; } - result = true; + result = min != 0; string memory assertion = concatenateStrings( '{"and": [{ "src": "$total_followers", "op": ">", "dst": "', @@ -106,4 +105,23 @@ contract A6 is DynamicAssertion { assertions.push(assertion); return (description, assertion_type, assertions, schema_url, result); } + + function prepareHeaders(string memory apiKey) + private + pure + returns (HttpHeader[] memory) + { + HttpHeader[] memory headers = new HttpHeader[](1); + // we expect first secret to be twitter api key + headers[0] = HttpHeader("authorization", prepareAuthHeader(apiKey)); + return headers; + } + + function prepareAuthHeader(string memory apiKey) + private + pure + returns (string memory) + { + return concatenateStrings("Bearer ", apiKey); + } } diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/repository.rs b/tee-worker/litentry/core/assertion-build/src/dynamic/repository.rs index 15551f3e18..5352fcc8da 100644 --- a/tee-worker/litentry/core/assertion-build/src/dynamic/repository.rs +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/repository.rs @@ -65,7 +65,7 @@ impl InMemorySmartContractRepo { map.insert( hash(2), ( - hex::decode("608060405234801561001057600080fd5b50611101806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063e256184614610030575b600080fd5b61004361003e366004610b0e565b61005d565b604051610054959493929190610d18565b60405180910390f35b6060806060806000806040518060600160405280602e815260200161109e602e9139905060006040518060400160405280601781526020017f5477697474657220466f6c6c6f77657220416d6f756e7400000000000000000081525090506040518060a00160405280606f8152602001610f70606f913980516100e8916001916020909101906108d4565b50600080805b8b518110156102ad576101198c828151811061010c5761010c610dc2565b6020026020010151610600565b1561029b57600061015f6040518060600160405280602b815260200161103a602b91398e848151811061014e5761014e610dc2565b602002602001015160200151610613565b905060006101a2826040518060400160405280601b81526020017f3f757365722e6669656c64733d7075626c69635f6d6574726963730000000000815250610613565b60408051600180825281830190925291925060009190816020015b60408051808201909152606080825260208201528152602001906001900390816101bd57905050905060405180604001604052806040518060400160405280600d81526020016c30baba3437b934bd30ba34b7b760991b81525081526020018f60008151811061022f5761022f610dc2565b60200260200101518152508160008151811061024d5761024d610dc2565b602002602001018190525060008061027e84604051806060016040528060248152602001610fdf6024913985610642565b915091508115610295576102928188610dee565b96505b50505050505b806102a581610e3f565b9150506100ee565b5060008060008360070b121580156102c9575060018360070b13155b156102da57506000905060016103a5565b60018360070b1380156102f1575060648360070b13155b1561030257506001905060646103a5565b60648360070b13801561031a57506103e88360070b13155b1561032c5750606490506103e86103a5565b6103e88360070b13801561034557506127108360070b13155b1561035857506103e890506127106103a5565b6127108360070b1380156103725750620186a08360070b13155b1561038657506127109050620186a06103a5565b620186a08360070b13156103a55750620186a09050677fffffffffffffff5b6001935060006103d8604051806060016040528060398152602001611065603991396103d38560070b6106ac565b610613565b90506103fc8160405180606001604052806037815260200161100360379139610613565b905061040e816103d38460070b6106ac565b9050610439816040518060400160405280600781526020016622207d205d207d60c81b815250610613565b60008054600181018255908052815191925061047e917f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e5639091019060208401906108d4565b508686600060018882805480602002602001604051908101604052809291908181526020016000905b828210156105535783829060005260206000200180546104c690610e5a565b80601f01602080910402602001604051908101604052809291908181526020018280546104f290610e5a565b801561053f5780601f106105145761010080835404028352916020019161053f565b820191906000526020600020905b81548152906001019060200180831161052257829003601f168201915b5050505050815260200190600101906104a7565b50505050925081805461056590610e5a565b80601f016020809104026020016040519081016040528092919081815260200182805461059190610e5a565b80156105de5780601f106105b3576101008083540402835291602001916105de565b820191906000526020600020905b8154815290600101906020018083116105c157829003601f168201915b505050505091509b509b509b509b509b50505050505050509295509295909350565b600061060d82600061071e565b92915050565b60606000838360405160200161062a929190610e95565b60408051808303601f19018152919052949350505050565b600080600080600087878760405160200161065f93929190610ec4565b60408051601f198184030181528282528051909350919081836020860160006103e8600019f161068e57600080fd5b8051602082015160409283019092529a909950975050505050505050565b6060600082126106cb57604051806020016040528060008152506106e6565b604051806040016040528060018152602001602d60f81b8152505b6106f76106f284610748565b61075f565b604051602001610708929190610e95565b6040516020818303038152906040529050919050565b60008163ffffffff16836000015163ffffffff1614156107405750600161060d565b50600061060d565b60008082121561075b578160000361060d565b5090565b6060600061076c836107fc565b600101905060008167ffffffffffffffff81111561078c5761078c610964565b6040519080825280601f01601f1916602001820160405280156107b6576020820181803683370190505b5090508181016020015b600019016f181899199a1a9b1b9c1cb0b131b232b360811b600a86061a8153600a85049450846107ef576107f4565b6107c0565b509392505050565b60008072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b831061083b5772184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b830492506040015b6d04ee2d6d415b85acef81000000008310610867576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc10000831061088557662386f26fc10000830492506010015b6305f5e100831061089d576305f5e100830492506008015b61271083106108b157612710830492506004015b606483106108c3576064830492506002015b600a831061060d5760010192915050565b8280546108e090610e5a565b90600052602060002090601f0160209004810192826109025760008555610948565b82601f1061091b57805160ff1916838001178555610948565b82800160010185558215610948579182015b8281111561094857825182559160200191906001019061092d565b5061075b9291505b8082111561075b5760008155600101610950565b634e487b7160e01b600052604160045260246000fd5b6040516060810167ffffffffffffffff8111828210171561099d5761099d610964565b60405290565b604051601f8201601f1916810167ffffffffffffffff811182821017156109cc576109cc610964565b604052919050565b600067ffffffffffffffff8211156109ee576109ee610964565b5060051b60200190565b803563ffffffff81168114610a0c57600080fd5b919050565b600067ffffffffffffffff831115610a2b57610a2b610964565b610a3e601f8401601f19166020016109a3565b9050828152838383011115610a5257600080fd5b828260208301376000602084830101529392505050565b600082601f830112610a7a57600080fd5b81356020610a8f610a8a836109d4565b6109a3565b82815260059290921b84018101918181019086841115610aae57600080fd5b8286015b84811015610b0357803567ffffffffffffffff811115610ad25760008081fd5b8701603f81018913610ae45760008081fd5b610af5898683013560408401610a11565b845250918301918301610ab2565b509695505050505050565b60008060408385031215610b2157600080fd5b823567ffffffffffffffff80821115610b3957600080fd5b818501915085601f830112610b4d57600080fd5b81356020610b5d610a8a836109d4565b82815260059290921b84018101918181019089841115610b7c57600080fd5b8286015b84811015610c8e57803586811115610b9757600080fd5b87016060818d03601f19011215610bad57600080fd5b610bb561097a565b610bc08683016109f8565b8152604082013588811115610bd457600080fd5b8201603f81018e13610be557600080fd5b610bf68e8883013560408401610a11565b8783015250606082013588811115610c0d57600080fd5b8083019250508c603f830112610c2257600080fd5b85820135610c32610a8a826109d4565b81815260059190911b830160400190878101908f831115610c5257600080fd5b6040850194505b82851015610c7957610c6a856109f8565b82529388019390880190610c59565b60408401525050845250918301918301610b80565b5096505086013592505080821115610ca557600080fd5b50610cb285828601610a69565b9150509250929050565b60005b83811015610cd7578181015183820152602001610cbf565b83811115610ce6576000848401525b50505050565b60008151808452610d04816020860160208601610cbc565b601f01601f19169290920160200192915050565b60a081526000610d2b60a0830188610cec565b602083820381850152610d3e8289610cec565b915083820360408501528187518084528284019150828160051b850101838a0160005b83811015610d8f57601f19878403018552610d7d838351610cec565b94860194925090850190600101610d61565b50508681036060880152610da3818a610cec565b95505050505050610db8608083018415159052565b9695505050505050565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b60008160070b8360070b6000821282677fffffffffffffff03821381151615610e1957610e19610dd8565b82677fffffffffffffff19038212811615610e3657610e36610dd8565b50019392505050565b6000600019821415610e5357610e53610dd8565b5060010190565b600181811c90821680610e6e57607f821691505b60208210811415610e8f57634e487b7160e01b600052602260045260246000fd5b50919050565b60008351610ea7818460208801610cbc565b835190830190610ebb818360208801610cbc565b01949350505050565b606081526000610ed76060830186610cec565b602083820381850152610eea8287610cec565b91506040848303818601528286518085528385019150838160051b86010184890160005b83811015610f5e57878303601f1901855281518051878552610f3288860182610cec565b91890151858303868b0152919050610f4a8183610cec565b968901969450505090860190600101610f0e565b50909b9a505050505050505050505056fe68747470733a2f2f7261772e67697468756275736572636f6e74656e742e636f6d2f6c6974656e7472792f76632d6a736f6e736368656d612f6d61696e2f646973742f736368656d61732f362d747769747465722d666f6c6c6f7765722d616d6f756e742f312d302d302e6a736f6e2f646174612f7075626c69635f6d6574726963732f666f6c6c6f776572735f636f756e7422207d2c207b2022737263223a2022246861735f776562335f6163636f756e74222c20226f70223a20223c3d222c2022647374223a2022687474703a2f2f6c6f63616c686f73743a31393532382f322f75736572732f62792f757365726e616d652f7b22616e64223a205b7b2022737263223a202224746f74616c5f666f6c6c6f77657273222c20226f70223a20223e222c2022647374223a20225468652072616e6765206f662074686520757365722773205477697474657220666f6c6c6f77657220636f756e74a26469706673582212205ac73b1873ac9a973d745ba779b9bfcef50026b13042b0bf6c8546142feec36a64736f6c634300080b0033").unwrap(), + hex::decode("608060405234801561001057600080fd5b50611148806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063e256184614610030575b600080fd5b61004361003e366004610b55565b61005d565b604051610054959493929190610d5f565b60405180910390f35b6060806060806000806040518060600160405280602e81526020016110e5602e9139905060006040518060400160405280601781526020017f5477697474657220466f6c6c6f77657220416d6f756e7400000000000000000081525090506040518060a00160405280606f8152602001610fdb606f913980516100e89160019160209091019061091b565b50600080805b8b51811015610220576101198c828151811061010c5761010c610e09565b6020026020010151610579565b1561020e57600061015f6040518060600160405280602b8152602001611081602b91398e848151811061014e5761014e610e09565b60200260200101516020015161058c565b905060006101a2826040518060400160405280601b81526020017f3f757365722e6669656c64733d7075626c69635f6d657472696373000000000081525061058c565b905060006101c98e6000815181106101bc576101bc610e09565b60200260200101516105bb565b90506000806101f184604051806060016040528060248152602001610fb7602491398561065e565b915091508115610208576102058188610e35565b96505b50505050505b8061021881610e86565b9150506100ee565b5060008060008360070b1215801561023c575060018360070b13155b1561024d5750600090506001610318565b60018360070b138015610264575060648360070b13155b156102755750600190506064610318565b60648360070b13801561028d57506103e88360070b13155b1561029f5750606490506103e8610318565b6103e88360070b1380156102b857506127108360070b13155b156102cb57506103e89050612710610318565b6127108360070b1380156102e55750620186a08360070b13155b156102f957506127109050620186a0610318565b620186a08360070b13156103185750620186a09050677fffffffffffffff5b8160070b60001415935060006103516040518060600160405280603981526020016110ac6039913961034c8560070b6106c8565b61058c565b90506103758160405180606001604052806037815260200161104a6037913961058c565b90506103878161034c8460070b6106c8565b90506103b2816040518060400160405280600781526020016622207d205d207d60c81b81525061058c565b6000805460018101825590805281519192506103f7917f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e56390910190602084019061091b565b508686600060018882805480602002602001604051908101604052809291908181526020016000905b828210156104cc57838290600052602060002001805461043f90610ea1565b80601f016020809104026020016040519081016040528092919081815260200182805461046b90610ea1565b80156104b85780601f1061048d576101008083540402835291602001916104b8565b820191906000526020600020905b81548152906001019060200180831161049b57829003601f168201915b505050505081526020019060010190610420565b5050505092508180546104de90610ea1565b80601f016020809104026020016040519081016040528092919081815260200182805461050a90610ea1565b80156105575780601f1061052c57610100808354040283529160200191610557565b820191906000526020600020905b81548152906001019060200180831161053a57829003601f168201915b505050505091509b509b509b509b509b50505050505050509295509295909350565b600061058682600061073a565b92915050565b6060600083836040516020016105a3929190610edc565b60408051808303601f19018152919052949350505050565b60408051600180825281830190925260609160009190816020015b60408051808201909152606080825260208201528152602001906001900390816105d657505060408051608081018252600d9181019182526c30baba3437b934bd30ba34b7b760991b60608201529081529091506020810161063785610764565b8152508160008151811061064d5761064d610e09565b602090810291909101015292915050565b600080600080600087878760405160200161067b93929190610f0b565b60408051601f198184030181528282528051909350919081836020860160006103e8600019f16106aa57600080fd5b8051602082015160409283019092529a909950975050505050505050565b6060600082126106e75760405180602001604052806000815250610702565b604051806040016040528060018152602001602d60f81b8152505b61071361070e8461078f565b6107a6565b604051602001610724929190610edc565b6040516020818303038152906040529050919050565b60008163ffffffff16836000015163ffffffff16141561075c57506001610586565b506000610586565b60606105866040518060400160405280600781526020016602132b0b932b9160cd1b8152508361058c565b6000808212156107a25781600003610586565b5090565b606060006107b383610843565b600101905060008167ffffffffffffffff8111156107d3576107d36109ab565b6040519080825280601f01601f1916602001820160405280156107fd576020820181803683370190505b5090508181016020015b600019016f181899199a1a9b1b9c1cb0b131b232b360811b600a86061a8153600a85049450846108365761083b565b610807565b509392505050565b60008072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b83106108825772184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b830492506040015b6d04ee2d6d415b85acef810000000083106108ae576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc1000083106108cc57662386f26fc10000830492506010015b6305f5e10083106108e4576305f5e100830492506008015b61271083106108f857612710830492506004015b6064831061090a576064830492506002015b600a83106105865760010192915050565b82805461092790610ea1565b90600052602060002090601f016020900481019282610949576000855561098f565b82601f1061096257805160ff191683800117855561098f565b8280016001018555821561098f579182015b8281111561098f578251825591602001919060010190610974565b506107a29291505b808211156107a25760008155600101610997565b634e487b7160e01b600052604160045260246000fd5b6040516060810167ffffffffffffffff811182821017156109e4576109e46109ab565b60405290565b604051601f8201601f1916810167ffffffffffffffff81118282101715610a1357610a136109ab565b604052919050565b600067ffffffffffffffff821115610a3557610a356109ab565b5060051b60200190565b803563ffffffff81168114610a5357600080fd5b919050565b600067ffffffffffffffff831115610a7257610a726109ab565b610a85601f8401601f19166020016109ea565b9050828152838383011115610a9957600080fd5b828260208301376000602084830101529392505050565b600082601f830112610ac157600080fd5b81356020610ad6610ad183610a1b565b6109ea565b82815260059290921b84018101918181019086841115610af557600080fd5b8286015b84811015610b4a57803567ffffffffffffffff811115610b195760008081fd5b8701603f81018913610b2b5760008081fd5b610b3c898683013560408401610a58565b845250918301918301610af9565b509695505050505050565b60008060408385031215610b6857600080fd5b823567ffffffffffffffff80821115610b8057600080fd5b818501915085601f830112610b9457600080fd5b81356020610ba4610ad183610a1b565b82815260059290921b84018101918181019089841115610bc357600080fd5b8286015b84811015610cd557803586811115610bde57600080fd5b87016060818d03601f19011215610bf457600080fd5b610bfc6109c1565b610c07868301610a3f565b8152604082013588811115610c1b57600080fd5b8201603f81018e13610c2c57600080fd5b610c3d8e8883013560408401610a58565b8783015250606082013588811115610c5457600080fd5b8083019250508c603f830112610c6957600080fd5b85820135610c79610ad182610a1b565b81815260059190911b830160400190878101908f831115610c9957600080fd5b6040850194505b82851015610cc057610cb185610a3f565b82529388019390880190610ca0565b60408401525050845250918301918301610bc7565b5096505086013592505080821115610cec57600080fd5b50610cf985828601610ab0565b9150509250929050565b60005b83811015610d1e578181015183820152602001610d06565b83811115610d2d576000848401525b50505050565b60008151808452610d4b816020860160208601610d03565b601f01601f19169290920160200192915050565b60a081526000610d7260a0830188610d33565b602083820381850152610d858289610d33565b915083820360408501528187518084528284019150828160051b850101838a0160005b83811015610dd657601f19878403018552610dc4838351610d33565b94860194925090850190600101610da8565b50508681036060880152610dea818a610d33565b95505050505050610dff608083018415159052565b9695505050505050565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b60008160070b8360070b6000821282677fffffffffffffff03821381151615610e6057610e60610e1f565b82677fffffffffffffff19038212811615610e7d57610e7d610e1f565b50019392505050565b6000600019821415610e9a57610e9a610e1f565b5060010190565b600181811c90821680610eb557607f821691505b60208210811415610ed657634e487b7160e01b600052602260045260246000fd5b50919050565b60008351610eee818460208801610d03565b835190830190610f02818360208801610d03565b01949350505050565b606081526000610f1e6060830186610d33565b602083820381850152610f318287610d33565b91506040848303818601528286518085528385019150838160051b86010184890160005b83811015610fa557878303601f1901855281518051878552610f7988860182610d33565b91890151858303868b0152919050610f918183610d33565b968901969450505090860190600101610f55565b50909b9a505050505050505050505056fe2f646174612f7075626c69635f6d6574726963732f666f6c6c6f776572735f636f756e7468747470733a2f2f7261772e67697468756275736572636f6e74656e742e636f6d2f6c6974656e7472792f76632d6a736f6e736368656d612f6d61696e2f646973742f736368656d61732f362d747769747465722d666f6c6c6f7765722d616d6f756e742f312d312d312e6a736f6e22207d2c207b2022737263223a2022246861735f776562335f6163636f756e74222c20226f70223a20223c3d222c2022647374223a2022687474703a2f2f6c6f63616c686f73743a31393532382f322f75736572732f62792f757365726e616d652f7b22616e64223a205b7b2022737263223a202224746f74616c5f666f6c6c6f77657273222c20226f70223a20223e222c2022647374223a20225468652072616e6765206f662074686520757365722773205477697474657220666f6c6c6f77657220636f756e74a264697066735822122043552c15b5a126b734447b17ad16ec5cb3b87a35973c7763e655f3e13e9a32db64736f6c634300080b0033").unwrap(), vec!["twitter_api_key".to_string()] ) ); From 8e4fc96084a5a570afcdd2b41c89d937ea64d4c1 Mon Sep 17 00:00:00 2001 From: Kasper Ziemianek Date: Fri, 7 Jun 2024 17:59:15 +0200 Subject: [PATCH 05/10] Create `bitacross` sealed files relative to `data-dir` (#2781) * init relayers file relatively to data-dir * init signers file relatively to data-dir * init enclaves file relatively to data-dir * fix sealing empty state --------- Co-authored-by: Kai <7630809+Kailai-Wang@users.noreply.github.com> --- bitacross-worker/Cargo.lock | 3 + .../src/indirect_calls/invoke.rs | 15 ++- .../indirect_calls/litentry/args_executor.rs | 33 +++++- .../litentry/scheduled_enclave.rs | 27 ++++- .../src/indirect_calls/shield_funds.rs | 15 ++- .../src/indirect_calls/timestamp_set.rs | 16 ++- .../transfer_to_alice_shields_funds.rs | 15 ++- .../src/integritee/event_handler.rs | 32 +++++- .../src/integritee/mod.rs | 104 +++++++++++++----- .../src/target_a/event_handler.rs | 32 +++++- .../parentchain-interface/src/target_a/mod.rs | 15 ++- .../src/target_b/event_handler.rs | 22 +++- .../parentchain-interface/src/target_b/mod.rs | 15 ++- .../core/bc-enclave-registry/src/lib.rs | 47 +++----- .../core/bc-relayer-registry/src/lib.rs | 36 ++---- .../core/bc-signer-registry/src/lib.rs | 35 +++--- .../stf-primitives/src/traits.rs | 8 +- .../core-primitives/types/src/parentchain.rs | 4 +- .../indirect-calls-executor/Cargo.toml | 9 ++ .../indirect-calls-executor/src/executor.rs | 84 +++++++++++++- .../src/filter_metadata.rs | 8 +- .../indirect-calls-executor/src/mock.rs | 76 +++++++++++-- .../indirect-calls-executor/src/traits.rs | 8 +- bitacross-worker/enclave-runtime/Cargo.lock | 3 + .../src/initialization/global_components.rs | 22 ++++ .../enclave-runtime/src/initialization/mod.rs | 37 +++++-- .../src/initialization/parentchain/common.rs | 21 +++- .../src/tls_ra/tls_ra_client.rs | 22 +++- .../src/tls_ra/tls_ra_server.rs | 23 +++- 29 files changed, 612 insertions(+), 175 deletions(-) diff --git a/bitacross-worker/Cargo.lock b/bitacross-worker/Cargo.lock index 181eab9c2a..5bb3fede85 100644 --- a/bitacross-worker/Cargo.lock +++ b/bitacross-worker/Cargo.lock @@ -3078,6 +3078,9 @@ dependencies = [ name = "itc-parentchain-indirect-calls-executor" version = "0.9.0" dependencies = [ + "bc-enclave-registry", + "bc-relayer-registry", + "bc-signer-registry", "binary-merkle-tree", "bs58", "env_logger", diff --git a/bitacross-worker/app-libs/parentchain-interface/src/indirect_calls/invoke.rs b/bitacross-worker/app-libs/parentchain-interface/src/indirect_calls/invoke.rs index af3bb0c088..0b7ae16dba 100644 --- a/bitacross-worker/app-libs/parentchain-interface/src/indirect_calls/invoke.rs +++ b/bitacross-worker/app-libs/parentchain-interface/src/indirect_calls/invoke.rs @@ -15,6 +15,9 @@ */ +use bc_enclave_registry::EnclaveRegistry; +use bc_relayer_registry::RelayerRegistry; +use bc_signer_registry::SignerRegistry; use codec::{Decode, Encode}; use ita_stf::TrustedCallSigned; use itc_parentchain_indirect_calls_executor::{ @@ -29,8 +32,16 @@ pub struct InvokeArgs { request: RsaRequest, } -impl> - IndirectDispatch for InvokeArgs +impl< + Executor: IndirectExecutor< + TrustedCallSigned, + Error, + RelayerRegistry, + SignerRegistry, + EnclaveRegistry, + >, + > IndirectDispatch + for InvokeArgs { type Args = (); fn dispatch(&self, executor: &Executor, _args: Self::Args) -> Result<()> { diff --git a/bitacross-worker/app-libs/parentchain-interface/src/indirect_calls/litentry/args_executor.rs b/bitacross-worker/app-libs/parentchain-interface/src/indirect_calls/litentry/args_executor.rs index 4bdb352aa7..546094bb46 100644 --- a/bitacross-worker/app-libs/parentchain-interface/src/indirect_calls/litentry/args_executor.rs +++ b/bitacross-worker/app-libs/parentchain-interface/src/indirect_calls/litentry/args_executor.rs @@ -14,6 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Litentry. If not, see . +use bc_enclave_registry::EnclaveRegistry; +use bc_relayer_registry::RelayerRegistry; +use bc_signer_registry::SignerRegistry; use codec::Encode; use ita_stf::{Getter, TrustedCall, TrustedCallSigned}; use itc_parentchain_indirect_calls_executor::error::{Error, Result}; @@ -26,13 +29,29 @@ pub trait ArgsExecutor { fn error(&self) -> Error; fn name() -> &'static str; fn shard(&self) -> ShardIdentifier; - fn prepare_trusted_call>( + fn prepare_trusted_call< + Executor: IndirectExecutor< + TrustedCallSigned, + Error, + RelayerRegistry, + SignerRegistry, + EnclaveRegistry, + >, + >( &self, executor: &Executor, address: MultiAddress, hash: H256, ) -> Result; - fn execute>( + fn execute< + Executor: IndirectExecutor< + TrustedCallSigned, + Error, + RelayerRegistry, + SignerRegistry, + EnclaveRegistry, + >, + >( &self, executor: &Executor, address: Option>, @@ -44,7 +63,15 @@ pub trait ArgsExecutor { Ok(()) } - fn submit>( + fn submit< + Executor: IndirectExecutor< + TrustedCallSigned, + Error, + RelayerRegistry, + SignerRegistry, + EnclaveRegistry, + >, + >( &self, executor: &Executor, address: MultiAddress, diff --git a/bitacross-worker/app-libs/parentchain-interface/src/indirect_calls/litentry/scheduled_enclave.rs b/bitacross-worker/app-libs/parentchain-interface/src/indirect_calls/litentry/scheduled_enclave.rs index 885fab3b17..6cae72ca94 100644 --- a/bitacross-worker/app-libs/parentchain-interface/src/indirect_calls/litentry/scheduled_enclave.rs +++ b/bitacross-worker/app-libs/parentchain-interface/src/indirect_calls/litentry/scheduled_enclave.rs @@ -14,6 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Litentry. If not, see . +use bc_enclave_registry::EnclaveRegistry; +use bc_relayer_registry::RelayerRegistry; +use bc_signer_registry::SignerRegistry; use codec::{Decode, Encode}; use ita_stf::TrustedCallSigned; use itc_parentchain_indirect_calls_executor::{ @@ -32,8 +35,16 @@ pub struct SetScheduledEnclaveArgs { mrenclave: MrEnclave, } -impl> - IndirectDispatch for SetScheduledEnclaveArgs +impl< + Executor: IndirectExecutor< + TrustedCallSigned, + Error, + RelayerRegistry, + SignerRegistry, + EnclaveRegistry, + >, + > IndirectDispatch + for SetScheduledEnclaveArgs { type Args = (); fn dispatch(&self, _executor: &Executor, _args: Self::Args) -> Result<()> { @@ -53,8 +64,16 @@ pub struct RemoveScheduledEnclaveArgs { sbn: SidechainBlockNumber, } -impl> - IndirectDispatch for RemoveScheduledEnclaveArgs +impl< + Executor: IndirectExecutor< + TrustedCallSigned, + Error, + RelayerRegistry, + SignerRegistry, + EnclaveRegistry, + >, + > IndirectDispatch + for RemoveScheduledEnclaveArgs { type Args = (); fn dispatch(&self, _executor: &Executor, _args: Self::Args) -> Result<()> { diff --git a/bitacross-worker/app-libs/parentchain-interface/src/indirect_calls/shield_funds.rs b/bitacross-worker/app-libs/parentchain-interface/src/indirect_calls/shield_funds.rs index 5567839deb..49f6fd1dc0 100644 --- a/bitacross-worker/app-libs/parentchain-interface/src/indirect_calls/shield_funds.rs +++ b/bitacross-worker/app-libs/parentchain-interface/src/indirect_calls/shield_funds.rs @@ -15,6 +15,9 @@ */ +use bc_enclave_registry::EnclaveRegistry; +use bc_relayer_registry::RelayerRegistry; +use bc_signer_registry::SignerRegistry; use codec::{Decode, Encode}; use ita_stf::{Getter, TrustedCall, TrustedCallSigned}; use itc_parentchain_indirect_calls_executor::{ @@ -37,8 +40,16 @@ pub struct ShieldFundsArgs { shard: ShardIdentifier, } -impl> - IndirectDispatch for ShieldFundsArgs +impl< + Executor: IndirectExecutor< + TrustedCallSigned, + Error, + RelayerRegistry, + SignerRegistry, + EnclaveRegistry, + >, + > IndirectDispatch + for ShieldFundsArgs { type Args = (); fn dispatch(&self, executor: &Executor, _args: Self::Args) -> Result<()> { diff --git a/bitacross-worker/app-libs/parentchain-interface/src/indirect_calls/timestamp_set.rs b/bitacross-worker/app-libs/parentchain-interface/src/indirect_calls/timestamp_set.rs index c1c534298f..c7b9e60889 100644 --- a/bitacross-worker/app-libs/parentchain-interface/src/indirect_calls/timestamp_set.rs +++ b/bitacross-worker/app-libs/parentchain-interface/src/indirect_calls/timestamp_set.rs @@ -16,6 +16,9 @@ */ use crate::{Litentry, ParentchainInstance, TargetA, TargetB}; +use bc_enclave_registry::EnclaveRegistry; +use bc_relayer_registry::RelayerRegistry; +use bc_signer_registry::SignerRegistry; use codec::{Compact, Decode, Encode}; use core::{any::TypeId, marker::PhantomData}; use ita_stf::{Getter, TrustedCall, TrustedCallSigned}; @@ -33,8 +36,17 @@ pub struct TimestampSetArgs { _phantom: PhantomData, } -impl, I: ParentchainInstance + 'static> - IndirectDispatch for TimestampSetArgs +impl< + Executor: IndirectExecutor< + TrustedCallSigned, + Error, + RelayerRegistry, + SignerRegistry, + EnclaveRegistry, + >, + I: ParentchainInstance + 'static, + > IndirectDispatch + for TimestampSetArgs { type Args = (); fn dispatch(&self, executor: &Executor, _args: Self::Args) -> Result<()> { diff --git a/bitacross-worker/app-libs/parentchain-interface/src/indirect_calls/transfer_to_alice_shields_funds.rs b/bitacross-worker/app-libs/parentchain-interface/src/indirect_calls/transfer_to_alice_shields_funds.rs index b5474b17cb..a80e8fc159 100644 --- a/bitacross-worker/app-libs/parentchain-interface/src/indirect_calls/transfer_to_alice_shields_funds.rs +++ b/bitacross-worker/app-libs/parentchain-interface/src/indirect_calls/transfer_to_alice_shields_funds.rs @@ -15,6 +15,9 @@ */ +use bc_enclave_registry::EnclaveRegistry; +use bc_relayer_registry::RelayerRegistry; +use bc_signer_registry::SignerRegistry; use codec::{Decode, Encode}; use core::fmt::Debug; use ita_stf::{Getter, TrustedCall, TrustedCallSigned}; @@ -58,8 +61,16 @@ pub const ALICE_ACCOUNT_ID: AccountId = AccountId::new([ 76, 205, 227, 154, 86, 132, 231, 165, 109, 162, 125, ]); -impl> - IndirectDispatch for TransferToAliceShieldsFundsArgs +impl< + Executor: IndirectExecutor< + TrustedCallSigned, + Error, + RelayerRegistry, + SignerRegistry, + EnclaveRegistry, + >, + > IndirectDispatch + for TransferToAliceShieldsFundsArgs { type Args = (); fn dispatch(&self, executor: &Executor, _args: Self::Args) -> Result<()> { diff --git a/bitacross-worker/app-libs/parentchain-interface/src/integritee/event_handler.rs b/bitacross-worker/app-libs/parentchain-interface/src/integritee/event_handler.rs index cff2f7a973..1441f699ac 100644 --- a/bitacross-worker/app-libs/parentchain-interface/src/integritee/event_handler.rs +++ b/bitacross-worker/app-libs/parentchain-interface/src/integritee/event_handler.rs @@ -15,8 +15,11 @@ */ +use bc_relayer_registry::RelayerRegistry; +use bc_signer_registry::SignerRegistry; use codec::Encode; +use bc_enclave_registry::EnclaveRegistry; pub use ita_sgx_runtime::{Balance, Index}; use ita_stf::{Getter, TrustedCall, TrustedCallSigned}; use itc_parentchain_indirect_calls_executor::error::Error; @@ -30,7 +33,15 @@ use log::*; pub struct ParentchainEventHandler {} impl ParentchainEventHandler { - fn shield_funds>( + fn shield_funds< + Executor: IndirectExecutor< + TrustedCallSigned, + Error, + RelayerRegistry, + SignerRegistry, + EnclaveRegistry, + >, + >( executor: &Executor, account: &AccountId, amount: Balance, @@ -55,10 +66,23 @@ impl ParentchainEventHandler { } } -impl HandleParentchainEvents - for ParentchainEventHandler +impl + HandleParentchainEvents< + Executor, + TrustedCallSigned, + Error, + RelayerRegistry, + SignerRegistry, + EnclaveRegistry, + > for ParentchainEventHandler where - Executor: IndirectExecutor, + Executor: IndirectExecutor< + TrustedCallSigned, + Error, + RelayerRegistry, + SignerRegistry, + EnclaveRegistry, + >, { fn handle_events( executor: &Executor, diff --git a/bitacross-worker/app-libs/parentchain-interface/src/integritee/mod.rs b/bitacross-worker/app-libs/parentchain-interface/src/integritee/mod.rs index 62beed6de5..00ee82bd3e 100644 --- a/bitacross-worker/app-libs/parentchain-interface/src/integritee/mod.rs +++ b/bitacross-worker/app-libs/parentchain-interface/src/integritee/mod.rs @@ -23,9 +23,9 @@ use crate::{ extrinsic_parser::{ExtrinsicParser, ParseExtrinsic, SemiOpaqueExtrinsic}, indirect_calls::{RemoveScheduledEnclaveArgs, SetScheduledEnclaveArgs}, }; -use bc_enclave_registry::{EnclaveRegistryUpdater, GLOBAL_ENCLAVE_REGISTRY}; -use bc_relayer_registry::{RelayerRegistryUpdater, GLOBAL_RELAYER_REGISTRY}; -use bc_signer_registry::{SignerRegistryUpdater, GLOBAL_SIGNER_REGISTRY}; +use bc_enclave_registry::{EnclaveRegistry, EnclaveRegistryUpdater}; +use bc_relayer_registry::{RelayerRegistry, RelayerRegistryUpdater}; +use bc_signer_registry::{SignerRegistry, SignerRegistryUpdater}; use codec::{Decode, Encode}; use core::str::from_utf8; pub use event_filter::FilterableEvents; @@ -74,8 +74,16 @@ pub enum IndirectCall { SaveSigner(SaveSignerArgs), } -impl> - IndirectDispatch for IndirectCall +impl< + Executor: IndirectExecutor< + TrustedCallSigned, + Error, + RelayerRegistry, + SignerRegistry, + EnclaveRegistry, + >, + > IndirectDispatch + for IndirectCall { type Args = (); fn dispatch(&self, executor: &Executor, _args: Self::Args) -> Result<()> { @@ -100,13 +108,21 @@ pub struct AddRelayerArgs { account_id: Identity, } -impl> - IndirectDispatch for AddRelayerArgs +impl< + Executor: IndirectExecutor< + TrustedCallSigned, + Error, + RelayerRegistry, + SignerRegistry, + EnclaveRegistry, + >, + > IndirectDispatch + for AddRelayerArgs { type Args = (); - fn dispatch(&self, _executor: &Executor, _args: Self::Args) -> Result<()> { + fn dispatch(&self, executor: &Executor, _args: Self::Args) -> Result<()> { log::info!("Adding Relayer Account to Registry: {:?}", self.account_id); - GLOBAL_RELAYER_REGISTRY.update(self.account_id.clone()).unwrap(); + executor.get_relayer_registry_updater().update(self.account_id.clone()).unwrap(); Ok(()) } } @@ -116,13 +132,21 @@ pub struct RemoveRelayerArgs { account_id: Identity, } -impl> - IndirectDispatch for RemoveRelayerArgs +impl< + Executor: IndirectExecutor< + TrustedCallSigned, + Error, + RelayerRegistry, + SignerRegistry, + EnclaveRegistry, + >, + > IndirectDispatch + for RemoveRelayerArgs { type Args = (); - fn dispatch(&self, _executor: &Executor, _args: Self::Args) -> Result<()> { - log::info!("Remove Relayer Account from Registry: {:?}", self.account_id); - GLOBAL_RELAYER_REGISTRY.remove(self.account_id.clone()).unwrap(); + fn dispatch(&self, executor: &Executor, _args: Self::Args) -> Result<()> { + log::info!("Removing Relayer Account from Registry: {:?}", self.account_id); + executor.get_relayer_registry_updater().remove(self.account_id.clone()).unwrap(); Ok(()) } } @@ -155,24 +179,44 @@ pub struct TeebagRegisterEnclaveCall { attestation_type: AttestationType, } -impl> - IndirectDispatch for SaveSignerArgs +impl< + Executor: IndirectExecutor< + TrustedCallSigned, + Error, + RelayerRegistry, + SignerRegistry, + EnclaveRegistry, + >, + > IndirectDispatch + for SaveSignerArgs { type Args = (); - fn dispatch(&self, _executor: &Executor, _args: Self::Args) -> Result<()> { + fn dispatch(&self, executor: &Executor, _args: Self::Args) -> Result<()> { log::info!("Save signer : {:?}, pub_key: {:?}", self.account_id, self.pub_key); - GLOBAL_SIGNER_REGISTRY.update(self.account_id, self.pub_key).unwrap(); + executor + .get_signer_registry_updater() + .update(self.account_id, self.pub_key) + .unwrap(); Ok(()) } } -impl> - IndirectDispatch for RegisterEnclaveArgs +impl< + Executor: IndirectExecutor< + TrustedCallSigned, + Error, + RelayerRegistry, + SignerRegistry, + EnclaveRegistry, + >, + > IndirectDispatch + for RegisterEnclaveArgs { type Args = (); - fn dispatch(&self, _executor: &Executor, _args: Self::Args) -> Result<()> { + fn dispatch(&self, executor: &Executor, _args: Self::Args) -> Result<()> { log::info!("Register enclave : {:?}", self.account_id); - GLOBAL_ENCLAVE_REGISTRY + executor + .get_enclave_registry_updater() .update(self.account_id, from_utf8(&self.worker_url).unwrap().to_string()) .unwrap(); Ok(()) @@ -184,13 +228,21 @@ pub struct UnregisterEnclaveArgs { account_id: Address32, } -impl> - IndirectDispatch for UnregisterEnclaveArgs +impl< + Executor: IndirectExecutor< + TrustedCallSigned, + Error, + RelayerRegistry, + SignerRegistry, + EnclaveRegistry, + >, + > IndirectDispatch + for UnregisterEnclaveArgs { type Args = (); - fn dispatch(&self, _executor: &Executor, _args: Self::Args) -> Result<()> { + fn dispatch(&self, executor: &Executor, _args: Self::Args) -> Result<()> { log::info!("Unregister enclave : {:?}", self.account_id); - GLOBAL_ENCLAVE_REGISTRY.remove(self.account_id).unwrap(); + executor.get_enclave_registry_updater().remove(self.account_id).unwrap(); Ok(()) } } diff --git a/bitacross-worker/app-libs/parentchain-interface/src/target_a/event_handler.rs b/bitacross-worker/app-libs/parentchain-interface/src/target_a/event_handler.rs index 0a24999849..06f95fe1aa 100644 --- a/bitacross-worker/app-libs/parentchain-interface/src/target_a/event_handler.rs +++ b/bitacross-worker/app-libs/parentchain-interface/src/target_a/event_handler.rs @@ -15,9 +15,12 @@ */ +use bc_relayer_registry::RelayerRegistry; +use bc_signer_registry::SignerRegistry; use codec::Encode; pub use ita_sgx_runtime::{Balance, Index}; +use bc_enclave_registry::EnclaveRegistry; use ita_stf::{Getter, TrustedCall, TrustedCallSigned}; use itc_parentchain_indirect_calls_executor::error::Error; use itp_stf_primitives::{traits::IndirectExecutor, types::TrustedOperation}; @@ -30,7 +33,15 @@ use log::*; pub struct ParentchainEventHandler {} impl ParentchainEventHandler { - fn shield_funds>( + fn shield_funds< + Executor: IndirectExecutor< + TrustedCallSigned, + Error, + RelayerRegistry, + SignerRegistry, + EnclaveRegistry, + >, + >( executor: &Executor, account: &AccountId, amount: Balance, @@ -55,10 +66,23 @@ impl ParentchainEventHandler { } } -impl HandleParentchainEvents - for ParentchainEventHandler +impl + HandleParentchainEvents< + Executor, + TrustedCallSigned, + Error, + RelayerRegistry, + SignerRegistry, + EnclaveRegistry, + > for ParentchainEventHandler where - Executor: IndirectExecutor, + Executor: IndirectExecutor< + TrustedCallSigned, + Error, + RelayerRegistry, + SignerRegistry, + EnclaveRegistry, + >, { fn handle_events( executor: &Executor, diff --git a/bitacross-worker/app-libs/parentchain-interface/src/target_a/mod.rs b/bitacross-worker/app-libs/parentchain-interface/src/target_a/mod.rs index 9370f7368c..971d3e55c7 100644 --- a/bitacross-worker/app-libs/parentchain-interface/src/target_a/mod.rs +++ b/bitacross-worker/app-libs/parentchain-interface/src/target_a/mod.rs @@ -23,6 +23,9 @@ use crate::{ indirect_calls::timestamp_set::TimestampSetArgs, TargetA, }; +use bc_enclave_registry::EnclaveRegistry; +use bc_relayer_registry::RelayerRegistry; +use bc_signer_registry::SignerRegistry; use codec::{Decode, Encode}; pub use event_filter::FilterableEvents; pub use event_handler::ParentchainEventHandler; @@ -46,8 +49,16 @@ pub enum IndirectCall { TimestampSet(TimestampSetArgs), } -impl> - IndirectDispatch for IndirectCall +impl< + Executor: IndirectExecutor< + TrustedCallSigned, + Error, + RelayerRegistry, + SignerRegistry, + EnclaveRegistry, + >, + > IndirectDispatch + for IndirectCall { type Args = (); fn dispatch(&self, executor: &Executor, _args: Self::Args) -> Result<()> { diff --git a/bitacross-worker/app-libs/parentchain-interface/src/target_b/event_handler.rs b/bitacross-worker/app-libs/parentchain-interface/src/target_b/event_handler.rs index 39a5555973..7c4b401291 100644 --- a/bitacross-worker/app-libs/parentchain-interface/src/target_b/event_handler.rs +++ b/bitacross-worker/app-libs/parentchain-interface/src/target_b/event_handler.rs @@ -15,8 +15,11 @@ */ +use bc_relayer_registry::RelayerRegistry; +use bc_signer_registry::SignerRegistry; pub use ita_sgx_runtime::{Balance, Index}; +use bc_enclave_registry::EnclaveRegistry; use ita_stf::TrustedCallSigned; use itc_parentchain_indirect_calls_executor::error::Error; use itp_stf_primitives::traits::IndirectExecutor; @@ -25,10 +28,23 @@ use log::*; pub struct ParentchainEventHandler {} -impl HandleParentchainEvents - for ParentchainEventHandler +impl + HandleParentchainEvents< + Executor, + TrustedCallSigned, + Error, + RelayerRegistry, + SignerRegistry, + EnclaveRegistry, + > for ParentchainEventHandler where - Executor: IndirectExecutor, + Executor: IndirectExecutor< + TrustedCallSigned, + Error, + RelayerRegistry, + SignerRegistry, + EnclaveRegistry, + >, { fn handle_events( _executor: &Executor, diff --git a/bitacross-worker/app-libs/parentchain-interface/src/target_b/mod.rs b/bitacross-worker/app-libs/parentchain-interface/src/target_b/mod.rs index 77df3b327d..2ac2843690 100644 --- a/bitacross-worker/app-libs/parentchain-interface/src/target_b/mod.rs +++ b/bitacross-worker/app-libs/parentchain-interface/src/target_b/mod.rs @@ -24,6 +24,9 @@ use crate::{ indirect_calls::timestamp_set::TimestampSetArgs, TargetB, }; +use bc_enclave_registry::EnclaveRegistry; +use bc_relayer_registry::RelayerRegistry; +use bc_signer_registry::SignerRegistry; use codec::{Decode, Encode}; pub use event_filter::FilterableEvents; pub use event_handler::ParentchainEventHandler; @@ -47,8 +50,16 @@ pub enum IndirectCall { TimestampSet(TimestampSetArgs), } -impl> - IndirectDispatch for IndirectCall +impl< + Executor: IndirectExecutor< + TrustedCallSigned, + Error, + RelayerRegistry, + SignerRegistry, + EnclaveRegistry, + >, + > IndirectDispatch + for IndirectCall { type Args = (); fn dispatch(&self, executor: &Executor, _arg: Self::Args) -> Result<()> { diff --git a/bitacross-worker/bitacross/core/bc-enclave-registry/src/lib.rs b/bitacross-worker/bitacross/core/bc-enclave-registry/src/lib.rs index 9af60f6914..f1f4c929b8 100644 --- a/bitacross-worker/bitacross/core/bc-enclave-registry/src/lib.rs +++ b/bitacross-worker/bitacross/core/bc-enclave-registry/src/lib.rs @@ -25,22 +25,14 @@ compile_error!("feature \"std\" and feature \"sgx\" cannot be enabled at the sam use sp_std::{boxed::Box, fmt::Debug}; -use lazy_static::lazy_static; use log::error; -use std::{ - collections::BTreeMap, error::Error, path::PathBuf, string::String, sync::Arc, vec::Vec, -}; +use std::{collections::BTreeMap, error::Error, path::PathBuf, string::String, vec::Vec}; #[cfg(feature = "std")] use std::sync::RwLock; #[cfg(feature = "sgx")] use std::sync::SgxRwLock as RwLock; -lazy_static! { - /// Global instance of a EnclaveRegistry - pub static ref GLOBAL_ENCLAVE_REGISTRY: Arc = Default::default(); -} - pub type EnclaveRegistryMap = BTreeMap; #[derive(Default)] @@ -49,6 +41,12 @@ pub struct EnclaveRegistry { pub seal_path: PathBuf, } +impl EnclaveRegistry { + pub fn new(base_dir: PathBuf) -> Self { + EnclaveRegistry { registry: Default::default(), seal_path: base_dir } + } +} + pub type RegistryResult = Result; use litentry_primitives::Address32; @@ -154,16 +152,13 @@ impl EnclaveRegistrySealer for EnclaveRegistry { #[cfg(feature = "sgx")] fn seal(&self, mut state: EnclaveRegistryMap) -> RegistryResult<()> { - let mut registry = GLOBAL_ENCLAVE_REGISTRY - .registry - .write() - .map_err(|_| RegistryError::PoisonLock)?; + let mut registry = self.registry.write().map_err(|_| RegistryError::PoisonLock)?; while let Some((key, val)) = state.pop_first() { registry.insert(key, val); } let enclave_seal = EnclaveRegistrySeal::new(self.seal_path.clone()); - enclave_seal.seal(&state) + enclave_seal.seal(®istry) } #[cfg(feature = "sgx")] @@ -201,18 +196,12 @@ impl EnclaveRegistryUpdater for EnclaveRegistry { "[Enclave] EnclaveRegistry file not found, creating new! {}", ENCLAVE_REGISTRY_FILE ); - let registry = GLOBAL_ENCLAVE_REGISTRY - .registry - .write() - .map_err(|_| RegistryError::PoisonLock)?; + let registry = self.registry.write().map_err(|_| RegistryError::PoisonLock)?; enclave_seal.seal(&*registry) } else { let m = enclave_seal.unseal()?; info!("[Enclave] EnclaveRegistry unsealed from file: {:?}", m); - let mut registry = GLOBAL_ENCLAVE_REGISTRY - .registry - .write() - .map_err(|_| RegistryError::PoisonLock)?; + let mut registry = self.registry.write().map_err(|_| RegistryError::PoisonLock)?; *registry = m; Ok(()) } @@ -220,20 +209,14 @@ impl EnclaveRegistryUpdater for EnclaveRegistry { #[cfg(feature = "sgx")] fn update(&self, account: Address32, worker_url: String) -> RegistryResult<()> { - let mut registry = GLOBAL_ENCLAVE_REGISTRY - .registry - .write() - .map_err(|_| RegistryError::PoisonLock)?; + let mut registry = self.registry.write().map_err(|_| RegistryError::PoisonLock)?; registry.insert(account, worker_url); EnclaveRegistrySeal::new(self.seal_path.clone()).seal(&*registry) } #[cfg(feature = "sgx")] fn remove(&self, account: Address32) -> RegistryResult<()> { - let mut registry = GLOBAL_ENCLAVE_REGISTRY - .registry - .write() - .map_err(|_| RegistryError::PoisonLock)?; + let mut registry = self.registry.write().map_err(|_| RegistryError::PoisonLock)?; let old_value = registry.remove(&account); if old_value.is_some() { return EnclaveRegistrySeal::new(self.seal_path.clone()).seal(&*registry) @@ -258,14 +241,14 @@ impl EnclaveRegistryLookup for EnclaveRegistry { #[cfg(feature = "sgx")] fn contains_key(&self, account: &Address32) -> bool { // Using unwrap becaused poisoned locks are unrecoverable errors - let registry = GLOBAL_ENCLAVE_REGISTRY.registry.read().unwrap(); + let registry = self.registry.read().unwrap(); registry.contains_key(account) } #[cfg(feature = "sgx")] fn get_all(&self) -> Vec<(Address32, String)> { // Using unwrap becaused poisoned locks are unrecoverable errors - let registry = GLOBAL_ENCLAVE_REGISTRY.registry.read().unwrap(); + let registry = self.registry.read().unwrap(); registry.iter().map(|(k, v)| (k.clone(), v.clone())).collect() } } diff --git a/bitacross-worker/bitacross/core/bc-relayer-registry/src/lib.rs b/bitacross-worker/bitacross/core/bc-relayer-registry/src/lib.rs index 338489ddbf..4736bd1038 100644 --- a/bitacross-worker/bitacross/core/bc-relayer-registry/src/lib.rs +++ b/bitacross-worker/bitacross/core/bc-relayer-registry/src/lib.rs @@ -25,21 +25,15 @@ compile_error!("feature \"std\" and feature \"sgx\" cannot be enabled at the sam use sp_std::{boxed::Box, fmt::Debug}; -use lazy_static::lazy_static; use litentry_primitives::Identity; use log::error; -use std::{collections::BTreeMap, path::PathBuf, sync::Arc}; +use std::{collections::BTreeMap, path::PathBuf}; #[cfg(feature = "std")] use std::sync::RwLock; #[cfg(feature = "sgx")] use std::sync::SgxRwLock as RwLock; -lazy_static! { - /// Global instance of a RelayerRegistry - pub static ref GLOBAL_RELAYER_REGISTRY: Arc = Default::default(); -} - pub type RelayerRegistryMap = BTreeMap; #[derive(Default)] @@ -48,6 +42,12 @@ pub struct RelayerRegistry { pub seal_path: PathBuf, } +impl RelayerRegistry { + pub fn new(base_dir: PathBuf) -> Self { + RelayerRegistry { registry: Default::default(), seal_path: base_dir } + } +} + pub type RegistryResult = core::result::Result; #[cfg(feature = "sgx")] @@ -161,18 +161,12 @@ impl RelayerRegistryUpdater for RelayerRegistry { "[Enclave] RelayerRegistry file not found, creating new! {}", RELAYER_REGISTRY_FILE ); - let registry = GLOBAL_RELAYER_REGISTRY - .registry - .write() - .map_err(|_| RegistryError::PoisonLock)?; + let registry = self.registry.write().map_err(|_| RegistryError::PoisonLock)?; enclave_seal.seal(&*registry) } else { let m = enclave_seal.unseal()?; info!("[Enclave] RelayerRegistry unsealed from file: {:?}", m); - let mut registry = GLOBAL_RELAYER_REGISTRY - .registry - .write() - .map_err(|_| RegistryError::PoisonLock)?; + let mut registry = self.registry.write().map_err(|_| RegistryError::PoisonLock)?; *registry = m; Ok(()) } @@ -180,20 +174,14 @@ impl RelayerRegistryUpdater for RelayerRegistry { #[cfg(feature = "sgx")] fn update(&self, account: Identity) -> RegistryResult<()> { - let mut registry = GLOBAL_RELAYER_REGISTRY - .registry - .write() - .map_err(|_| RegistryError::PoisonLock)?; + let mut registry = self.registry.write().map_err(|_| RegistryError::PoisonLock)?; registry.insert(account, ()); RelayerRegistrySeal::new(self.seal_path.clone()).seal(&*registry) } #[cfg(feature = "sgx")] fn remove(&self, account: Identity) -> RegistryResult<()> { - let mut registry = GLOBAL_RELAYER_REGISTRY - .registry - .write() - .map_err(|_| RegistryError::PoisonLock)?; + let mut registry = self.registry.write().map_err(|_| RegistryError::PoisonLock)?; let old_value = registry.remove(&account); if old_value.is_some() { return RelayerRegistrySeal::new(self.seal_path.clone()).seal(&*registry) @@ -212,7 +200,7 @@ impl RelayerRegistryLookup for RelayerRegistry { #[cfg(feature = "sgx")] fn contains_key(&self, account: Identity) -> bool { // Using unwrap becaused poisoned locks are unrecoverable errors - let registry = GLOBAL_RELAYER_REGISTRY.registry.read().unwrap(); + let registry = self.registry.read().unwrap(); registry.contains_key(&account) } } diff --git a/bitacross-worker/bitacross/core/bc-signer-registry/src/lib.rs b/bitacross-worker/bitacross/core/bc-signer-registry/src/lib.rs index 966abba3ec..5cd6efb6de 100644 --- a/bitacross-worker/bitacross/core/bc-signer-registry/src/lib.rs +++ b/bitacross-worker/bitacross/core/bc-signer-registry/src/lib.rs @@ -25,20 +25,14 @@ compile_error!("feature \"std\" and feature \"sgx\" cannot be enabled at the sam use sp_std::{boxed::Box, fmt::Debug}; -use lazy_static::lazy_static; use log::error; -use std::{collections::BTreeMap, error::Error, path::PathBuf, sync::Arc, vec::Vec}; +use std::{collections::BTreeMap, error::Error, path::PathBuf, vec::Vec}; #[cfg(feature = "std")] use std::sync::RwLock; #[cfg(feature = "sgx")] use std::sync::SgxRwLock as RwLock; -lazy_static! { - /// Global instance of a SignerRegistry - pub static ref GLOBAL_SIGNER_REGISTRY: Arc = Default::default(); -} - pub type PubKey = [u8; 33]; pub type SignerRegistryMap = BTreeMap; @@ -49,6 +43,12 @@ pub struct SignerRegistry { pub seal_path: PathBuf, } +impl SignerRegistry { + pub fn new(base_dir: PathBuf) -> Self { + SignerRegistry { registry: Default::default(), seal_path: base_dir } + } +} + pub type RegistryResult = Result; use litentry_primitives::Address32; @@ -154,14 +154,13 @@ impl SignerRegistrySealer for SignerRegistry { #[cfg(feature = "sgx")] fn seal(&self, mut state: SignerRegistryMap) -> RegistryResult<()> { - let mut registry = - GLOBAL_SIGNER_REGISTRY.registry.write().map_err(|_| RegistryError::PoisonLock)?; + let mut registry = self.registry.write().map_err(|_| RegistryError::PoisonLock)?; while let Some((key, val)) = state.pop_first() { registry.insert(key, val); } let signer_seal = SignerRegistrySeal::new(self.seal_path.clone()); - signer_seal.seal(&state) + signer_seal.seal(®istry) } #[cfg(feature = "sgx")] @@ -196,14 +195,12 @@ impl SignerRegistryUpdater for SignerRegistry { let enclave_seal = SignerRegistrySeal::new(self.seal_path.clone()); if SgxFile::open(SIGNER_REGISTRY_FILE).is_err() { info!("[Signer] SignerRegistry file not found, creating new! {}", SIGNER_REGISTRY_FILE); - let registry = - GLOBAL_SIGNER_REGISTRY.registry.write().map_err(|_| RegistryError::PoisonLock)?; + let registry = self.registry.write().map_err(|_| RegistryError::PoisonLock)?; enclave_seal.seal(&*registry) } else { let m = enclave_seal.unseal()?; info!("[Signer] SignerRegistry unsealed from file: {:?}", m); - let mut registry = - GLOBAL_SIGNER_REGISTRY.registry.write().map_err(|_| RegistryError::PoisonLock)?; + let mut registry = self.registry.write().map_err(|_| RegistryError::PoisonLock)?; *registry = m; Ok(()) } @@ -211,16 +208,14 @@ impl SignerRegistryUpdater for SignerRegistry { #[cfg(feature = "sgx")] fn update(&self, account: Address32, key: PubKey) -> RegistryResult<()> { - let mut registry = - GLOBAL_SIGNER_REGISTRY.registry.write().map_err(|_| RegistryError::PoisonLock)?; + let mut registry = self.registry.write().map_err(|_| RegistryError::PoisonLock)?; registry.insert(account, key); SignerRegistrySeal::new(self.seal_path.clone()).seal(&*registry) } #[cfg(feature = "sgx")] fn remove(&self, account: Address32) -> RegistryResult<()> { - let mut registry = - GLOBAL_SIGNER_REGISTRY.registry.write().map_err(|_| RegistryError::PoisonLock)?; + let mut registry = self.registry.write().map_err(|_| RegistryError::PoisonLock)?; let old_value = registry.remove(&account); if old_value.is_some() { return SignerRegistrySeal::new(self.seal_path.clone()).seal(&*registry) @@ -245,14 +240,14 @@ impl SignerRegistryLookup for SignerRegistry { #[cfg(feature = "sgx")] fn contains_key(&self, account: &Address32) -> bool { // Using unwrap because poisoned locks are unrecoverable errors - let registry = GLOBAL_SIGNER_REGISTRY.registry.read().unwrap(); + let registry = self.registry.read().unwrap(); registry.contains_key(account) } #[cfg(feature = "sgx")] fn get_all(&self) -> Vec<(Address32, PubKey)> { // Using unwrap because poisoned locks are unrecoverable errors - let registry = GLOBAL_SIGNER_REGISTRY.registry.read().unwrap(); + let registry = self.registry.read().unwrap(); registry.iter().map(|(k, v)| (k.clone(), v.clone())).collect() } } diff --git a/bitacross-worker/core-primitives/stf-primitives/src/traits.rs b/bitacross-worker/core-primitives/stf-primitives/src/traits.rs index eaad1e3563..7193a5ea34 100644 --- a/bitacross-worker/core-primitives/stf-primitives/src/traits.rs +++ b/bitacross-worker/core-primitives/stf-primitives/src/traits.rs @@ -54,7 +54,7 @@ pub trait PoolTransactionValidation { /// Trait to be implemented on the executor to serve helper methods of the executor /// to the `IndirectDispatch` implementation. -pub trait IndirectExecutor +pub trait IndirectExecutor where TCS: PartialEq + Encode + Decode + Debug + Clone + Send + Sync + TrustedCallVerification, { @@ -73,4 +73,10 @@ where trusted_call: &TC, shard: &ShardIdentifier, ) -> Result; + + fn get_relayer_registry_updater(&self) -> &RRU; + + fn get_signer_registry_updater(&self) -> &SRU; + + fn get_enclave_registry_updater(&self) -> &ERU; } diff --git a/bitacross-worker/core-primitives/types/src/parentchain.rs b/bitacross-worker/core-primitives/types/src/parentchain.rs index b73ebc4f83..a4be35a7dc 100644 --- a/bitacross-worker/core-primitives/types/src/parentchain.rs +++ b/bitacross-worker/core-primitives/types/src/parentchain.rs @@ -164,9 +164,9 @@ impl StaticEvent for ParentchainBlockProcessed { const EVENT: &'static str = "ParentchainBlockProcessed"; } -pub trait HandleParentchainEvents +pub trait HandleParentchainEvents where - Executor: IndirectExecutor, + Executor: IndirectExecutor, TCS: PartialEq + Encode + Decode + Debug + Clone + Send + Sync + TrustedCallVerification, { fn handle_events( diff --git a/bitacross-worker/core/parentchain/indirect-calls-executor/Cargo.toml b/bitacross-worker/core/parentchain/indirect-calls-executor/Cargo.toml index b006457b3a..7bd496124e 100644 --- a/bitacross-worker/core/parentchain/indirect-calls-executor/Cargo.toml +++ b/bitacross-worker/core/parentchain/indirect-calls-executor/Cargo.toml @@ -39,6 +39,9 @@ sp-core = { default-features = false, features = ["full_crypto"], git = "https:/ sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" } # litentry +bc-enclave-registry = { path = "../../../bitacross/core/bc-enclave-registry", default-features = false } +bc-relayer-registry = { path = "../../../bitacross/core/bc-relayer-registry", default-features = false } +bc-signer-registry = { path = "../../../bitacross/core/bc-signer-registry", default-features = false } lc-scheduled-enclave = { path = "../../../litentry/core/scheduled-enclave", default-features = false, optional = true } litentry-primitives = { path = "../../../litentry/primitives", default-features = false } @@ -74,6 +77,9 @@ std = [ # litentry "litentry-primitives/std", "lc-scheduled-enclave/std", + "bc-relayer-registry/std", + "bc-signer-registry/std", + "bc-enclave-registry/std", ] sgx = [ "sgx_tstd", @@ -87,4 +93,7 @@ sgx = [ # litentry "litentry-primitives/sgx", "lc-scheduled-enclave/sgx", + "bc-relayer-registry/sgx", + "bc-signer-registry/sgx", + "bc-enclave-registry/sgx", ] diff --git a/bitacross-worker/core/parentchain/indirect-calls-executor/src/executor.rs b/bitacross-worker/core/parentchain/indirect-calls-executor/src/executor.rs index 93090a8ba0..54273d99ce 100644 --- a/bitacross-worker/core/parentchain/indirect-calls-executor/src/executor.rs +++ b/bitacross-worker/core/parentchain/indirect-calls-executor/src/executor.rs @@ -25,6 +25,9 @@ use crate::{ traits::{ExecuteIndirectCalls, IndirectDispatch}, }; use alloc::format; +use bc_enclave_registry::EnclaveRegistryUpdater; +use bc_relayer_registry::RelayerRegistryUpdater; +use bc_signer_registry::SignerRegistryUpdater; use binary_merkle_tree::merkle_root; use codec::{Decode, Encode}; use core::marker::PhantomData; @@ -57,12 +60,22 @@ pub struct IndirectCallsExecutor< ParentchainEventHandler, TCS, G, -> { + RRU, + SRU, + ERU, +> where + RRU: RelayerRegistryUpdater, + SRU: SignerRegistryUpdater, + ERU: EnclaveRegistryUpdater, +{ pub(crate) shielding_key_repo: Arc, pub stf_enclave_signer: Arc, pub(crate) top_pool_author: Arc, pub(crate) node_meta_data_provider: Arc, pub parentchain_id: ParentchainId, + pub relayer_registry_updater: Arc, + pub signer_registry_updater: Arc, + pub enclave_registry_updater: Arc, _phantom: PhantomData<(IndirectCallsFilter, EventCreator, ParentchainEventHandler, TCS, G)>, } impl< @@ -75,6 +88,9 @@ impl< ParentchainEventHandler, TCS, G, + RRU, + SRU, + ERU, > IndirectCallsExecutor< ShieldingKeyRepository, @@ -86,14 +102,24 @@ impl< ParentchainEventHandler, TCS, G, - > + RRU, + SRU, + ERU, + > where + RRU: RelayerRegistryUpdater, + SRU: SignerRegistryUpdater, + ERU: EnclaveRegistryUpdater, { + #[allow(clippy::too_many_arguments)] pub fn new( shielding_key_repo: Arc, stf_enclave_signer: Arc, top_pool_author: Arc, node_meta_data_provider: Arc, parentchain_id: ParentchainId, + relayer_registry_updater: Arc, + signer_registry_updater: Arc, + enclave_registry_updater: Arc, ) -> Self { IndirectCallsExecutor { shielding_key_repo, @@ -101,6 +127,9 @@ impl< top_pool_author, node_meta_data_provider, parentchain_id, + relayer_registry_updater, + signer_registry_updater, + enclave_registry_updater, _phantom: Default::default(), } } @@ -116,6 +145,9 @@ impl< ParentchainEventHandler, TCS, G, + RRU, + SRU, + ERU, > ExecuteIndirectCalls for IndirectCallsExecutor< ShieldingKeyRepository, @@ -127,6 +159,9 @@ impl< ParentchainEventHandler, TCS, G, + RRU, + SRU, + ERU, > where ShieldingKeyRepository: AccessKey, ::KeyType: ShieldingCryptoDecrypt @@ -136,11 +171,15 @@ impl< NodeMetadataProvider: AccessNodeMetadata, FilterIndirectCalls: FilterIntoDataFrom, NodeMetadataProvider::MetadataType: NodeMetadataTrait + Clone, - FilterIndirectCalls::Output: IndirectDispatch + Encode + Debug, + FilterIndirectCalls::Output: + IndirectDispatch + Encode + Debug, EventCreator: EventsFromMetadata, - ParentchainEventHandler: HandleParentchainEvents, + ParentchainEventHandler: HandleParentchainEvents, TCS: PartialEq + Encode + Decode + Debug + Clone + Send + Sync + TrustedCallVerification, G: PartialEq + Encode + Decode + Debug + Clone + Send + Sync, + RRU: RelayerRegistryUpdater, + SRU: SignerRegistryUpdater, + ERU: EnclaveRegistryUpdater, { fn execute_indirect_calls_in_extrinsics( &self, @@ -245,7 +284,10 @@ impl< PrivacySidechain, TCS, G, - > IndirectExecutor + RRU, + SRU, + ERU, + > IndirectExecutor for IndirectCallsExecutor< ShieldingKeyRepository, StfEnclaveSigner, @@ -256,6 +298,9 @@ impl< PrivacySidechain, TCS, G, + RRU, + SRU, + ERU, > where ShieldingKeyRepository: AccessKey, ::KeyType: ShieldingCryptoDecrypt @@ -264,6 +309,9 @@ impl< TopPoolAuthor: AuthorApi + Send + Sync + 'static, TCS: PartialEq + Encode + Decode + Debug + Clone + Send + Sync + TrustedCallVerification, G: PartialEq + Encode + Decode + Debug + Clone + Send + Sync, + RRU: RelayerRegistryUpdater, + SRU: SignerRegistryUpdater, + ERU: EnclaveRegistryUpdater, { fn submit_trusted_call(&self, shard: ShardIdentifier, encrypted_trusted_call: Vec) { if let Err(e) = futures::executor::block_on( @@ -298,6 +346,18 @@ impl< ) -> Result { Ok(self.stf_enclave_signer.sign_call_with_self(trusted_call, shard)?) } + + fn get_relayer_registry_updater(&self) -> &RRU { + self.relayer_registry_updater.as_ref() + } + + fn get_signer_registry_updater(&self) -> &SRU { + self.signer_registry_updater.as_ref() + } + + fn get_enclave_registry_updater(&self) -> &ERU { + self.enclave_registry_updater.as_ref() + } } pub fn hash_of(xt: &T) -> H256 { @@ -308,6 +368,9 @@ pub fn hash_of(xt: &T) -> H256 { mod test { use super::*; use crate::mock::*; + use bc_enclave_registry::EnclaveRegistry; + use bc_relayer_registry::RelayerRegistry; + use bc_signer_registry::SignerRegistry; use codec::Encode; use itc_parentchain_test::ParentchainBlockBuilder; use itp_node_api::{ @@ -324,7 +387,7 @@ mod test { stf_mock::{GetterMock, TrustedCallSignedMock}, }; use itp_top_pool_author::mocks::AuthorApiMock; - use itp_types::{Block, PostOpaqueTaskFn, RsaRequest, ShardIdentifier}; + use itp_types::{Block, Enclave, PostOpaqueTaskFn, RsaRequest, ShardIdentifier}; use sp_core::{ed25519, Pair}; use sp_runtime::{MultiAddress, MultiSignature, OpaqueExtrinsic}; @@ -342,6 +405,9 @@ mod test { MockParentchainEventHandler, TrustedCallSignedMock, GetterMock, + RelayerRegistry, + SignerRegistry, + EnclaveRegistry, >; type Seed = [u8; 32]; @@ -457,6 +523,9 @@ mod test { let stf_enclave_signer = Arc::new(TestStfEnclaveSigner::new(mr_enclave)); let top_pool_author = Arc::new(TestTopPoolAuthor::default()); let node_metadata_repo = Arc::new(NodeMetadataRepository::new(metadata)); + let relayer_registry = Arc::new(RelayerRegistry::new(Default::default())); + let signer_registry = Arc::new(SignerRegistry::new(Default::default())); + let enclave_registry = Arc::new(EnclaveRegistry::new(Default::default())); let executor = IndirectCallsExecutor::new( shielding_key_repo.clone(), @@ -464,6 +533,9 @@ mod test { top_pool_author.clone(), node_metadata_repo, ParentchainId::Litentry, + relayer_registry, + signer_registry, + enclave_registry, ); (executor, top_pool_author, shielding_key_repo) diff --git a/bitacross-worker/core/parentchain/indirect-calls-executor/src/filter_metadata.rs b/bitacross-worker/core/parentchain/indirect-calls-executor/src/filter_metadata.rs index 22abc50bb3..25edc70ed7 100644 --- a/bitacross-worker/core/parentchain/indirect-calls-executor/src/filter_metadata.rs +++ b/bitacross-worker/core/parentchain/indirect-calls-executor/src/filter_metadata.rs @@ -76,6 +76,9 @@ pub struct DenyAll; mod seal { use super::*; use crate::Error; + use bc_enclave_registry::EnclaveRegistry; + use bc_relayer_registry::RelayerRegistry; + use bc_signer_registry::SignerRegistry; use core::fmt::Debug; use itp_stf_primitives::traits::TrustedCallVerification; @@ -92,7 +95,10 @@ mod seal { } } - impl, TCS> IndirectDispatch for CantExecute + impl< + Executor: IndirectExecutor, + TCS, + > IndirectDispatch for CantExecute where TCS: PartialEq + Encode + Decode + Debug + Clone + Send + Sync + TrustedCallVerification, { diff --git a/bitacross-worker/core/parentchain/indirect-calls-executor/src/mock.rs b/bitacross-worker/core/parentchain/indirect-calls-executor/src/mock.rs index 57c1645cc2..1e9350d399 100644 --- a/bitacross-worker/core/parentchain/indirect-calls-executor/src/mock.rs +++ b/bitacross-worker/core/parentchain/indirect-calls-executor/src/mock.rs @@ -3,10 +3,13 @@ use crate::{ filter_metadata::{EventsFromMetadata, FilterIntoDataFrom}, IndirectDispatch, }; +use bc_relayer_registry::RelayerRegistry; +use bc_signer_registry::SignerRegistry; use codec::{Decode, Encode}; use core::marker::PhantomData; use litentry_primitives::DecryptableRequest; +use bc_enclave_registry::EnclaveRegistry; use itp_node_api::{ api_client::{CallIndex, PairSignature, UncheckedExtrinsicV4}, metadata::NodeMetadataTrait, @@ -130,8 +133,22 @@ pub enum IndirectCall { Invoke(InvokeArgs), } -impl> - IndirectDispatch for IndirectCall +impl< + Executor: IndirectExecutor< + TrustedCallSignedMock, + Error, + RelayerRegistry, + SignerRegistry, + EnclaveRegistry, + >, + > + IndirectDispatch< + Executor, + TrustedCallSignedMock, + RelayerRegistry, + SignerRegistry, + EnclaveRegistry, + > for IndirectCall { type Args = (); fn dispatch(&self, executor: &Executor, args: Self::Args) -> ICResult<()> { @@ -178,10 +195,23 @@ impl FilterEvents for MockEvents { pub struct MockParentchainEventHandler {} -impl HandleParentchainEvents - for MockParentchainEventHandler +impl + HandleParentchainEvents< + Executor, + TrustedCallSignedMock, + Error, + RelayerRegistry, + SignerRegistry, + EnclaveRegistry, + > for MockParentchainEventHandler where - Executor: IndirectExecutor, + Executor: IndirectExecutor< + TrustedCallSignedMock, + Error, + RelayerRegistry, + SignerRegistry, + EnclaveRegistry, + >, { fn handle_events( _: &Executor, @@ -200,8 +230,22 @@ pub struct ShieldFundsArgs { shard: ShardIdentifier, } -impl> - IndirectDispatch for ShieldFundsArgs +impl< + Executor: IndirectExecutor< + TrustedCallSignedMock, + Error, + RelayerRegistry, + SignerRegistry, + EnclaveRegistry, + >, + > + IndirectDispatch< + Executor, + TrustedCallSignedMock, + RelayerRegistry, + SignerRegistry, + EnclaveRegistry, + > for ShieldFundsArgs { type Args = (); fn dispatch(&self, executor: &Executor, _args: Self::Args) -> ICResult<()> { @@ -231,8 +275,22 @@ pub struct InvokeArgs { request: RsaRequest, } -impl> - IndirectDispatch for InvokeArgs +impl< + Executor: IndirectExecutor< + TrustedCallSignedMock, + Error, + RelayerRegistry, + SignerRegistry, + EnclaveRegistry, + >, + > + IndirectDispatch< + Executor, + TrustedCallSignedMock, + RelayerRegistry, + SignerRegistry, + EnclaveRegistry, + > for InvokeArgs { type Args = (); fn dispatch(&self, executor: &Executor, _args: Self::Args) -> ICResult<()> { diff --git a/bitacross-worker/core/parentchain/indirect-calls-executor/src/traits.rs b/bitacross-worker/core/parentchain/indirect-calls-executor/src/traits.rs index 0665113d6d..3ae4f61970 100644 --- a/bitacross-worker/core/parentchain/indirect-calls-executor/src/traits.rs +++ b/bitacross-worker/core/parentchain/indirect-calls-executor/src/traits.rs @@ -16,6 +16,9 @@ */ use crate::{error::Result, Error}; +use bc_enclave_registry::EnclaveRegistryUpdater; +use bc_relayer_registry::RelayerRegistryUpdater; +use bc_signer_registry::SignerRegistryUpdater; use codec::{Decode, Encode}; use core::fmt::Debug; use itp_stf_primitives::traits::{IndirectExecutor, TrustedCallVerification}; @@ -50,9 +53,12 @@ pub trait ExecuteIndirectCalls { } /// Trait that should be implemented on indirect calls to be executed. -pub trait IndirectDispatch, TCS> +pub trait IndirectDispatch, TCS, RRU, SRU, ERU> where TCS: PartialEq + Encode + Decode + Debug + Clone + Send + Sync + TrustedCallVerification, + RRU: RelayerRegistryUpdater, + SRU: SignerRegistryUpdater, + ERU: EnclaveRegistryUpdater, { type Args; fn dispatch(&self, executor: &E, args: Self::Args) -> Result<()>; diff --git a/bitacross-worker/enclave-runtime/Cargo.lock b/bitacross-worker/enclave-runtime/Cargo.lock index af57a268c2..bf84f41da0 100644 --- a/bitacross-worker/enclave-runtime/Cargo.lock +++ b/bitacross-worker/enclave-runtime/Cargo.lock @@ -2128,6 +2128,9 @@ dependencies = [ name = "itc-parentchain-indirect-calls-executor" version = "0.9.0" dependencies = [ + "bc-enclave-registry", + "bc-relayer-registry", + "bc-signer-registry", "binary-merkle-tree", "bs58", "futures 0.3.8", diff --git a/bitacross-worker/enclave-runtime/src/initialization/global_components.rs b/bitacross-worker/enclave-runtime/src/initialization/global_components.rs index b765f98cc7..fc8eba389a 100644 --- a/bitacross-worker/enclave-runtime/src/initialization/global_components.rs +++ b/bitacross-worker/enclave-runtime/src/initialization/global_components.rs @@ -31,6 +31,7 @@ use crate::{ tls_ra::seal_handler::SealHandler, }; use bc_enclave_registry::EnclaveRegistry; +use bc_relayer_registry::RelayerRegistry; use bc_signer_registry::SignerRegistry; use ita_parentchain_interface::{integritee, target_a, target_b}; use ita_sgx_runtime::Runtime; @@ -175,6 +176,9 @@ pub type IntegriteeParentchainIndirectCallsExecutor = IndirectCallsExecutor< integritee::ParentchainEventHandler, EnclaveTrustedCallSigned, EnclaveGetter, + RelayerRegistry, + SignerRegistry, + EnclaveRegistry, >; pub type IntegriteeParentchainBlockImporter = ParentchainBlockImporter< @@ -218,6 +222,9 @@ pub type TargetAParentchainIndirectCallsExecutor = IndirectCallsExecutor< target_a::ParentchainEventHandler, EnclaveTrustedCallSigned, EnclaveGetter, + RelayerRegistry, + SignerRegistry, + EnclaveRegistry, >; pub type TargetAParentchainBlockImporter = ParentchainBlockImporter< @@ -261,6 +268,9 @@ pub type TargetBParentchainIndirectCallsExecutor = IndirectCallsExecutor< target_b::ParentchainEventHandler, EnclaveTrustedCallSigned, EnclaveGetter, + RelayerRegistry, + SignerRegistry, + EnclaveRegistry, >; pub type TargetBParentchainBlockImporter = ParentchainBlockImporter< @@ -434,3 +444,15 @@ pub static GLOBAL_TARGET_B_PARACHAIN_HANDLER_COMPONENT: ComponentContainer< /// Enclave RPC WS handler. pub static GLOBAL_RPC_WS_HANDLER_COMPONENT: ComponentContainer = ComponentContainer::new("rpc_ws_handler"); + +/// Relayer registry +pub static GLOBAL_RELAYER_REGISTRY: ComponentContainer = + ComponentContainer::new("relayer_registry"); + +/// Signer registry +pub static GLOBAL_SIGNER_REGISTRY: ComponentContainer = + ComponentContainer::new("signer_registry"); + +/// Enclave registry +pub static GLOBAL_ENCLAVE_REGISTRY: ComponentContainer = + ComponentContainer::new("enclave_registry"); diff --git a/bitacross-worker/enclave-runtime/src/initialization/mod.rs b/bitacross-worker/enclave-runtime/src/initialization/mod.rs index af34a3e679..06f09cdc29 100644 --- a/bitacross-worker/enclave-runtime/src/initialization/mod.rs +++ b/bitacross-worker/enclave-runtime/src/initialization/mod.rs @@ -44,11 +44,11 @@ use crate::{ Hash, }; use base58::ToBase58; -use bc_enclave_registry::{EnclaveRegistryUpdater, GLOBAL_ENCLAVE_REGISTRY}; +use bc_enclave_registry::EnclaveRegistryUpdater; use bc_musig2_ceremony::{CeremonyRegistry, MuSig2Ceremony}; use bc_musig2_runner::init_ceremonies_thread; -use bc_relayer_registry::{RelayerRegistryUpdater, GLOBAL_RELAYER_REGISTRY}; -use bc_signer_registry::{SignerRegistryUpdater, GLOBAL_SIGNER_REGISTRY}; +use bc_relayer_registry::{RelayerRegistry, RelayerRegistryUpdater}; +use bc_signer_registry::SignerRegistryUpdater; use bc_task_receiver::{run_bit_across_handler_runner, BitAcrossTaskContext}; use codec::Encode; use ita_stf::{Getter, TrustedCallSigned}; @@ -82,6 +82,11 @@ use itp_sgx_crypto::{ schnorr::{create_schnorr_repository, Pair as SchnorrPair, Seal}, }; +use crate::initialization::global_components::{ + GLOBAL_ENCLAVE_REGISTRY, GLOBAL_RELAYER_REGISTRY, GLOBAL_SIGNER_REGISTRY, +}; +use bc_enclave_registry::EnclaveRegistry; +use bc_signer_registry::SignerRegistry; use itp_stf_state_handler::{ file_io::StateDir, handle_state::HandleState, query_shard_state::QueryShardState, state_snapshot_repository::VersionedStateAccess, @@ -148,7 +153,7 @@ pub(crate) fn init_enclave( GLOBAL_TARGET_B_PARENTCHAIN_LIGHT_CLIENT_SEAL.initialize(target_b_light_client_seal); let state_file_io = - Arc::new(EnclaveStateFileIo::new(state_key_repository, StateDir::new(base_dir))); + Arc::new(EnclaveStateFileIo::new(state_key_repository, StateDir::new(base_dir.clone()))); let state_initializer = Arc::new(EnclaveStateInitializer::new(shielding_key_repository.clone())); let state_snapshot_repository_loader = StateSnapshotRepositoryLoader::< @@ -223,9 +228,17 @@ pub(crate) fn init_enclave( Arc::new(IntelAttestationHandler::new(ocall_api.clone(), signing_key_repository.clone())); GLOBAL_ATTESTATION_HANDLER_COMPONENT.initialize(attestation_handler); - GLOBAL_RELAYER_REGISTRY.init().map_err(|e| Error::Other(e.into()))?; - GLOBAL_ENCLAVE_REGISTRY.init().map_err(|e| Error::Other(e.into()))?; - GLOBAL_SIGNER_REGISTRY.init().map_err(|e| Error::Other(e.into()))?; + let relayer_registry = RelayerRegistry::new(base_dir.clone()); + relayer_registry.init().map_err(|e| Error::Other(e.into()))?; + GLOBAL_RELAYER_REGISTRY.initialize(relayer_registry.into()); + + let signer_registry = Arc::new(SignerRegistry::new(base_dir.clone())); + signer_registry.init().map_err(|e| Error::Other(e.into()))?; + GLOBAL_SIGNER_REGISTRY.initialize(signer_registry.clone()); + + let enclave_registry = Arc::new(EnclaveRegistry::new(base_dir)); + enclave_registry.init().map_err(|e| Error::Other(e.into()))?; + GLOBAL_ENCLAVE_REGISTRY.initialize(enclave_registry.clone()); let io_handler = public_api_rpc_handler( top_pool_author, @@ -235,7 +248,7 @@ pub(crate) fn init_enclave( signing_key_repository, bitcoin_key_repository, ethereum_key_repository, - GLOBAL_SIGNER_REGISTRY.clone(), + signer_registry, ); let rpc_handler = Arc::new(RpcWsHandler::new(io_handler, watch_extractor, connection_registry)); GLOBAL_RPC_WS_HANDLER_COMPONENT.initialize(rpc_handler); @@ -253,7 +266,7 @@ pub(crate) fn init_enclave( GLOBAL_SIGNING_KEY_REPOSITORY_COMPONENT.get()?, GLOBAL_SHIELDING_KEY_REPOSITORY_COMPONENT.get()?, Arc::new(client_factory), - GLOBAL_ENCLAVE_REGISTRY.clone(), + enclave_registry, ceremony_registry_cloned, pending_ceremony_commands_cloned, ocall_api, @@ -369,9 +382,9 @@ fn run_bit_across_handler( let author_api = GLOBAL_TOP_POOL_AUTHOR_COMPONENT.get()?; let state_handler = GLOBAL_STATE_HANDLER_COMPONENT.get()?; let state_observer = GLOBAL_STATE_OBSERVER_COMPONENT.get()?; - let relayer_registry_lookup = GLOBAL_RELAYER_REGISTRY.clone(); - let enclave_registry_lookup = GLOBAL_ENCLAVE_REGISTRY.clone(); - let signer_registry_lookup = GLOBAL_SIGNER_REGISTRY.clone(); + let relayer_registry_lookup = GLOBAL_RELAYER_REGISTRY.get()?; + let enclave_registry_lookup = GLOBAL_ENCLAVE_REGISTRY.get()?; + let signer_registry_lookup = GLOBAL_SIGNER_REGISTRY.get()?; let shielding_key_repository = GLOBAL_SHIELDING_KEY_REPOSITORY_COMPONENT.get()?; let ethereum_key_repository = GLOBAL_ETHEREUM_KEY_REPOSITORY_COMPONENT.get()?; diff --git a/bitacross-worker/enclave-runtime/src/initialization/parentchain/common.rs b/bitacross-worker/enclave-runtime/src/initialization/parentchain/common.rs index 54a9ed3b67..ec6bcf4a8e 100644 --- a/bitacross-worker/enclave-runtime/src/initialization/parentchain/common.rs +++ b/bitacross-worker/enclave-runtime/src/initialization/parentchain/common.rs @@ -32,7 +32,8 @@ use crate::{ GLOBAL_STATE_HANDLER_COMPONENT, GLOBAL_STATE_OBSERVER_COMPONENT, GLOBAL_TOP_POOL_AUTHOR_COMPONENT, }, - EnclaveStfEnclaveSigner, + EnclaveStfEnclaveSigner, GLOBAL_ENCLAVE_REGISTRY, GLOBAL_RELAYER_REGISTRY, + GLOBAL_SIGNER_REGISTRY, }, }; use itp_component_container::ComponentGetter; @@ -55,6 +56,9 @@ pub(crate) fn create_integritee_parentchain_block_importer( let top_pool_author = GLOBAL_TOP_POOL_AUTHOR_COMPONENT.get()?; let shielding_key_repository = GLOBAL_SHIELDING_KEY_REPOSITORY_COMPONENT.get()?; let ocall_api = GLOBAL_OCALL_API_COMPONENT.get()?; + let relayer_registry = GLOBAL_RELAYER_REGISTRY.get()?; + let signer_registry = GLOBAL_SIGNER_REGISTRY.get()?; + let enclave_registry = GLOBAL_ENCLAVE_REGISTRY.get()?; let stf_enclave_signer = Arc::new(EnclaveStfEnclaveSigner::new( state_observer, @@ -68,6 +72,9 @@ pub(crate) fn create_integritee_parentchain_block_importer( top_pool_author, node_metadata_repository, ParentchainId::Litentry, + relayer_registry, + signer_registry, + enclave_registry, )); Ok(IntegriteeParentchainBlockImporter::new( validator_access, @@ -91,6 +98,9 @@ pub(crate) fn create_target_a_parentchain_block_importer( let top_pool_author = GLOBAL_TOP_POOL_AUTHOR_COMPONENT.get()?; let shielding_key_repository = GLOBAL_SHIELDING_KEY_REPOSITORY_COMPONENT.get()?; let ocall_api = GLOBAL_OCALL_API_COMPONENT.get()?; + let relayer_registry = GLOBAL_RELAYER_REGISTRY.get()?; + let signer_registry = GLOBAL_SIGNER_REGISTRY.get()?; + let enclave_registry = GLOBAL_ENCLAVE_REGISTRY.get()?; let stf_enclave_signer = Arc::new(EnclaveStfEnclaveSigner::new( state_observer, @@ -104,6 +114,9 @@ pub(crate) fn create_target_a_parentchain_block_importer( top_pool_author, node_metadata_repository, ParentchainId::TargetA, + relayer_registry, + signer_registry, + enclave_registry, )); Ok(TargetAParentchainBlockImporter::new( validator_access, @@ -127,6 +140,9 @@ pub(crate) fn create_target_b_parentchain_block_importer( let top_pool_author = GLOBAL_TOP_POOL_AUTHOR_COMPONENT.get()?; let shielding_key_repository = GLOBAL_SHIELDING_KEY_REPOSITORY_COMPONENT.get()?; let ocall_api = GLOBAL_OCALL_API_COMPONENT.get()?; + let relayer_registry = GLOBAL_RELAYER_REGISTRY.get()?; + let signer_registry = GLOBAL_SIGNER_REGISTRY.get()?; + let enclave_registry = GLOBAL_ENCLAVE_REGISTRY.get()?; let stf_enclave_signer = Arc::new(EnclaveStfEnclaveSigner::new( state_observer, @@ -140,6 +156,9 @@ pub(crate) fn create_target_b_parentchain_block_importer( top_pool_author, node_metadata_repository, ParentchainId::TargetB, + relayer_registry, + signer_registry, + enclave_registry, )); Ok(TargetBParentchainBlockImporter::new( validator_access, diff --git a/bitacross-worker/enclave-runtime/src/tls_ra/tls_ra_client.rs b/bitacross-worker/enclave-runtime/src/tls_ra/tls_ra_client.rs index e64c95cbf2..0d6aac53c9 100644 --- a/bitacross-worker/enclave-runtime/src/tls_ra/tls_ra_client.rs +++ b/bitacross-worker/enclave-runtime/src/tls_ra/tls_ra_client.rs @@ -23,7 +23,8 @@ use crate::{ error::{Error as EnclaveError, Result as EnclaveResult}, initialization::global_components::{ EnclaveSealHandler, GLOBAL_INTEGRITEE_PARENTCHAIN_LIGHT_CLIENT_SEAL, - GLOBAL_SHIELDING_KEY_REPOSITORY_COMPONENT, GLOBAL_STATE_KEY_REPOSITORY_COMPONENT, + GLOBAL_SHIELDING_KEY_REPOSITORY_COMPONENT, GLOBAL_SIGNER_REGISTRY, + GLOBAL_STATE_KEY_REPOSITORY_COMPONENT, }, ocall::OcallApi, shard_config::init_shard_config, @@ -35,12 +36,11 @@ use codec::Encode; use itp_attestation_handler::{RemoteAttestationType, DEV_HOSTNAME}; use itp_component_container::ComponentGetter; -use bc_enclave_registry::GLOBAL_ENCLAVE_REGISTRY; -use bc_signer_registry::GLOBAL_SIGNER_REGISTRY; use itp_ocall_api::EnclaveAttestationOCallApi; use itp_sgx_crypto::key_repository::AccessPubkey; use itp_types::{AccountId, ShardIdentifier}; +use crate::initialization::global_components::GLOBAL_ENCLAVE_REGISTRY; use log::*; use rustls::{ClientConfig, ClientSession, Stream}; use sgx_types::*; @@ -216,8 +216,20 @@ pub unsafe extern "C" fn request_state_provisioning( }, }; - let signer_registry = GLOBAL_SIGNER_REGISTRY.clone(); - let enclave_registry = GLOBAL_ENCLAVE_REGISTRY.clone(); + let signer_registry = match GLOBAL_SIGNER_REGISTRY.get() { + Ok(s) => s, + Err(e) => { + error!("{:?}", e); + return sgx_status_t::SGX_ERROR_UNEXPECTED + }, + }; + let enclave_registry = match GLOBAL_ENCLAVE_REGISTRY.get() { + Ok(s) => s, + Err(e) => { + error!("{:?}", e); + return sgx_status_t::SGX_ERROR_UNEXPECTED + }, + }; let seal_handler = EnclaveSealHandler::new( state_handler, diff --git a/bitacross-worker/enclave-runtime/src/tls_ra/tls_ra_server.rs b/bitacross-worker/enclave-runtime/src/tls_ra/tls_ra_server.rs index ead1194c91..bfbe36d2b0 100644 --- a/bitacross-worker/enclave-runtime/src/tls_ra/tls_ra_server.rs +++ b/bitacross-worker/enclave-runtime/src/tls_ra/tls_ra_server.rs @@ -23,15 +23,16 @@ use crate::{ error::{Error as EnclaveError, Result as EnclaveResult}, initialization::global_components::{ EnclaveSealHandler, GLOBAL_INTEGRITEE_PARENTCHAIN_LIGHT_CLIENT_SEAL, - GLOBAL_SHIELDING_KEY_REPOSITORY_COMPONENT, GLOBAL_STATE_KEY_REPOSITORY_COMPONENT, + GLOBAL_SHIELDING_KEY_REPOSITORY_COMPONENT, GLOBAL_SIGNER_REGISTRY, + GLOBAL_STATE_KEY_REPOSITORY_COMPONENT, }, ocall::OcallApi, shard_vault::add_shard_vault_proxy, tls_ra::seal_handler::UnsealStateAndKeys, GLOBAL_STATE_HANDLER_COMPONENT, }; -use bc_enclave_registry::GLOBAL_ENCLAVE_REGISTRY; -use bc_signer_registry::GLOBAL_SIGNER_REGISTRY; + +use crate::initialization::global_components::GLOBAL_ENCLAVE_REGISTRY; use codec::Decode; use itp_attestation_handler::RemoteAttestationType; use itp_component_container::ComponentGetter; @@ -241,8 +242,20 @@ pub unsafe extern "C" fn run_state_provisioning_server( }, }; - let signer_registry = GLOBAL_SIGNER_REGISTRY.clone(); - let enclave_registry = GLOBAL_ENCLAVE_REGISTRY.clone(); + let signer_registry = match GLOBAL_SIGNER_REGISTRY.get() { + Ok(s) => s, + Err(e) => { + error!("{:?}", e); + return sgx_status_t::SGX_ERROR_UNEXPECTED + }, + }; + let enclave_registry = match GLOBAL_ENCLAVE_REGISTRY.get() { + Ok(s) => s, + Err(e) => { + error!("{:?}", e); + return sgx_status_t::SGX_ERROR_UNEXPECTED + }, + }; let seal_handler = EnclaveSealHandler::new( state_handler, From c717119a5fcb12805f22def966e3b0fe58a373fc Mon Sep 17 00:00:00 2001 From: Faisal Ahmed <42486737+felixfaisal@users.noreply.github.com> Date: Mon, 10 Jun 2024 10:37:30 +0530 Subject: [PATCH 06/10] fix: not format the enum assertion for metrics (#2787) * fix: not format the enum assertion * fix: add dynamic assertion * refactor: add id for dynamic assertion label * refactor: fix clippy --- .../enclave-metrics/Cargo.toml | 6 +- .../enclave-metrics/src/lib.rs | 3 +- .../litentry/core/vc-task/receiver/src/lib.rs | 8 +- tee-worker/service/src/prometheus_metrics.rs | 88 ++++++++++--------- 4 files changed, 59 insertions(+), 46 deletions(-) diff --git a/tee-worker/core-primitives/enclave-metrics/Cargo.toml b/tee-worker/core-primitives/enclave-metrics/Cargo.toml index 23b4e0ef51..8b3a6e524c 100644 --- a/tee-worker/core-primitives/enclave-metrics/Cargo.toml +++ b/tee-worker/core-primitives/enclave-metrics/Cargo.toml @@ -13,16 +13,20 @@ sgx_tstd = { branch = "master", git = "https://github.com/apache/teaclave-sgx-sd # no-std dependencies codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive", "full"] } lc-stf-task-sender = { path = "../../litentry/core/stf-task/sender", default-features = false } +litentry-primitives = { path = "../../litentry/primitives", default-features = false } substrate-fixed = { default-features = false, git = "https://github.com/encointer/substrate-fixed", tag = "v0.5.9" } [features] default = ["std"] std = [ + "substrate-fixed/std", "codec/std", + "litentry-primitives/std", "lc-stf-task-sender/std", - "substrate-fixed/std", + ] sgx = [ "sgx_tstd", + "litentry-primitives/sgx", "lc-stf-task-sender/sgx", ] diff --git a/tee-worker/core-primitives/enclave-metrics/src/lib.rs b/tee-worker/core-primitives/enclave-metrics/src/lib.rs index 008aa17aa5..0190c32b67 100644 --- a/tee-worker/core-primitives/enclave-metrics/src/lib.rs +++ b/tee-worker/core-primitives/enclave-metrics/src/lib.rs @@ -27,6 +27,7 @@ extern crate sgx_tstd as std; use codec::{Decode, Encode}; use core::time::Duration; use lc_stf_task_sender::RequestType; +use litentry_primitives::Assertion; use std::{boxed::Box, string::String}; #[derive(Encode, Decode, Debug)] @@ -44,7 +45,7 @@ pub enum EnclaveMetric { SidechainSlotStfExecutionTime(Duration), SidechainSlotBlockCompositionTime(Duration), SidechainBlockBroadcastingTime(Duration), - VCBuildTime(String, Duration), + VCBuildTime(Assertion, Duration), SuccessfullVCIssuance, FailedVCIssuance, ParentchainEventProcessed(String), diff --git a/tee-worker/litentry/core/vc-task/receiver/src/lib.rs b/tee-worker/litentry/core/vc-task/receiver/src/lib.rs index 20423d0c0f..1e1a1115d3 100644 --- a/tee-worker/litentry/core/vc-task/receiver/src/lib.rs +++ b/tee-worker/litentry/core/vc-task/receiver/src/lib.rs @@ -612,10 +612,10 @@ where .send_to_parentchain(xt, &ParentchainId::Litentry, false) .map_err(|e| format!("Unable to send extrinsic to parentchain: {:?}", e))?; - if let Err(e) = context.ocall_api.update_metric(EnclaveMetric::VCBuildTime( - format!("{:?}", assertion), - start_time.elapsed(), - )) { + if let Err(e) = context + .ocall_api + .update_metric(EnclaveMetric::VCBuildTime(assertion, start_time.elapsed())) + { warn!("Failed to update metric for vc build time: {:?}", e); } diff --git a/tee-worker/service/src/prometheus_metrics.rs b/tee-worker/service/src/prometheus_metrics.rs index f014cc4dc1..76d325d664 100644 --- a/tee-worker/service/src/prometheus_metrics.rs +++ b/tee-worker/service/src/prometheus_metrics.rs @@ -241,8 +241,9 @@ impl ReceiveEnclaveMetrics for EnclaveMetricsReceiver { ENCLAVE_SIDECHAIN_SLOT_BLOCK_COMPOSITION_TIME.observe(time.as_secs_f64()), EnclaveMetric::SidechainBlockBroadcastingTime(time) => ENCLAVE_SIDECHAIN_BLOCK_BROADCASTING_TIME.observe(time.as_secs_f64()), - EnclaveMetric::VCBuildTime(assertion, time) => - VC_BUILD_TIME.with_label_values(&[&assertion]).observe(time.as_secs_f64()), + EnclaveMetric::VCBuildTime(assertion, time) => VC_BUILD_TIME + .with_label_values(&[&assertion_to_string(assertion)]) + .observe(time.as_secs_f64()), EnclaveMetric::SuccessfullVCIssuance => { SUCCESSFULL_VC_ISSUANCE_TASKS.inc(); }, @@ -272,48 +273,55 @@ fn handle_stf_call_request(req: RequestType, time: f64) { RequestType::AssertionVerification(_) => "request_vc", }; - let label = match req { + let label: String = match req { RequestType::IdentityVerification(request) => match request.identity { - Identity::Twitter(_) => "Twitter", - Identity::Discord(_) => "Discord", - Identity::Github(_) => "Github", - Identity::Substrate(_) => "Substrate", - Identity::Evm(_) => "Evm", - Identity::Bitcoin(_) => "Bitcoin", - Identity::Solana(_) => "Solana", + Identity::Twitter(_) => "Twitter".into(), + Identity::Discord(_) => "Discord".into(), + Identity::Github(_) => "Github".into(), + Identity::Substrate(_) => "Substrate".into(), + Identity::Evm(_) => "Evm".into(), + Identity::Bitcoin(_) => "Bitcoin".into(), + Identity::Solana(_) => "Solana".into(), }, - RequestType::AssertionVerification(request) => match request.assertion { - Assertion::A1 => "A1", - Assertion::A2(_) => "A2", - Assertion::A3(..) => "A3", - Assertion::A4(_) => "A4", - Assertion::A6 => "A6", - Assertion::A7(_) => "A7", - Assertion::A8(_) => "A8", - Assertion::A10(_) => "A10", - Assertion::A11(_) => "A11", - Assertion::A13(_) => "A13", - Assertion::A14 => "A14", - Assertion::A20 => "A20", - Assertion::Achainable(..) => "Achainable", - Assertion::OneBlock(..) => "OneBlock", - Assertion::BnbDomainHolding => "BnbDomainHolding", - Assertion::BnbDigitDomainClub(..) => "BnbDigitDomainClub", - Assertion::GenericDiscordRole(_) => "GenericDiscordRole", - Assertion::VIP3MembershipCard(..) => "VIP3MembershipCard", - Assertion::WeirdoGhostGangHolder => "WeirdoGhostGangHolder", - Assertion::LITStaking => "LITStaking", - Assertion::EVMAmountHolding(_) => "EVMAmountHolding", - Assertion::BRC20AmountHolder => "BRC20AmountHolder", - Assertion::CryptoSummary => "CryptoSummary", - Assertion::TokenHoldingAmount(_) => "TokenHoldingAmount", - Assertion::PlatformUser(_) => "PlatformUser", - Assertion::NftHolder(_) => "NftHolder", - Assertion::Dynamic(_) => "Dynamic", + RequestType::AssertionVerification(request) => assertion_to_string(request.assertion), + }; + inc_stf_calls(category, &label); + observe_execution_time(category, &label, time) +} + +fn assertion_to_string(assertion: Assertion) -> String { + let assertion = match assertion { + Assertion::A1 => "A1".into(), + Assertion::A2(_) => "A2".into(), + Assertion::A3(..) => "A3".into(), + Assertion::A4(_) => "A4".into(), + Assertion::A6 => "A6".into(), + Assertion::A7(_) => "A7".into(), + Assertion::A8(_) => "A8".into(), + Assertion::A10(_) => "A10".into(), + Assertion::A11(_) => "A11".into(), + Assertion::A13(_) => "A13".into(), + Assertion::A14 => "A14".into(), + Assertion::A20 => "A20".into(), + Assertion::Achainable(..) => "Achainable".into(), + Assertion::OneBlock(..) => "OneBlock".into(), + Assertion::BnbDomainHolding => "BnbDomainHolding".into(), + Assertion::BnbDigitDomainClub(..) => "BnbDigitDomainClub".into(), + Assertion::GenericDiscordRole(_) => "GenericDiscordRole".into(), + Assertion::VIP3MembershipCard(..) => "VIP3MembershipCard".into(), + Assertion::WeirdoGhostGangHolder => "WeirdoGhostGangHolder".into(), + Assertion::LITStaking => "LITStaking".into(), + Assertion::EVMAmountHolding(_) => "EVMAmountHolding".into(), + Assertion::BRC20AmountHolder => "BRC20AmountHolder".into(), + Assertion::CryptoSummary => "CryptoSummary".into(), + Assertion::TokenHoldingAmount(_) => "TokenHoldingAmount".into(), + Assertion::PlatformUser(_) => "PlatformUser".into(), + Assertion::NftHolder(_) => "NftHolder".into(), + Assertion::Dynamic(id) => { + format!("DynamicAssertion({:?})", id) }, }; - inc_stf_calls(category, label); - observe_execution_time(category, label, time) + assertion } #[derive(Serialize, Deserialize, Debug)] From bc2dd32405149ee3b3712e1799b830fffa1e0f5b Mon Sep 17 00:00:00 2001 From: "will.li" <120463031+higherordertech@users.noreply.github.com> Date: Mon, 10 Jun 2024 18:34:57 +1000 Subject: [PATCH 07/10] feat: P-701 solidity VC: token holding amount for BRC20 tokens (#2785) 1) add the precompile function: test_hex_to_number, integration_test, parse_decimal, parse_int 2) extract new common functions for Web3Network: get_code, from_code, get_name 3) move integration test of precompile function to its own file 4) move all util functions to new library files 5) add BRC20 contracts, one contract only support one token 6) add new library AssertionLogic instead of assemble assertion JSON manually Co-authored-by: higherordertech --- primitives/core/src/assertion/network.rs | 71 ++++ tee-worker/Cargo.lock | 17 + tee-worker/enclave-runtime/Cargo.lock | 16 + .../assertion-build/src/dynamic/.gitignore | 3 + .../src/dynamic/.prettierrc.json | 38 ++ .../src/dynamic/contracts/A1.sol | 36 +- .../src/dynamic/contracts/A20.sol | 41 +- .../src/dynamic/contracts/A6.sol | 53 ++- .../dynamic/contracts/DynamicAssertion.sol | 347 +-------------- .../src/dynamic/contracts/README.md | 2 +- .../contracts/libraries/AssertionLogic.sol | 139 ++++++ .../src/dynamic/contracts/libraries/Http.sol | 128 ++++++ .../contracts/libraries/Identities.sol | 295 +++++++++++++ .../src/dynamic/contracts/libraries/Utils.sol | 171 ++++++++ .../src/dynamic/contracts/tests/GetBool.sol | 29 +- .../src/dynamic/contracts/tests/GetI64.sol | 28 +- .../src/dynamic/contracts/tests/GetString.sol | 42 ++ .../dynamic/contracts/tests/HexToNumber.sol | 30 ++ .../contracts/tests/IdentityToString.sol | 30 ++ .../dynamic/contracts/tests/ParseDecimal.sol | 30 ++ .../src/dynamic/contracts/tests/ParseInt.sol | 27 ++ .../src/dynamic/contracts/tests/README.md | 2 +- .../src/dynamic/contracts/tests/ToHex.sol | 24 +- .../contracts/token_holding_amount/BRC20.sol | 82 ++++ .../TokenHoldingAmount.sol | 165 ++++++++ .../tokens/Btcs.sol} | 44 +- .../token_holding_amount/tokens/Cats.sol | 45 ++ .../token_holding_amount/tokens/Long.sol | 46 ++ .../token_holding_amount/tokens/Mmss.sol | 46 ++ .../token_holding_amount/tokens/Ordi.sol | 45 ++ .../token_holding_amount/tokens/Rats.sol | 46 ++ .../token_holding_amount/tokens/Sats.sol | 46 ++ .../core/assertion-build/src/dynamic/mod.rs | 248 +++-------- .../assertion-build/src/dynamic/repository.rs | 15 +- .../core/evm-dynamic-assertions/Cargo.toml | 9 +- .../core/evm-dynamic-assertions/src/lib.rs | 52 ++- .../src/precompiles/hex_to_number.rs | 162 +++++++ .../src/precompiles/http_get.rs | 348 ++++++++++++--- .../src/precompiles/identity_to_string.rs | 398 ++++++++++++++++++ .../src/precompiles/macros.rs | 57 +-- .../src/precompiles/mod.rs | 20 + .../src/precompiles/parse_decimal.rs | 162 +++++++ .../src/precompiles/parse_int.rs | 133 ++++++ .../src/precompiles/to_hex.rs | 89 ++-- .../core/mock-server/src/geniidata.rs | 109 +++-- 45 files changed, 3097 insertions(+), 869 deletions(-) create mode 100644 tee-worker/litentry/core/assertion-build/src/dynamic/.gitignore create mode 100644 tee-worker/litentry/core/assertion-build/src/dynamic/.prettierrc.json create mode 100644 tee-worker/litentry/core/assertion-build/src/dynamic/contracts/libraries/AssertionLogic.sol create mode 100644 tee-worker/litentry/core/assertion-build/src/dynamic/contracts/libraries/Http.sol create mode 100644 tee-worker/litentry/core/assertion-build/src/dynamic/contracts/libraries/Identities.sol create mode 100644 tee-worker/litentry/core/assertion-build/src/dynamic/contracts/libraries/Utils.sol create mode 100644 tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/GetString.sol create mode 100644 tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/HexToNumber.sol create mode 100644 tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/IdentityToString.sol create mode 100644 tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/ParseDecimal.sol create mode 100644 tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/ParseInt.sol create mode 100644 tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/BRC20.sol create mode 100644 tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/TokenHoldingAmount.sol rename tee-worker/litentry/core/assertion-build/src/dynamic/contracts/{tests/ConcatenateStrings.sol => token_holding_amount/tokens/Btcs.sol} (52%) create mode 100644 tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/tokens/Cats.sol create mode 100644 tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/tokens/Long.sol create mode 100644 tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/tokens/Mmss.sol create mode 100644 tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/tokens/Ordi.sol create mode 100644 tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/tokens/Rats.sol create mode 100644 tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/tokens/Sats.sol create mode 100644 tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/hex_to_number.rs create mode 100644 tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/identity_to_string.rs create mode 100644 tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/parse_decimal.rs create mode 100644 tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/parse_int.rs diff --git a/primitives/core/src/assertion/network.rs b/primitives/core/src/assertion/network.rs index 2d353ffaa8..caf345bded 100644 --- a/primitives/core/src/assertion/network.rs +++ b/primitives/core/src/assertion/network.rs @@ -14,6 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Litentry. If not, see . +use crate::alloc::string::String; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; use sp_runtime::{traits::ConstU32, BoundedVec}; @@ -143,6 +144,76 @@ impl Web3Network { pub fn is_solana(&self) -> bool { matches!(self, Self::Solana) } + + pub fn get_code(&self) -> u8 { + match self { + Web3Network::Polkadot => 0, + Web3Network::Kusama => 1, + Web3Network::Litentry => 2, + Web3Network::Litmus => 3, + Web3Network::LitentryRococo => 4, + Web3Network::Khala => 5, + Web3Network::SubstrateTestnet => 6, + Web3Network::Ethereum => 7, + Web3Network::Bsc => 8, + Web3Network::BitcoinP2tr => 9, + Web3Network::BitcoinP2pkh => 10, + Web3Network::BitcoinP2sh => 11, + Web3Network::BitcoinP2wpkh => 12, + Web3Network::BitcoinP2wsh => 13, + Web3Network::Polygon => 14, + Web3Network::Arbitrum => 15, + Web3Network::Solana => 16, + Web3Network::Combo => 17, + } + } + + pub fn from_code(code: u8) -> Option { + match code { + 0 => Some(Web3Network::Polkadot), + 1 => Some(Web3Network::Kusama), + 2 => Some(Web3Network::Litentry), + 3 => Some(Web3Network::Litmus), + 4 => Some(Web3Network::LitentryRococo), + 5 => Some(Web3Network::Khala), + 6 => Some(Web3Network::SubstrateTestnet), + 7 => Some(Web3Network::Ethereum), + 8 => Some(Web3Network::Bsc), + 9 => Some(Web3Network::BitcoinP2tr), + 10 => Some(Web3Network::BitcoinP2pkh), + 11 => Some(Web3Network::BitcoinP2sh), + 12 => Some(Web3Network::BitcoinP2wpkh), + 13 => Some(Web3Network::BitcoinP2wsh), + 14 => Some(Web3Network::Polygon), + 15 => Some(Web3Network::Arbitrum), + 16 => Some(Web3Network::Solana), + 17 => Some(Web3Network::Combo), + _ => None, + } + } + + pub fn get_name(&self) -> String { + match self { + Web3Network::Polkadot => "polkadot".into(), + Web3Network::Kusama => "kusama".into(), + Web3Network::Litentry => "litentry".into(), + Web3Network::Litmus => "litmus".into(), + Web3Network::LitentryRococo => "litentry_rococo".into(), + Web3Network::Khala => "khala".into(), + Web3Network::SubstrateTestnet => "substrate_testnet".into(), + Web3Network::Ethereum => "ethereum".into(), + Web3Network::Bsc => "bsc".into(), + Web3Network::BitcoinP2tr => "bitcoin_p2tr".into(), + Web3Network::BitcoinP2pkh => "bitcoin_p2pkh".into(), + Web3Network::BitcoinP2sh => "bitcoin_p2sh".into(), + Web3Network::BitcoinP2wpkh => "bitcoin_p2wpkh".into(), + Web3Network::BitcoinP2wsh => "bitcoin_p2wsh".into(), + Web3Network::Polygon => "polygon".into(), + Web3Network::Arbitrum => "arbitrum".into(), + Web3Network::Solana => "solana".into(), + Web3Network::Combo => "combo".into(), + } + } } pub fn all_web3networks() -> Vec { diff --git a/tee-worker/Cargo.lock b/tee-worker/Cargo.lock index 3437c5ed68..21a598e9ad 100644 --- a/tee-worker/Cargo.lock +++ b/tee-worker/Cargo.lock @@ -4621,6 +4621,8 @@ dependencies = [ name = "lc-evm-dynamic-assertions" version = "0.1.0" dependencies = [ + "base58", + "blake2-rfc", "ethabi", "evm 0.41.1", "hex", @@ -4631,12 +4633,17 @@ dependencies = [ "itp-settings", "itp-sgx-io", "itp-sgx-temp-dir", + "itp-utils", "lc-dynamic-assertion", + "lc-mock-server", + "litentry-hex-utils", "litentry-primitives", "log 0.4.20", "parity-scale-codec", + "rust_decimal", "serde_json 1.0.103", "sgx_tstd", + "ss58-registry", "thiserror 1.0.44", "thiserror 1.0.9", ] @@ -7155,6 +7162,16 @@ dependencies = [ "ordered-multimap", ] +[[package]] +name = "rust_decimal" +version = "1.35.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1790d1c4c0ca81211399e0e0af16333276f375209e71a37b67698a373db5b47a" +dependencies = [ + "arrayvec 0.7.4", + "num-traits 0.2.16", +] + [[package]] name = "rustc-demangle" version = "0.1.23" diff --git a/tee-worker/enclave-runtime/Cargo.lock b/tee-worker/enclave-runtime/Cargo.lock index 44b3f9554d..199185c3bd 100644 --- a/tee-worker/enclave-runtime/Cargo.lock +++ b/tee-worker/enclave-runtime/Cargo.lock @@ -3146,6 +3146,8 @@ dependencies = [ name = "lc-evm-dynamic-assertions" version = "0.1.0" dependencies = [ + "base58", + "blake2-rfc", "ethabi", "evm 0.41.1", "hex", @@ -3154,11 +3156,15 @@ dependencies = [ "itp-settings", "itp-sgx-io", "itp-sgx-temp-dir", + "itp-utils", "lc-dynamic-assertion", + "litentry-primitives", "log", "parity-scale-codec", + "rust_decimal", "serde_json 1.0.107", "sgx_tstd", + "ss58-registry", "thiserror", ] @@ -4403,6 +4409,16 @@ dependencies = [ "sgx_tstd", ] +[[package]] +name = "rust_decimal" +version = "1.35.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1790d1c4c0ca81211399e0e0af16333276f375209e71a37b67698a373db5b47a" +dependencies = [ + "arrayvec 0.7.4", + "num-traits 0.2.16", +] + [[package]] name = "rustc-hex" version = "2.1.0" diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/.gitignore b/tee-worker/litentry/core/assertion-build/src/dynamic/.gitignore new file mode 100644 index 0000000000..1a440b2a3e --- /dev/null +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/.gitignore @@ -0,0 +1,3 @@ +.deps +artifacts +.prettierrc.json diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/.prettierrc.json b/tee-worker/litentry/core/assertion-build/src/dynamic/.prettierrc.json new file mode 100644 index 0000000000..13cf33ed2a --- /dev/null +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/.prettierrc.json @@ -0,0 +1,38 @@ +{ + "overrides": [ + { + "files": "*.sol", + "options": { + "printWidth": 80, + "tabWidth": 4, + "useTabs": false, + "singleQuote": false, + "bracketSpacing": false + } + }, + { + "files": "*.yml", + "options": {} + }, + { + "files": "*.yaml", + "options": {} + }, + { + "files": "*.toml", + "options": {} + }, + { + "files": "*.json", + "options": {} + }, + { + "files": "*.js", + "options": {} + }, + { + "files": "*.ts", + "options": {} + } + ] +} \ No newline at end of file diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/A1.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/A1.sol index 1028305481..24b90c32da 100644 --- a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/A1.sol +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/A1.sol @@ -18,10 +18,15 @@ pragma solidity ^0.8.8; -import {DynamicAssertion, Identity} from "./DynamicAssertion.sol"; +import "./libraries/AssertionLogic.sol"; +import "./libraries/Identities.sol"; +import "./DynamicAssertion.sol"; contract A1 is DynamicAssertion { - function execute(Identity[] memory identities, string[] memory secrets) + function execute( + Identity[] memory identities, + string[] memory /*secrets*/ + ) public override returns ( @@ -35,9 +40,6 @@ contract A1 is DynamicAssertion { string memory description = "You've identified at least one account/address in both Web2 and Web3."; string memory assertion_type = "Basic Identity Verification"; - assertions.push( - '{"and": [{ "src": "$has_web2_account", "op": "==", "dst": "true" }, { "src": "$has_web3_account", "op": "==", "dst": "true" } ] }' - ); schema_url = "https://raw.githubusercontent.com/litentry/vc-jsonschema/main/dist/schemas/1-basic-identity-verification/1-0-0.json"; bool result; @@ -46,14 +48,34 @@ contract A1 is DynamicAssertion { bool has_web2_identity = false; for (uint256 i = 0; i < identities.length; i++) { - if (is_web2(identities[i])) { + if (Identities.is_web2(identities[i])) { has_web2_identity = true; - } else if (is_web3(identities[i])) { + } else if (Identities.is_web3(identities[i])) { has_web3_identity = true; } } result = has_web2_identity && has_web3_identity; + AssertionLogic.CompositeCondition memory cc = AssertionLogic + .CompositeCondition(new AssertionLogic.Condition[](2), true); + AssertionLogic.andOp( + cc, + 0, + "$has_web2_account", + AssertionLogic.Op.Equal, + "true" + ); + AssertionLogic.andOp( + cc, + 1, + "$has_web3_account", + AssertionLogic.Op.Equal, + "true" + ); + + string[] memory assertions = new string[](1); + assertions[0] = AssertionLogic.toString(cc); + return (description, assertion_type, assertions, schema_url, result); } } diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/A20.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/A20.sol index bccbf6783d..806824961b 100644 --- a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/A20.sol +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/A20.sol @@ -18,10 +18,17 @@ pragma solidity ^0.8.8; -import {DynamicAssertion, Identity, HttpHeader} from "./DynamicAssertion.sol"; +import "./libraries/AssertionLogic.sol"; +import "./libraries/Http.sol"; +import "./libraries/Identities.sol"; +import "./libraries/Utils.sol"; +import "./DynamicAssertion.sol"; contract A20 is DynamicAssertion { - function execute(Identity[] memory identities, string[] memory secrets) + function execute( + Identity[] memory identities, + string[] memory /*secrets*/ + ) public override returns ( @@ -35,25 +42,30 @@ contract A20 is DynamicAssertion { string memory description = "The user is an early bird user of the IdentityHub EVM version and has generated at least 1 credential during 2023 Aug 14th ~ Aug 21st."; string memory assertion_type = "IDHub EVM Version Early Bird"; - assertions.push('{ "src": "$has_joined", "op": "==", "dst": "true" }'); schema_url = "https://raw.githubusercontent.com/litentry/vc-jsonschema/main/dist/schemas/12-idhub-evm-version-early-bird/1-0-0.json"; - bool result = false; + bool result = false; for (uint256 i = 0; i < identities.length; i++) { - if (is_web3(identities[i])) { - (bool success, string memory res) = toHex(identities[i].value); + if (Identities.is_web3(identities[i])) { + (bool success, string memory res) = Utils.toHex( + identities[i].value + ); if (success) { if (!success) { continue; } - string memory url = concatenateStrings( - "http://localhost:19527/events/does-user-joined-evm-campaign?account=", - res + string memory url = string( + abi.encodePacked( + "https://archive-test.litentry.io/events/does-user-joined-evm-campaign?account=", + // below url is used for test against mock server + // "http://localhost:19527/events/does-user-joined-evm-campaign?account=", + res + ) ); string memory jsonPointer = "/hasJoined"; HttpHeader[] memory headers = new HttpHeader[](0); - (bool get_success, bool get_result) = GetBool( + (bool get_success, bool get_result) = Http.GetBool( url, jsonPointer, headers @@ -68,6 +80,15 @@ contract A20 is DynamicAssertion { } } } + + AssertionLogic.Condition memory condition = AssertionLogic.Condition( + "$has_joined", + AssertionLogic.Op.Equal, + "true" + ); + string[] memory assertions = new string[](1); + assertions[0] = AssertionLogic.toString(condition); + return (description, assertion_type, assertions, schema_url, result); } } diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/A6.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/A6.sol index 1adceb5a6e..5896f2821d 100644 --- a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/A6.sol +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/A6.sol @@ -18,8 +18,11 @@ pragma solidity ^0.8.8; -import {DynamicAssertion, Identity, HttpHeader} from "./DynamicAssertion.sol"; import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.9.0/contracts/utils/Strings.sol"; +import "./libraries/AssertionLogic.sol"; +import "./libraries/Http.sol"; +import "./libraries/Identities.sol"; +import "./DynamicAssertion.sol"; contract A6 is DynamicAssertion { function execute(Identity[] memory identities, string[] memory secrets) @@ -43,21 +46,21 @@ contract A6 is DynamicAssertion { int64 sum = 0; for (uint256 i = 0; i < identities.length; i++) { - if (is_twitter(identities[i])) { - /// "http://localhost:19528/2/users/by/username/" mock address used in dev env - string memory url = concatenateStrings( - "https://api.twitter.com/2/users/by/username/", - string(identities[i].value) - ); - string memory full_url = concatenateStrings( - url, - "?user.fields=public_metrics" + if (Identities.is_twitter(identities[i])) { + string memory url = string( + abi.encodePacked( + "https://api.twitter.com/2/users/by/username/", + // below url is used for test against mock server + // "http://localhost:19528/2/users/by/username/", + string(identities[i].value), + "?user.fields=public_metrics" + ) ); HttpHeader[] memory headers = prepareHeaders(secrets[0]); - (bool get_success, int64 followers_count) = GetI64( - full_url, + (bool get_success, int64 followers_count) = Http.GetI64( + url, "/data/public_metrics/followers_count", headers ); @@ -92,17 +95,27 @@ contract A6 is DynamicAssertion { } result = min != 0; - string memory assertion = concatenateStrings( - '{"and": [{ "src": "$total_followers", "op": ">", "dst": "', + string memory variable = "$total_followers"; + AssertionLogic.CompositeCondition memory cc = AssertionLogic + .CompositeCondition(new AssertionLogic.Condition[](2), true); + AssertionLogic.andOp( + cc, + 0, + variable, + AssertionLogic.Op.GreaterThan, Strings.toString(min) ); - assertion = concatenateStrings( - assertion, - '" }, { "src": "$has_web3_account", "op": "<=", "dst": "' + AssertionLogic.andOp( + cc, + 1, + variable, + AssertionLogic.Op.LessEq, + Strings.toString(max) ); - assertion = concatenateStrings(assertion, Strings.toString(max)); - assertion = concatenateStrings(assertion, '" } ] }'); - assertions.push(assertion); + + string[] memory assertions = new string[](1); + assertions[0] = AssertionLogic.toString(cc); + return (description, assertion_type, assertions, schema_url, result); } diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/DynamicAssertion.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/DynamicAssertion.sol index a1d6f84b7d..2783cf5ee5 100644 --- a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/DynamicAssertion.sol +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/DynamicAssertion.sol @@ -18,19 +18,9 @@ pragma solidity ^0.8.8; -struct Identity { - uint32 identity_type; - bytes value; - uint32[] networks; -} - -struct HttpHeader { - string name; - string value; -} +import "./libraries/Identities.sol"; abstract contract DynamicAssertion { - string[] assertions; string schema_url; function execute(Identity[] memory identities, string[] memory secrets) @@ -43,339 +33,4 @@ abstract contract DynamicAssertion { string memory, bool ); - - function encode_params(string memory url, string memory jsonPointer) - internal - pure - returns (bytes memory) - { - return abi.encode(url, jsonPointer); - } - - function GetI64( - string memory url, - string memory jsonPointer, - HttpHeader[] memory headers - ) internal returns (bool, int64) { - bool success; - int64 value; - - bytes memory encoded_params = abi.encode(url, jsonPointer, headers); - uint256 encoded_params_len = encoded_params.length; - assembly { - let memPtr := mload(0x40) - if iszero( - call( - not(0), - 0x03E8, - 0, - add(encoded_params, 0x20), - encoded_params_len, - memPtr, - 0x40 - ) - ) { - revert(0, 0) - } - success := mload(memPtr) - value := mload(add(memPtr, 0x20)) - mstore(0x40, add(memPtr, 0x40)) - } - - return (success, value); - } - - function GetBool( - string memory url, - string memory jsonPointer, - HttpHeader[] memory headers - ) internal returns (bool, bool) { - bool success; - bool value; - - bytes memory encoded_params = abi.encode(url, jsonPointer, headers); - uint256 encoded_params_len = encoded_params.length; - - assembly { - let memPtr := mload(0x40) - if iszero( - call( - not(0), - 0x03E9, - 0, - add(encoded_params, 0x20), - encoded_params_len, - memPtr, - 0x40 - ) - ) { - revert(0, 0) - } - success := mload(memPtr) - value := mload(add(memPtr, 0x20)) - mstore(0x40, add(memPtr, 0x40)) - } - - return (success, value); - } - - function concatenateStrings(string memory a, string memory b) - internal - pure - returns (string memory) - { - bytes memory concatenatedBytes = abi.encodePacked(a, b); - return string(concatenatedBytes); - } - - function toHex(bytes memory bytes_value) - internal - returns (bool success, string memory value) - { - bytes memory encoded = abi.encode(bytes_value); - uint256 encoded_len = encoded.length; - - assembly { - let memPtr := mload(0x40) - if iszero( - call( - not(0), - 0x041B, - 0, - add(encoded, 0x20), - encoded_len, - memPtr, - 0x1000 - ) - ) { - revert(0, 0) - } - success := memPtr - value := add(memPtr, 0x40) - mstore(0x40, add(memPtr, 0x1000)) - } - - return (success, value); - } - - function from( - uint32 identity_type, - bytes memory value, - uint32[] memory networks - ) internal pure returns (Identity memory) { - return (Identity(identity_type, value, networks)); - } - - function is_web3(Identity memory identity_type) - internal - pure - returns (bool) - { - return (is_substrate(identity_type) || - is_evm(identity_type) || - is_bitcoin(identity_type)); - } - - function is_web2(Identity memory identity_type) - internal - pure - returns (bool) - { - return (is_twitter(identity_type) || - is_discord(identity_type) || - is_github(identity_type)); - } - - function is_twitter(Identity memory identity) internal pure returns (bool) { - return is_of_type(identity, 0); - } - - function is_discord(Identity memory identity) internal pure returns (bool) { - return is_of_type(identity, 1); - } - - function is_github(Identity memory identity) internal pure returns (bool) { - return is_of_type(identity, 2); - } - - function is_substrate(Identity memory identity) - internal - pure - returns (bool) - { - return is_of_type(identity, 3); - } - - function is_evm(Identity memory identity) internal pure returns (bool) { - return is_of_type(identity, 4); - } - - function is_bitcoin(Identity memory identity) internal pure returns (bool) { - return is_of_type(identity, 5); - } - - function is_solana(Identity memory identity) internal pure returns (bool) { - return is_of_type(identity, 6); - } - - function is_of_type(Identity memory identity, uint32 identity_type) - internal - pure - returns (bool) - { - if (identity.identity_type == identity_type) { - return (true); - } else { - return (false); - } - } - - function has_polkadot_network(Identity memory identity_type) - internal - pure - returns (bool) - { - return has_network(identity_type, 0); - } - - function has_kusama_network(Identity memory identity_type) - internal - pure - returns (bool) - { - return has_network(identity_type, 1); - } - - function has_litentry_network(Identity memory identity_type) - internal - pure - returns (bool) - { - return has_network(identity_type, 2); - } - - function has_litmus_network(Identity memory identity_type) - internal - pure - returns (bool) - { - return has_network(identity_type, 3); - } - - function has_litentry_rococo_network(Identity memory identity_type) - internal - pure - returns (bool) - { - return has_network(identity_type, 4); - } - - function has_khala_network(Identity memory identity_type) - internal - pure - returns (bool) - { - return has_network(identity_type, 5); - } - - function has_substrate_testnet_network(Identity memory identity_type) - internal - pure - returns (bool) - { - return has_network(identity_type, 6); - } - - function has_ethereum_network(Identity memory identity_type) - internal - pure - returns (bool) - { - return has_network(identity_type, 7); - } - - function has_bsc_network(Identity memory identity_type) - internal - pure - returns (bool) - { - return has_network(identity_type, 8); - } - - function has_bitcoin_p2tr_network(Identity memory identity_type) - internal - pure - returns (bool) - { - return has_network(identity_type, 9); - } - - function has_bitcoin_p2pkh_network(Identity memory identity_type) - internal - pure - returns (bool) - { - return has_network(identity_type, 10); - } - - function has_bitcoin_p2sh_network(Identity memory identity_type) - internal - pure - returns (bool) - { - return has_network(identity_type, 11); - } - - function has_bitcoin_p2wpkh_network(Identity memory identity_type) - internal - pure - returns (bool) - { - return has_network(identity_type, 12); - } - - function has_bitcoin_p2wsh_network(Identity memory identity_type) - internal - pure - returns (bool) - { - return has_network(identity_type, 13); - } - - function has_polygon_network(Identity memory identity_type) - internal - pure - returns (bool) - { - return has_network(identity_type, 14); - } - - function has_arbitrum_network(Identity memory identity_type) - internal - pure - returns (bool) - { - return has_network(identity_type, 15); - } - - function has_solana_network(Identity memory identity_type) - internal - pure - returns (bool) - { - return has_network(identity_type, 16); - } - - function has_network(Identity memory identity_type, uint32 network) - internal - pure - returns (bool) - { - for (uint256 i = 0; i < identity_type.networks.length; i++) { - if (identity_type.networks[i] == network) { - return (true); - } - } - return (false); - } } diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/README.md b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/README.md index b65394f4c5..11752fec9c 100644 --- a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/README.md +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/README.md @@ -1 +1 @@ -Compiled with solc 0.8.11 \ No newline at end of file +Compiled with solc 0.8.11 diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/libraries/AssertionLogic.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/libraries/AssertionLogic.sol new file mode 100644 index 0000000000..ada40ce5dd --- /dev/null +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/libraries/AssertionLogic.sol @@ -0,0 +1,139 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . + +// SPDX-License-Identifier: GPL-3.0-or-later + +pragma solidity ^0.8.8; + +library AssertionLogic { + enum Op { + GreaterThan, + LessThan, + GreaterEq, + LessEq, + Equal, + NotEq + } + + struct Condition { + string src; + Op op; + string dst; + } + + struct CompositeCondition { + Condition[] conditions; + bool isAnd; // true for 'And', false for 'Or' + } + + function addCondition( + CompositeCondition memory cc, + uint256 i, + string memory src, + Op op, + string memory dst + ) internal pure { + cc.conditions[i] = Condition(src, op, dst); + } + + function andOp( + CompositeCondition memory cc, + uint256 i, + string memory src, + Op op, + string memory dst + ) internal pure returns (CompositeCondition memory) { + addCondition(cc, i, src, op, dst); + cc.isAnd = true; + return cc; + } + + function orOp( + CompositeCondition memory cc, + uint256 i, + string memory src, + Op op, + string memory dst + ) internal pure returns (CompositeCondition memory) { + addCondition(cc, i, src, op, dst); + cc.isAnd = false; + return cc; + } + + function toString(CompositeCondition memory cc) + internal + pure + returns (string memory) + { + string memory result = "{"; + + if (cc.conditions.length > 0) { + result = string( + abi.encodePacked(result, cc.isAnd ? '"and":[' : '"or":[') + ); + for (uint256 i = 0; i < cc.conditions.length; i++) { + if (i > 0) { + result = string(abi.encodePacked(result, ",")); + } + result = string( + abi.encodePacked(result, toString(cc.conditions[i])) + ); + } + result = string(abi.encodePacked(result, "]")); + } + + result = string(abi.encodePacked(result, "}")); + + return result; + } + + function toString(Condition memory condition) + internal + pure + returns (string memory) + { + return + string( + abi.encodePacked( + '{"src":"', + condition.src, + '","op":"', + operatorToString(condition.op), + '","dst":"', + condition.dst, + '"}' + ) + ); + } + + function operatorToString(Op op) internal pure returns (string memory) { + if (op == Op.Equal) { + return "=="; + } else if (op == Op.GreaterThan) { + return ">"; + } else if (op == Op.LessThan) { + return "<"; + } else if (op == Op.GreaterEq) { + return ">="; + } else if (op == Op.LessEq) { + return "<="; + } else if (op == Op.NotEq) { + return "!="; + } + + revert("Unsupported operator"); + } +} diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/libraries/Http.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/libraries/Http.sol new file mode 100644 index 0000000000..8cf256da12 --- /dev/null +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/libraries/Http.sol @@ -0,0 +1,128 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . + +// SPDX-License-Identifier: GPL-3.0-or-later + +pragma solidity ^0.8.8; + +struct HttpHeader { + string name; + string value; +} + +library Http { + function GetI64( + string memory url, + string memory jsonPointer, + HttpHeader[] memory headers + ) internal returns (bool, int64) { + bool success; + int64 value; + + bytes memory encoded_params = abi.encode(url, jsonPointer, headers); + uint256 encoded_params_len = encoded_params.length; + + assembly { + let memPtr := mload(0x40) + if iszero( + call( + not(0), + 0x03E8, + 0, + add(encoded_params, 0x20), + encoded_params_len, + memPtr, + 0x40 + ) + ) { + revert(0, 0) + } + success := mload(memPtr) + value := mload(add(memPtr, 0x20)) + mstore(0x40, add(memPtr, 0x40)) + } + + return (success, value); + } + + function GetBool( + string memory url, + string memory jsonPointer, + HttpHeader[] memory headers + ) internal returns (bool, bool) { + bool success; + bool value; + + bytes memory encoded_params = abi.encode(url, jsonPointer, headers); + uint256 encoded_params_len = encoded_params.length; + + assembly { + let memPtr := mload(0x40) + if iszero( + call( + not(0), + 0x03E9, + 0, + add(encoded_params, 0x20), + encoded_params_len, + memPtr, + 0x40 + ) + ) { + revert(0, 0) + } + success := mload(memPtr) + value := mload(add(memPtr, 0x20)) + mstore(0x40, add(memPtr, 0x40)) + } + + return (success, value); + } + + function GetString( + string memory url, + string memory jsonPointer, + HttpHeader[] memory headers + ) internal returns (bool, string memory) { + bool success; + string memory value; + + bytes memory encoded_params = abi.encode(url, jsonPointer, headers); + uint256 encoded_params_len = encoded_params.length; + + assembly { + let memPtr := mload(0x40) + if iszero( + call( + not(0), + 0x03EA, + 0, + add(encoded_params, 0x20), + encoded_params_len, + memPtr, + 0x1000 + ) + ) { + revert(0, 0) + } + success := mload(memPtr) + value := add(memPtr, 0x40) + mstore(0x40, add(memPtr, 0x1000)) + } + + return (success, value); + } +} diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/libraries/Identities.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/libraries/Identities.sol new file mode 100644 index 0000000000..bf7990958a --- /dev/null +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/libraries/Identities.sol @@ -0,0 +1,295 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . + +// SPDX-License-Identifier: GPL-3.0-or-later + +pragma solidity ^0.8.8; + +struct Identity { + uint32 identity_type; + bytes value; + uint32[] networks; +} + +library IdentityTypes { + // web2 + uint32 public constant Twitter = 0; + uint32 public constant Discord = 1; + uint32 public constant Github = 2; + + // web3 + uint32 public constant Substrate = 3; + uint32 public constant Evm = 4; + uint32 public constant Bitcoin = 5; + uint32 public constant Solana = 6; +} + +library Web3Networks { + // substrate + uint32 public constant Polkadot = 0; + uint32 public constant Kusama = 1; + uint32 public constant Litentry = 2; + uint32 public constant Litmus = 3; + uint32 public constant LitentryRococo = 4; + uint32 public constant Khala = 5; + uint32 public constant SubstrateTestnet = 6; + + // evm + uint32 public constant Ethereum = 7; + uint32 public constant Bsc = 8; + uint32 public constant Polygon = 14; + uint32 public constant Arbitrum = 15; + uint32 public constant Solana = 16; + uint32 public constant Combo = 17; + + // btc + uint32 public constant BitcoinP2tr = 9; + uint32 public constant BitcoinP2pkh = 10; + uint32 public constant BitcoinP2sh = 11; + uint32 public constant BitcoinP2wpkh = 12; + uint32 public constant BitcoinP2wsh = 13; +} + +library Identities { + function from( + uint32 identity_type, + bytes memory value, + uint32[] memory networks + ) internal pure returns (Identity memory) { + return (Identity(identity_type, value, networks)); + } + + function is_web3(Identity memory identity_type) + internal + pure + returns (bool) + { + return (is_substrate(identity_type) || + is_evm(identity_type) || + is_bitcoin(identity_type)); + } + + function is_web2(Identity memory identity_type) + internal + pure + returns (bool) + { + return (is_twitter(identity_type) || + is_discord(identity_type) || + is_github(identity_type)); + } + + function is_twitter(Identity memory identity) internal pure returns (bool) { + return is_of_type(identity, IdentityTypes.Twitter); + } + + function is_discord(Identity memory identity) internal pure returns (bool) { + return is_of_type(identity, IdentityTypes.Discord); + } + + function is_github(Identity memory identity) internal pure returns (bool) { + return is_of_type(identity, IdentityTypes.Github); + } + + function is_substrate(Identity memory identity) + internal + pure + returns (bool) + { + return is_of_type(identity, IdentityTypes.Substrate); + } + + function is_evm(Identity memory identity) internal pure returns (bool) { + return is_of_type(identity, IdentityTypes.Evm); + } + + function is_bitcoin(Identity memory identity) internal pure returns (bool) { + return is_of_type(identity, IdentityTypes.Bitcoin); + } + + function is_solana(Identity memory identity) internal pure returns (bool) { + return is_of_type(identity, IdentityTypes.Solana); + } + + function is_of_type(Identity memory identity, uint32 identity_type) + internal + pure + returns (bool) + { + if (identity.identity_type == identity_type) { + return (true); + } else { + return (false); + } + } + + function has_polkadot_network(Identity memory identity_type) + internal + pure + returns (bool) + { + return has_network(identity_type, Web3Networks.Polkadot); + } + + function has_kusama_network(Identity memory identity_type) + internal + pure + returns (bool) + { + return has_network(identity_type, Web3Networks.Kusama); + } + + function has_litentry_network(Identity memory identity_type) + internal + pure + returns (bool) + { + return has_network(identity_type, Web3Networks.Litentry); + } + + function has_litmus_network(Identity memory identity_type) + internal + pure + returns (bool) + { + return has_network(identity_type, Web3Networks.Litmus); + } + + function has_litentry_rococo_network(Identity memory identity_type) + internal + pure + returns (bool) + { + return has_network(identity_type, Web3Networks.LitentryRococo); + } + + function has_khala_network(Identity memory identity_type) + internal + pure + returns (bool) + { + return has_network(identity_type, Web3Networks.Khala); + } + + function has_substrate_testnet_network(Identity memory identity_type) + internal + pure + returns (bool) + { + return has_network(identity_type, Web3Networks.SubstrateTestnet); + } + + function has_ethereum_network(Identity memory identity_type) + internal + pure + returns (bool) + { + return has_network(identity_type, Web3Networks.Ethereum); + } + + function has_bsc_network(Identity memory identity_type) + internal + pure + returns (bool) + { + return has_network(identity_type, Web3Networks.Bsc); + } + + function has_bitcoin_p2tr_network(Identity memory identity_type) + internal + pure + returns (bool) + { + return has_network(identity_type, Web3Networks.BitcoinP2tr); + } + + function has_bitcoin_p2pkh_network(Identity memory identity_type) + internal + pure + returns (bool) + { + return has_network(identity_type, Web3Networks.BitcoinP2pkh); + } + + function has_bitcoin_p2sh_network(Identity memory identity_type) + internal + pure + returns (bool) + { + return has_network(identity_type, Web3Networks.BitcoinP2sh); + } + + function has_bitcoin_p2wpkh_network(Identity memory identity_type) + internal + pure + returns (bool) + { + return has_network(identity_type, Web3Networks.BitcoinP2wpkh); + } + + function has_bitcoin_p2wsh_network(Identity memory identity_type) + internal + pure + returns (bool) + { + return has_network(identity_type, Web3Networks.BitcoinP2wsh); + } + + function has_polygon_network(Identity memory identity_type) + internal + pure + returns (bool) + { + return has_network(identity_type, Web3Networks.Polygon); + } + + function has_arbitrum_network(Identity memory identity_type) + internal + pure + returns (bool) + { + return has_network(identity_type, Web3Networks.Arbitrum); + } + + function has_solana_network(Identity memory identity_type) + internal + pure + returns (bool) + { + return has_network(identity_type, Web3Networks.Solana); + } + + function has_combo_network(Identity memory identity_type) + internal + pure + returns (bool) + { + return has_network(identity_type, Web3Networks.Combo); + } + + function has_network(Identity memory identity_type, uint32 network) + internal + pure + returns (bool) + { + for (uint256 i = 0; i < identity_type.networks.length; i++) { + if (identity_type.networks[i] == network) { + return (true); + } + } + return (false); + } +} diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/libraries/Utils.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/libraries/Utils.sol new file mode 100644 index 0000000000..6ab2c5a387 --- /dev/null +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/libraries/Utils.sol @@ -0,0 +1,171 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . + +// SPDX-License-Identifier: GPL-3.0-or-later + +pragma solidity ^0.8.8; + +library Utils { + function toHex(bytes memory bytes_value) + internal + returns (bool success, string memory value) + { + bytes memory encoded_params = abi.encode(bytes_value); + uint256 encoded_params_len = encoded_params.length; + + assembly { + let memPtr := mload(0x40) + if iszero( + call( + not(0), + 0x041B, + 0, + add(encoded_params, 0x20), + encoded_params_len, + memPtr, + 0x1000 + ) + ) { + revert(0, 0) + } + success := mload(memPtr) + value := add(memPtr, 0x40) + mstore(0x40, add(memPtr, 0x1000)) + } + + return (success, value); + } + + function identityToString(uint32 network_type, bytes memory identity_value) + internal + returns (bool success, string memory value) + { + bytes memory encoded_params = abi.encode(network_type, identity_value); + uint256 encoded_params_len = encoded_params.length; + + assembly { + let memPtr := mload(0x40) + if iszero( + call( + not(0), + 0x041C, + 0, + add(encoded_params, 0x20), + encoded_params_len, + memPtr, + 0x1000 + ) + ) { + revert(0, 0) + } + success := memPtr + value := add(memPtr, 0x40) + mstore(0x40, add(memPtr, 0x1000)) + } + + return (success, value); + } + + function hexToNumber(string memory string_value) + internal + returns (bool success, uint256 value) + { + bytes memory encoded_params = abi.encode(string_value); + uint256 encoded_params_len = encoded_params.length; + + assembly { + let memPtr := mload(0x40) + if iszero( + call( + not(0), + 0x041D, + 0, + add(encoded_params, 0x20), + encoded_params_len, + memPtr, + 0x82 + ) + ) { + revert(0, 0) + } + success := mload(memPtr) + value := mload(add(memPtr, 0x20)) + mstore(0x40, add(memPtr, 0x82)) + } + + return (success, value); + } + + function parseDecimal(string memory string_value, uint8 decimals) + internal + returns (bool success, uint256 value) + { + bytes memory encoded_params = abi.encode(string_value, decimals); + uint256 encoded_params_len = encoded_params.length; + + assembly { + let memPtr := mload(0x40) + if iszero( + call( + not(0), + 0x041E, + 0, + add(encoded_params, 0x20), + encoded_params_len, + memPtr, + 0x82 + ) + ) { + revert(0, 0) + } + success := mload(memPtr) + value := mload(add(memPtr, 0x20)) + mstore(0x40, add(memPtr, 0x82)) + } + + return (success, value); + } + + function parseInt(string memory string_value) + internal + returns (bool success, uint256 value) + { + bytes memory encoded_params = abi.encode(string_value); + uint256 encoded_params_len = encoded_params.length; + + assembly { + let memPtr := mload(0x40) + if iszero( + call( + not(0), + 0x041F, + 0, + add(encoded_params, 0x20), + encoded_params_len, + memPtr, + 0x82 + ) + ) { + revert(0, 0) + } + success := mload(memPtr) + value := mload(add(memPtr, 0x20)) + mstore(0x40, add(memPtr, 0x82)) + } + + return (success, value); + } +} diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/GetBool.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/GetBool.sol index 1e977eed81..62bad3564f 100644 --- a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/GetBool.sol +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/GetBool.sol @@ -18,34 +18,15 @@ pragma solidity ^0.8.8; -import {DynamicAssertion, Identity, HttpHeader} from "./DynamicAssertion.sol"; - -contract GetI64 is DynamicAssertion { - function execute(Identity[] memory identities, string[] memory secrets) - public - override - returns ( - string memory, - string memory, - string[] memory, - string memory, - bool - ) - { - string memory description = "description"; - string memory assertion_type = "assertion type"; - bool result = false; - - return (description, assertion_type, assertions, schema_url, result); - } +import "../libraries/Http.sol"; +contract GetI64 { function callGetBool(string memory url, string memory jsonPointer) public returns (bool, bool) { HttpHeader[] memory headers = new HttpHeader[](0); - return GetBool(url, jsonPointer, headers); - (url, jsonPointer, headers); + return Http.GetBool(url, jsonPointer, headers); } function callGetBoolTwiceAndReturnSecondResult( @@ -55,8 +36,8 @@ contract GetI64 is DynamicAssertion { string memory secondJsonPointer ) public returns (bool, bool) { HttpHeader[] memory headers = new HttpHeader[](0); - GetBool(firstUrl, firstJsonPointer, headers); + Http.GetBool(firstUrl, firstJsonPointer, headers); (firstUrl, firstJsonPointer, headers); - return GetBool(secondUrl, secondJsonPointer, headers); + return Http.GetBool(secondUrl, secondJsonPointer, headers); } } diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/GetI64.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/GetI64.sol index a0246c8570..d7e0d98ab6 100644 --- a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/GetI64.sol +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/GetI64.sol @@ -18,33 +18,15 @@ pragma solidity ^0.8.8; -import {DynamicAssertion, Identity, HttpHeader} from "./DynamicAssertion.sol"; - -contract GetI64 is DynamicAssertion { - function execute(Identity[] memory identities, string[] memory secrets) - public - override - returns ( - string memory, - string memory, - string[] memory, - string memory, - bool - ) - { - string memory description = "description"; - string memory assertion_type = "assertion type"; - bool result = false; - - return (description, assertion_type, assertions, schema_url, result); - } +import "../libraries/Http.sol"; +contract GetI64 { function callGetI64(string memory url, string memory jsonPointer) public returns (bool, int64) { HttpHeader[] memory headers = new HttpHeader[](0); - return GetI64(url, jsonPointer, headers); + return Http.GetI64(url, jsonPointer, headers); } function callGetI64TwiceAndReturnSecondResult( @@ -54,7 +36,7 @@ contract GetI64 is DynamicAssertion { string memory secondJsonPointer ) public returns (bool, int64) { HttpHeader[] memory headers = new HttpHeader[](0); - GetI64(firstUrl, firstJsonPointer, headers); - return GetI64(secondUrl, secondJsonPointer, headers); + Http.GetI64(firstUrl, firstJsonPointer, headers); + return Http.GetI64(secondUrl, secondJsonPointer, headers); } } diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/GetString.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/GetString.sol new file mode 100644 index 0000000000..c6a6a4754a --- /dev/null +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/GetString.sol @@ -0,0 +1,42 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . + +// SPDX-License-Identifier: GPL-3.0-or-later + +pragma solidity ^0.8.8; + +import "../libraries/Http.sol"; + +contract GetString { + function callGetString(string memory url, string memory jsonPointer) + public + returns (bool, string memory) + { + HttpHeader[] memory headers = new HttpHeader[](0); + return Http.GetString(url, jsonPointer, headers); + } + + function callGetStringTwiceAndReturnSecondResult( + string memory firstUrl, + string memory firstJsonPointer, + string memory secondUrl, + string memory secondJsonPointer + ) public returns (bool, string memory) { + HttpHeader[] memory headers = new HttpHeader[](0); + Http.GetI64(firstUrl, firstJsonPointer, headers); + return Http.GetString(secondUrl, secondJsonPointer, headers); + } +} diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/HexToNumber.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/HexToNumber.sol new file mode 100644 index 0000000000..7161bd1e15 --- /dev/null +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/HexToNumber.sol @@ -0,0 +1,30 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . + +// SPDX-License-Identifier: GPL-3.0-or-later + +pragma solidity ^0.8.8; + +import "../libraries/Utils.sol"; + +contract HexToNumber { + function callHexToNumber(string memory text) + public + returns (bool, uint256) + { + return Utils.hexToNumber(text); + } +} diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/IdentityToString.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/IdentityToString.sol new file mode 100644 index 0000000000..f934dd8cd7 --- /dev/null +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/IdentityToString.sol @@ -0,0 +1,30 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . + +// SPDX-License-Identifier: GPL-3.0-or-later + +pragma solidity ^0.8.8; + +import "../libraries/Utils.sol"; + +contract IdentityToString { + function callIdentityToString( + uint32 network_type, + bytes memory identity_value + ) public returns (bool, string memory) { + return Utils.identityToString(network_type, identity_value); + } +} diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/ParseDecimal.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/ParseDecimal.sol new file mode 100644 index 0000000000..81c9b05286 --- /dev/null +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/ParseDecimal.sol @@ -0,0 +1,30 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . + +// SPDX-License-Identifier: GPL-3.0-or-later + +pragma solidity ^0.8.8; + +import "../libraries/Utils.sol"; + +contract ParseDecimal { + function callParseDecimal(string memory text, uint8 decimals) + public + returns (bool, uint256) + { + return Utils.parseDecimal(text, decimals); + } +} diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/ParseInt.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/ParseInt.sol new file mode 100644 index 0000000000..bc2dc948e6 --- /dev/null +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/ParseInt.sol @@ -0,0 +1,27 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . + +// SPDX-License-Identifier: GPL-3.0-or-later + +pragma solidity ^0.8.8; + +import "../libraries/Utils.sol"; + +contract ParseInt { + function callParseInt(string memory text) public returns (bool, uint256) { + return Utils.parseInt(text); + } +} diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/README.md b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/README.md index 51178419c6..952e29e932 100644 --- a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/README.md +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/README.md @@ -1,2 +1,2 @@ This folder contains Solidity smart contracts used for testing integration between `DynamicAssertion.sol` and runtime precompiles. -Smart contract exposes function to call `DynamicAssertion.sol` functions with arbitrary data. Results can be used in test cases to assert integration correctness. \ No newline at end of file +Smart contract exposes function to call `DynamicAssertion.sol` functions with arbitrary data. Results can be used in test cases to assert integration correctness. diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/ToHex.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/ToHex.sol index 76874099b7..4c806292c4 100644 --- a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/ToHex.sol +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/ToHex.sol @@ -18,31 +18,13 @@ pragma solidity ^0.8.8; -import {DynamicAssertion, Identity, HttpHeader} from "./DynamicAssertion.sol"; - -contract ToHex is DynamicAssertion { - function execute(Identity[] memory identities, string[] memory secrets) - public - override - returns ( - string memory, - string memory, - string[] memory, - string memory, - bool - ) - { - string memory description = "description"; - string memory assertion_type = "assertion type"; - bool result = false; - - return (description, assertion_type, assertions, schema_url, result); - } +import "../libraries/Utils.sol"; +contract ToHex { function callToHex(string memory text) public returns (bool, string memory) { - return toHex(bytes(text)); + return Utils.toHex(bytes(text)); } } diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/BRC20.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/BRC20.sol new file mode 100644 index 0000000000..4f6af277f9 --- /dev/null +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/BRC20.sol @@ -0,0 +1,82 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . + +// SPDX-License-Identifier: GPL-3.0-or-later + +pragma solidity ^0.8.8; + +import "../libraries/Identities.sol"; +import "../libraries/Http.sol"; +import "../libraries/Utils.sol"; +import {TokenHoldingAmount} from "./TokenHoldingAmount.sol"; + +abstract contract BRC20 is TokenHoldingAmount { + function getTokenDecimals() internal pure override returns (uint8) { + return 18; + } + + function queryBalance( + Identity memory identity, + uint32 network, + string[] memory secrets + ) internal virtual override returns (uint256) { + (bool identityToStringSuccess, string memory identityString) = Utils + .identityToString(network, identity.value); + if (identityToStringSuccess) { + // https://geniidata.readme.io/reference/get-brc20-tick-list-copy + string memory url = string( + abi.encodePacked( + "https://api.geniidata.com/api/1/brc20/balance", + // below url is used for test against mock server + // "http://localhost:19529/api/1/brc20/balance", + "?tick=", + getTokenName(), + "&address=", + identityString + ) + ); + + HttpHeader[] memory headers = new HttpHeader[](1); + headers[0] = HttpHeader("api-key", secrets[0]); + + (bool success, string memory value) = Http.GetString( + url, + "/data/list/0/available_balance", + headers + ); + + if (success) { + (bool parseDecimalSuccess, uint256 result) = Utils.parseDecimal( + value, + getTokenDecimals() + ); + if (parseDecimalSuccess) { + return result; + } + } + } + return 0; + } + + function isSupportedNetwork(uint32 network) + internal + pure + override + returns (bool) + { + return network == Web3Networks.BitcoinP2tr; + } +} diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/TokenHoldingAmount.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/TokenHoldingAmount.sol new file mode 100644 index 0000000000..630c7f4a83 --- /dev/null +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/TokenHoldingAmount.sol @@ -0,0 +1,165 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . + +// SPDX-License-Identifier: GPL-3.0-or-later + +pragma solidity ^0.8.8; + +import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.9.0/contracts/utils/Strings.sol"; +import "../libraries/AssertionLogic.sol"; +import "../libraries/Identities.sol"; +import "../DynamicAssertion.sol"; + +abstract contract TokenHoldingAmount is DynamicAssertion { + function execute(Identity[] memory identities, string[] memory secrets) + public + override + returns ( + string memory, + string memory, + string[] memory, + string memory, + bool + ) + { + string + memory description = "The amount of a particular token you are holding"; + string memory assertion_type = "Token Holding Amount"; + schema_url = "https://raw.githubusercontent.com/litentry/vc-jsonschema/main/dist/schemas/25-token-holding-amount/1-1-0.json"; + + uint256 balance = queryTotalBalance(identities, secrets); + + (uint256 index, uint256 min, int256 max) = calculateRange(balance); + + string[] memory assertions = assembleAssertions(min, max); + + bool result = index > 0 || balance > 0; + + return (description, assertion_type, assertions, schema_url, result); + } + + function queryTotalBalance( + Identity[] memory identities, + string[] memory secrets + ) internal virtual returns (uint256) { + uint256 total_balance = 0; + uint256 identitiesLength = identities.length; + + for (uint256 i = 0; i < identitiesLength; i++) { + Identity memory identity = identities[i]; + uint256 networksLength = identity.networks.length; + for (uint32 j = 0; j < networksLength; j++) { + uint32 network = identity.networks[j]; + if (isSupportedNetwork(network)) { + total_balance += queryBalance(identity, network, secrets); + } + } + } + + return total_balance; + } + + function calculateRange(uint256 balance) + private + pure + returns ( + uint256, + uint256, + int256 + ) + { + uint256[] memory ranges = getTokenRanges(); + uint256 index = ranges.length - 1; + uint256 min = 0; + int256 max = 0; + + for (uint32 i = 1; i < ranges.length; i++) { + if (balance < ranges[i] * 10**getTokenDecimals()) { + index = i - 1; + break; + } + } + + if (index == ranges.length - 1) { + min = ranges[index]; + max = -1; + } else { + min = ranges[index]; + max = int256(ranges[index + 1]); + } + + return (index, min, max); + } + + function assembleAssertions(uint256 min, int256 max) + private + pure + returns (string[] memory) + { + string memory variable = "$holding_amount"; + AssertionLogic.CompositeCondition memory cc = AssertionLogic + .CompositeCondition( + new AssertionLogic.Condition[](max > 0 ? 3 : 2), + true + ); + AssertionLogic.andOp( + cc, + 0, + "$token", + AssertionLogic.Op.Equal, + getTokenName() + ); + AssertionLogic.andOp( + cc, + 1, + variable, + AssertionLogic.Op.GreaterEq, + Strings.toString(min) + ); + if (max > 0) { + AssertionLogic.andOp( + cc, + 2, + variable, + AssertionLogic.Op.LessThan, + Strings.toString(max) + ); + } + + string[] memory assertions = new string[](1); + assertions[0] = AssertionLogic.toString(cc); + + return assertions; + } + + function getTokenName() internal pure virtual returns (string memory); + + function getTokenRanges() internal pure virtual returns (uint256[] memory); + + function getTokenDecimals() internal pure virtual returns (uint8); + + function isSupportedNetwork(uint32 network) + internal + pure + virtual + returns (bool); + + function queryBalance( + Identity memory identity, + uint32 network, + string[] memory secrets + ) internal virtual returns (uint256); +} diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/ConcatenateStrings.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/tokens/Btcs.sol similarity index 52% rename from tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/ConcatenateStrings.sol rename to tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/tokens/Btcs.sol index 2a0734681d..1204ba10ca 100644 --- a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/ConcatenateStrings.sol +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/tokens/Btcs.sol @@ -18,31 +18,29 @@ pragma solidity ^0.8.8; -import {DynamicAssertion, Identity, HttpHeader} from "./DynamicAssertion.sol"; +import {BRC20} from "../BRC20.sol"; -contract ConcatenateStrings is DynamicAssertion { - function execute(Identity[] memory identities, string[] memory secrets) - public - override - returns ( - string memory, - string memory, - string[] memory, - string memory, - bool - ) - { - string memory description = "description"; - string memory assertion_type = "assertion type"; - bool result = false; - - return (description, assertion_type, assertions, schema_url, result); +contract Btcs is BRC20 { + function getTokenName() internal pure override returns (string memory) { + return "btcs"; } - function callConcatenateStrings(string memory s1, string memory s2) - public - returns (string memory) + function getTokenRanges() + internal + pure + override + returns (uint256[] memory) { - return concatenateStrings(s1, s2); + uint256[] memory ranges = new uint256[](9); + ranges[0] = 0; + ranges[1] = 1; + ranges[2] = 5; + ranges[3] = 20; + ranges[4] = 50; + ranges[5] = 100; + ranges[6] = 200; + ranges[7] = 500; + ranges[8] = 800; + return ranges; } -} \ No newline at end of file +} diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/tokens/Cats.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/tokens/Cats.sol new file mode 100644 index 0000000000..0c737a3c4c --- /dev/null +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/tokens/Cats.sol @@ -0,0 +1,45 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . + +// SPDX-License-Identifier: GPL-3.0-or-later + +pragma solidity ^0.8.8; + +import {BRC20} from "../BRC20.sol"; + +contract Cats is BRC20 { + function getTokenName() internal pure override returns (string memory) { + return "cats"; + } + + function getTokenRanges() + internal + pure + override + returns (uint256[] memory) + { + uint256[] memory ranges = new uint256[](8); + ranges[0] = 0; + ranges[1] = 1; + ranges[2] = 10000; + ranges[3] = 50000; + ranges[4] = 100000; + ranges[5] = 200000; + ranges[6] = 500000; + ranges[7] = 800000; + return ranges; + } +} diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/tokens/Long.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/tokens/Long.sol new file mode 100644 index 0000000000..8ec368121f --- /dev/null +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/tokens/Long.sol @@ -0,0 +1,46 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . + +// SPDX-License-Identifier: GPL-3.0-or-later + +pragma solidity ^0.8.8; + +import {BRC20} from "../BRC20.sol"; + +contract Long is BRC20 { + function getTokenName() internal pure override returns (string memory) { + return "long"; + } + + function getTokenRanges() + internal + pure + override + returns (uint256[] memory) + { + uint256[] memory ranges = new uint256[](9); + ranges[0] = 0; + ranges[1] = 1; + ranges[2] = 20; + ranges[3] = 50; + ranges[4] = 200; + ranges[5] = 500; + ranges[6] = 1000; + ranges[7] = 2000; + ranges[8] = 3000; + return ranges; + } +} diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/tokens/Mmss.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/tokens/Mmss.sol new file mode 100644 index 0000000000..4cf9030cd0 --- /dev/null +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/tokens/Mmss.sol @@ -0,0 +1,46 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . + +// SPDX-License-Identifier: GPL-3.0-or-later + +pragma solidity ^0.8.8; + +import {BRC20} from "../BRC20.sol"; + +contract Mmss is BRC20 { + function getTokenName() internal pure override returns (string memory) { + return "mmss"; + } + + function getTokenRanges() + internal + pure + override + returns (uint256[] memory) + { + uint256[] memory ranges = new uint256[](9); + ranges[0] = 0; + ranges[1] = 1; + ranges[2] = 20; + ranges[3] = 50; + ranges[4] = 100; + ranges[5] = 200; + ranges[6] = 500; + ranges[7] = 1000; + ranges[8] = 2000; + return ranges; + } +} diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/tokens/Ordi.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/tokens/Ordi.sol new file mode 100644 index 0000000000..eb337dfae9 --- /dev/null +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/tokens/Ordi.sol @@ -0,0 +1,45 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . + +// SPDX-License-Identifier: GPL-3.0-or-later + +pragma solidity ^0.8.8; + +import {BRC20} from "../BRC20.sol"; + +contract Ordi is BRC20 { + function getTokenName() internal pure override returns (string memory) { + return "ordi"; + } + + function getTokenRanges() + internal + pure + override + returns (uint256[] memory) + { + uint256[] memory ranges = new uint256[](8); + ranges[0] = 0; + ranges[1] = 1; + ranges[2] = 5; + ranges[3] = 20; + ranges[4] = 50; + ranges[5] = 100; + ranges[6] = 200; + ranges[7] = 500; + return ranges; + } +} diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/tokens/Rats.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/tokens/Rats.sol new file mode 100644 index 0000000000..27a27f42d5 --- /dev/null +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/tokens/Rats.sol @@ -0,0 +1,46 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . + +// SPDX-License-Identifier: GPL-3.0-or-later + +pragma solidity ^0.8.8; + +import {BRC20} from "../BRC20.sol"; + +contract Rats is BRC20 { + function getTokenName() internal pure override returns (string memory) { + return "rats"; + } + + function getTokenRanges() + internal + pure + override + returns (uint256[] memory) + { + uint256[] memory ranges = new uint256[](9); + ranges[0] = 0; + ranges[1] = 1; + ranges[2] = 40000; + ranges[3] = 200000; + ranges[4] = 1000000; + ranges[5] = 2000000; + ranges[6] = 4000000; + ranges[7] = 10000000; + ranges[8] = 2000000; + return ranges; + } +} diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/tokens/Sats.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/tokens/Sats.sol new file mode 100644 index 0000000000..3b866775c6 --- /dev/null +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/tokens/Sats.sol @@ -0,0 +1,46 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . + +// SPDX-License-Identifier: GPL-3.0-or-later + +pragma solidity ^0.8.8; + +import {BRC20} from "../BRC20.sol"; + +contract Sats is BRC20 { + function getTokenName() internal pure override returns (string memory) { + return "sats"; + } + + function getTokenRanges() + internal + pure + override + returns (uint256[] memory) + { + uint256[] memory ranges = new uint256[](9); + ranges[0] = 0; + ranges[1] = 1; + ranges[2] = 40000000; + ranges[3] = 200000000; + ranges[4] = 500000000; + ranges[5] = 1000000000; + ranges[6] = 2000000000; + ranges[7] = 4000000000; + ranges[8] = 6000000000; + return ranges; + } +} diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/mod.rs b/tee-worker/litentry/core/assertion-build/src/dynamic/mod.rs index a1ead2686e..a9465d43e7 100644 --- a/tee-worker/litentry/core/assertion-build/src/dynamic/mod.rs +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/mod.rs @@ -77,207 +77,14 @@ pub fn build< } } -#[cfg(test)] -pub mod dynamic_assertion_test { - use ethabi::{encode, Token}; - use lc_evm_dynamic_assertions::{execute_smart_contract, prepare_function_call_input}; - use lc_mock_server::run; - use primitive_types::U256; - - // ToHex.sol bytecode - const TO_HEX_BYTE_CODE: &str = "608060405234801561001057600080fd5b50610817806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80638876183c1461003b578063e256184614610065575b600080fd5b61004e6100493660046103c9565b610089565b60405161005c929190610453565b60405180910390f35b61007861007336600461053b565b61009f565b60405161005c9594939291906106e9565b6000606061009683610278565b91509150915091565b6060806060806000806040518060400160405280600b81526020016a3232b9b1b934b83a34b7b760a91b815250905060006040518060400160405280600e81526020016d617373657274696f6e207479706560901b815250905060008282600060018482805480602002602001604051908101604052809291908181526020016000905b828210156101cf57838290600052602060002001805461014290610793565b80601f016020809104026020016040519081016040528092919081815260200182805461016e90610793565b80156101bb5780601f10610190576101008083540402835291602001916101bb565b820191906000526020600020905b81548152906001019060200180831161019e57829003601f168201915b505050505081526020019060010190610123565b5050505092508180546101e190610793565b80601f016020809104026020016040519081016040528092919081815260200182805461020d90610793565b801561025a5780601f1061022f5761010080835404028352916020019161025a565b820191906000526020600020905b81548152906001019060200180831161023d57829003601f168201915b50505050509150975097509750975097505050509295509295909350565b6000606060008360405160200161028f91906107ce565b60408051601f1981840301815290829052805190925090611000818360208601600061041b600019f16102c157600080fd5b8094506040810193506110008101604052505050915091565b634e487b7160e01b600052604160045260246000fd5b6040516060810167ffffffffffffffff81118282101715610313576103136102da565b60405290565b604051601f8201601f1916810167ffffffffffffffff81118282101715610342576103426102da565b604052919050565b600067ffffffffffffffff831115610364576103646102da565b610377601f8401601f1916602001610319565b905082815283838301111561038b57600080fd5b828260208301376000602084830101529392505050565b600082601f8301126103b357600080fd5b6103c28383356020850161034a565b9392505050565b6000602082840312156103db57600080fd5b813567ffffffffffffffff8111156103f257600080fd5b6103fe848285016103a2565b949350505050565b6000815180845260005b8181101561042c57602081850181015186830182015201610410565b8181111561043e576000602083870101525b50601f01601f19169290920160200192915050565b82151581526040602082015260006103fe6040830184610406565b600067ffffffffffffffff821115610488576104886102da565b5060051b60200190565b803563ffffffff811681146104a657600080fd5b919050565b600082601f8301126104bc57600080fd5b813560206104d16104cc8361046e565b610319565b82815260059290921b840181019181810190868411156104f057600080fd5b8286015b8481101561053057803567ffffffffffffffff8111156105145760008081fd5b6105228986838b01016103a2565b8452509183019183016104f4565b509695505050505050565b6000806040838503121561054e57600080fd5b823567ffffffffffffffff8082111561056657600080fd5b818501915085601f83011261057a57600080fd5b8135602061058a6104cc8361046e565b82815260059290921b840181019181810190898411156105a957600080fd5b8286015b848110156106bb578035868111156105c457600080fd5b87016060818d03601f190112156105da57600080fd5b6105e26102f0565b6105ed868301610492565b815260408201358881111561060157600080fd5b8201603f81018e1361061257600080fd5b6106238e888301356040840161034a565b878301525060608201358881111561063a57600080fd5b8083019250508c603f83011261064f57600080fd5b8582013561065f6104cc8261046e565b81815260059190911b830160400190878101908f83111561067f57600080fd5b6040850194505b828510156106a65761069785610492565b82529388019390880190610686565b604084015250508452509183019183016105ad565b50965050860135925050808211156106d257600080fd5b506106df858286016104ab565b9150509250929050565b60a0815260006106fc60a0830188610406565b60208382038185015261070f8289610406565b915083820360408501528187518084528284019150828160051b850101838a0160005b8381101561076057601f1987840301855261074e838351610406565b94860194925090850190600101610732565b50508681036060880152610774818a610406565b95505050505050610789608083018415159052565b9695505050505050565b600181811c908216806107a757607f821691505b602082108114156107c857634e487b7160e01b600052602260045260246000fd5b50919050565b6020815260006103c2602083018461040656fea26469706673582212202bc48bafd887e8c048a6dd3bfe6528691288f0a4158ec3c7f543773204e9991564736f6c634300080b0033"; - - // ConcatenateStrings.sol bytecode - const CONCATENATE_STRINGS_BYTE_CODE: &str = "608060405234801561001057600080fd5b5061081a806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063e25618461461003b578063f2baa36e14610068575b600080fd5b61004e610049366004610458565b610088565b60405161005f959493929190610663565b60405180910390f35b61007b61007636600461070d565b610261565b60405161005f9190610767565b6060806060806000806040518060400160405280600b81526020016a3232b9b1b934b83a34b7b760a91b815250905060006040518060400160405280600e81526020016d617373657274696f6e207479706560901b815250905060008282600060018482805480602002602001604051908101604052809291908181526020016000905b828210156101b857838290600052602060002001805461012b9061077a565b80601f01602080910402602001604051908101604052809291908181526020018280546101579061077a565b80156101a45780601f10610179576101008083540402835291602001916101a4565b820191906000526020600020905b81548152906001019060200180831161018757829003601f168201915b50505050508152602001906001019061010c565b5050505092508180546101ca9061077a565b80601f01602080910402602001604051908101604052809291908181526020018280546101f69061077a565b80156102435780601f1061021857610100808354040283529160200191610243565b820191906000526020600020905b81548152906001019060200180831161022657829003601f168201915b50505050509150975097509750975097505050509295509295909350565b606061026d8383610274565b9392505050565b60606000838360405160200161028b9291906107b5565b60408051808303601f19018152919052949350505050565b634e487b7160e01b600052604160045260246000fd5b6040516060810167ffffffffffffffff811182821017156102dc576102dc6102a3565b60405290565b604051601f8201601f1916810167ffffffffffffffff8111828210171561030b5761030b6102a3565b604052919050565b600067ffffffffffffffff82111561032d5761032d6102a3565b5060051b60200190565b803563ffffffff8116811461034b57600080fd5b919050565b600067ffffffffffffffff83111561036a5761036a6102a3565b61037d601f8401601f19166020016102e2565b905082815283838301111561039157600080fd5b828260208301376000602084830101529392505050565b600082601f8301126103b957600080fd5b61026d83833560208501610350565b600082601f8301126103d957600080fd5b813560206103ee6103e983610313565b6102e2565b82815260059290921b8401810191818101908684111561040d57600080fd5b8286015b8481101561044d57803567ffffffffffffffff8111156104315760008081fd5b61043f8986838b01016103a8565b845250918301918301610411565b509695505050505050565b6000806040838503121561046b57600080fd5b823567ffffffffffffffff8082111561048357600080fd5b818501915085601f83011261049757600080fd5b813560206104a76103e983610313565b82815260059290921b840181019181810190898411156104c657600080fd5b8286015b848110156105d9578035868111156104e157600080fd5b87016060818d03601f190112156104f757600080fd5b6104ff6102b9565b61050a868301610337565b815260408201358881111561051e57600080fd5b8201603f81018e1361052f57600080fd5b6105408e8883013560408401610350565b878301525060608201358881111561055757600080fd5b8083019250508c603f83011261056c57600080fd5b8582013561057c6103e982610313565b81815260059190911b83018701870190878101908f83111561059d57600080fd5b6040850194505b828510156105c4576105b585610337565b825293880193908801906105a4565b604084015250508452509183019183016104ca565b50965050860135925050808211156105f057600080fd5b506105fd858286016103c8565b9150509250929050565b60005b8381101561062257818101518382015260200161060a565b83811115610631576000848401525b50505050565b6000815180845261064f816020860160208601610607565b601f01601f19169290920160200192915050565b60a08152600061067660a0830188610637565b6020838203818501526106898289610637565b915083820360408501528187518084528284019150828160051b850101838a0160005b838110156106da57601f198784030185526106c8838351610637565b948601949250908501906001016106ac565b505086810360608801526106ee818a610637565b95505050505050610703608083018415159052565b9695505050505050565b6000806040838503121561072057600080fd5b823567ffffffffffffffff8082111561073857600080fd5b610744868387016103a8565b9350602085013591508082111561075a57600080fd5b506105fd858286016103a8565b60208152600061026d6020830184610637565b600181811c9082168061078e57607f821691505b602082108114156107af57634e487b7160e01b600052602260045260246000fd5b50919050565b600083516107c7818460208801610607565b8351908301906107db818360208801610607565b0194935050505056fea2646970667358221220d4508ca4edbbc299296fc8dfc0223e54a63c733d541d0f6109c778d0af6539b064736f6c634300080b0033"; - - // GetI64.sol bytecode - const GET_I64_BYTE_CODE: &str = "608060405234801561001057600080fd5b50610a3f806100206000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063e256184614610046578063ed043e0f14610073578063f5e19bc0146100a0575b600080fd5b610059610054366004610577565b6100b3565b60405161006a959493929190610772565b60405180910390f35b61008661008136600461081c565b61028c565b60408051921515835260079190910b60208301520161006a565b6100866100ae3660046108c9565b6102f6565b6060806060806000806040518060400160405280600b81526020016a3232b9b1b934b83a34b7b760a91b815250905060006040518060400160405280600e81526020016d617373657274696f6e207479706560901b815250905060008282600060018482805480602002602001604051908101604052809291908181526020016000905b828210156101e357838290600052602060002001805461015690610923565b80601f016020809104026020016040519081016040528092919081815260200182805461018290610923565b80156101cf5780601f106101a4576101008083540402835291602001916101cf565b820191906000526020600020905b8154815290600101906020018083116101b257829003601f168201915b505050505081526020019060010190610137565b5050505092508180546101f590610923565b80601f016020809104026020016040519081016040528092919081815260200182805461022190610923565b801561026e5780601f106102435761010080835404028352916020019161026e565b820191906000526020600020905b81548152906001019060200180831161025157829003601f168201915b50505050509150975097509750975097505050509295509295909350565b6040805160008082526020820190925281908190816102cd565b60408051808201909152606080825260208201528152602001906001900390816102a65790505b5090506102db878783610351565b50506102e8858583610351565b925092505094509492505050565b604080516000808252602082019092528190819081610337565b60408051808201909152606080825260208201528152602001906001900390816103105790505b509050610345858583610351565b92509250509250929050565b600080600080600087878760405160200161036e9392919061095e565b60408051601f198184030181528282528051909350919081836020860160006103e8600019f161039d57600080fd5b8051602082015160409283019092529a909950975050505050505050565b634e487b7160e01b600052604160045260246000fd5b6040516060810167ffffffffffffffff811182821017156103f4576103f46103bb565b60405290565b604051601f8201601f1916810167ffffffffffffffff81118282101715610423576104236103bb565b604052919050565b600067ffffffffffffffff821115610445576104456103bb565b5060051b60200190565b803563ffffffff8116811461046357600080fd5b919050565b600067ffffffffffffffff831115610482576104826103bb565b610495601f8401601f19166020016103fa565b90508281528383830111156104a957600080fd5b828260208301376000602084830101529392505050565b600082601f8301126104d157600080fd5b6104e083833560208501610468565b9392505050565b600082601f8301126104f857600080fd5b8135602061050d6105088361042b565b6103fa565b82815260059290921b8401810191818101908684111561052c57600080fd5b8286015b8481101561056c57803567ffffffffffffffff8111156105505760008081fd5b61055e8986838b01016104c0565b845250918301918301610530565b509695505050505050565b6000806040838503121561058a57600080fd5b823567ffffffffffffffff808211156105a257600080fd5b818501915085601f8301126105b657600080fd5b813560206105c66105088361042b565b82815260059290921b840181019181810190898411156105e557600080fd5b8286015b848110156106f75780358681111561060057600080fd5b87016060818d03601f1901121561061657600080fd5b61061e6103d1565b61062986830161044f565b815260408201358881111561063d57600080fd5b8201603f81018e1361064e57600080fd5b61065f8e8883013560408401610468565b878301525060608201358881111561067657600080fd5b8083019250508c603f83011261068b57600080fd5b8582013561069b6105088261042b565b81815260059190911b830160400190878101908f8311156106bb57600080fd5b6040850194505b828510156106e2576106d38561044f565b825293880193908801906106c2565b604084015250508452509183019183016105e9565b509650508601359250508082111561070e57600080fd5b5061071b858286016104e7565b9150509250929050565b6000815180845260005b8181101561074b5760208185018101518683018201520161072f565b8181111561075d576000602083870101525b50601f01601f19169290920160200192915050565b60a08152600061078560a0830188610725565b6020838203818501526107988289610725565b915083820360408501528187518084528284019150828160051b850101838a0160005b838110156107e957601f198784030185526107d7838351610725565b948601949250908501906001016107bb565b505086810360608801526107fd818a610725565b95505050505050610812608083018415159052565b9695505050505050565b6000806000806080858703121561083257600080fd5b843567ffffffffffffffff8082111561084a57600080fd5b610856888389016104c0565b9550602087013591508082111561086c57600080fd5b610878888389016104c0565b9450604087013591508082111561088e57600080fd5b61089a888389016104c0565b935060608701359150808211156108b057600080fd5b506108bd878288016104c0565b91505092959194509250565b600080604083850312156108dc57600080fd5b823567ffffffffffffffff808211156108f457600080fd5b610900868387016104c0565b9350602085013591508082111561091657600080fd5b5061071b858286016104c0565b600181811c9082168061093757607f821691505b6020821081141561095857634e487b7160e01b600052602260045260246000fd5b50919050565b6060815260006109716060830186610725565b6020838203818501526109848287610725565b91506040848303818601528286518085528385019150838160051b86010184890160005b838110156109f857878303601f19018552815180518785526109cc88860182610725565b91890151858303868b01529190506109e48183610725565b9689019694505050908601906001016109a8565b50909b9a505050505050505050505056fea2646970667358221220dc347f537bd4447b1735029849707e20da3e7d2b936a4d52101bb4c795e2cb9e64736f6c634300080b0033"; - - // GetBool.sol bytecode - const GET_BOOL_BYTE_CODE: &str = "608060405234801561001057600080fd5b50610a38806100206000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c80637083d8ec14610046578063e256184614610075578063fe59859114610099575b600080fd5b6100596100543660046104a3565b6100ac565b6040805192151583529015156020830152015b60405180910390f35b61008861008336600461061d565b610116565b60405161006c959493929190610818565b6100596100a73660046108c2565b6102ef565b6040805160008082526020820190925281908190816100ed565b60408051808201909152606080825260208201528152602001906001900390816100c65790505b5090506100fb87878361034a565b505061010885858361034a565b925092505094509492505050565b6060806060806000806040518060400160405280600b81526020016a3232b9b1b934b83a34b7b760a91b815250905060006040518060400160405280600e81526020016d617373657274696f6e207479706560901b815250905060008282600060018482805480602002602001604051908101604052809291908181526020016000905b828210156102465783829060005260206000200180546101b99061091c565b80601f01602080910402602001604051908101604052809291908181526020018280546101e59061091c565b80156102325780601f1061020757610100808354040283529160200191610232565b820191906000526020600020905b81548152906001019060200180831161021557829003601f168201915b50505050508152602001906001019061019a565b5050505092508180546102589061091c565b80601f01602080910402602001604051908101604052809291908181526020018280546102849061091c565b80156102d15780601f106102a6576101008083540402835291602001916102d1565b820191906000526020600020905b8154815290600101906020018083116102b457829003601f168201915b50505050509150975097509750975097505050509295509295909350565b604080516000808252602082019092528190819081610330565b60408051808201909152606080825260208201528152602001906001900390816103095790505b50905061033e85858361034a565b92509250509250929050565b600080600080600087878760405160200161036793929190610957565b60408051601f198184030181528282528051909350919081836020860160006103e9600019f161039657600080fd5b8051602082015160409283019092529a909950975050505050505050565b634e487b7160e01b600052604160045260246000fd5b6040516060810167ffffffffffffffff811182821017156103ed576103ed6103b4565b60405290565b604051601f8201601f1916810167ffffffffffffffff8111828210171561041c5761041c6103b4565b604052919050565b600067ffffffffffffffff83111561043e5761043e6103b4565b610451601f8401601f19166020016103f3565b905082815283838301111561046557600080fd5b828260208301376000602084830101529392505050565b600082601f83011261048d57600080fd5b61049c83833560208501610424565b9392505050565b600080600080608085870312156104b957600080fd5b843567ffffffffffffffff808211156104d157600080fd5b6104dd8883890161047c565b955060208701359150808211156104f357600080fd5b6104ff8883890161047c565b9450604087013591508082111561051557600080fd5b6105218883890161047c565b9350606087013591508082111561053757600080fd5b506105448782880161047c565b91505092959194509250565b600067ffffffffffffffff82111561056a5761056a6103b4565b5060051b60200190565b803563ffffffff8116811461058857600080fd5b919050565b600082601f83011261059e57600080fd5b813560206105b36105ae83610550565b6103f3565b82815260059290921b840181019181810190868411156105d257600080fd5b8286015b8481101561061257803567ffffffffffffffff8111156105f65760008081fd5b6106048986838b010161047c565b8452509183019183016105d6565b509695505050505050565b6000806040838503121561063057600080fd5b823567ffffffffffffffff8082111561064857600080fd5b818501915085601f83011261065c57600080fd5b8135602061066c6105ae83610550565b82815260059290921b8401810191818101908984111561068b57600080fd5b8286015b8481101561079d578035868111156106a657600080fd5b87016060818d03601f190112156106bc57600080fd5b6106c46103ca565b6106cf868301610574565b81526040820135888111156106e357600080fd5b8201603f81018e136106f457600080fd5b6107058e8883013560408401610424565b878301525060608201358881111561071c57600080fd5b8083019250508c603f83011261073157600080fd5b858201356107416105ae82610550565b81815260059190911b830160400190878101908f83111561076157600080fd5b6040850194505b828510156107885761077985610574565b82529388019390880190610768565b6040840152505084525091830191830161068f565b50965050860135925050808211156107b457600080fd5b506107c18582860161058d565b9150509250929050565b6000815180845260005b818110156107f1576020818501810151868301820152016107d5565b81811115610803576000602083870101525b50601f01601f19169290920160200192915050565b60a08152600061082b60a08301886107cb565b60208382038185015261083e82896107cb565b915083820360408501528187518084528284019150828160051b850101838a0160005b8381101561088f57601f1987840301855261087d8383516107cb565b94860194925090850190600101610861565b505086810360608801526108a3818a6107cb565b955050505050506108b8608083018415159052565b9695505050505050565b600080604083850312156108d557600080fd5b823567ffffffffffffffff808211156108ed57600080fd5b6108f98683870161047c565b9350602085013591508082111561090f57600080fd5b506107c18582860161047c565b600181811c9082168061093057607f821691505b6020821081141561095157634e487b7160e01b600052602260045260246000fd5b50919050565b60608152600061096a60608301866107cb565b60208382038185015261097d82876107cb565b91506040848303818601528286518085528385019150838160051b86010184890160005b838110156109f157878303601f19018552815180518785526109c5888601826107cb565b91890151858303868b01529190506109dd81836107cb565b9689019694505050908601906001016109a1565b50909b9a505050505050505050505056fea2646970667358221220d32b94fab7696bf8cf3fc9b2184f1a396acbf4974cf49a325d576a241e12569564736f6c634300080b0033"; - - #[test] - pub fn test_to_hex() { - // given - let text = "test"; - let byte_code = hex::decode(TO_HEX_BYTE_CODE).unwrap(); - let input_data = - prepare_function_call_input("8876183c", encode(&[Token::String(text.to_string())])) - .unwrap(); - let (_, return_data) = execute_smart_contract(byte_code, input_data); - let types = vec![ethabi::ParamType::Bool, ethabi::ParamType::String]; - - // when - let decoded = ethabi::decode(&types, &return_data).unwrap(); - - // then - assert_eq!(true, decoded[0].clone().into_bool().unwrap()); - assert_eq!("0x".to_owned() + &hex::encode(text), decoded[1].clone().into_string().unwrap()); - } - - #[test] - pub fn test_concatenate_strings() { - // given - let byte_code = hex::decode(CONCATENATE_STRINGS_BYTE_CODE).unwrap(); - let input_data = prepare_function_call_input( - "f2baa36e", - encode(&[Token::String("foo".to_string()), Token::String("bar".to_string())]), - ) - .unwrap(); - let (_, return_data) = execute_smart_contract(byte_code, input_data); - let types = vec![ethabi::ParamType::String]; - - // when - let decoded = ethabi::decode(&types, &return_data).unwrap(); - - // then - assert_eq!("foobar", decoded[0].clone().into_string().unwrap()); - } - - #[test] - pub fn test_get_i64() { - run(19530).unwrap(); - - // given - let byte_code = hex::decode(GET_I64_BYTE_CODE).unwrap(); - let input_data = prepare_function_call_input("f5e19bc0", encode(&[Token::String("http://localhost:19530/2/users/by/username/twitterdev?user.fields=public_metrics".to_string()), Token::String("/data/public_metrics/followers_count".to_string())])).unwrap(); - let (_, return_data) = execute_smart_contract(byte_code, input_data); - let types = vec![ethabi::ParamType::Bool, ethabi::ParamType::Int(2)]; - - // when - let decoded = ethabi::decode(&types, &return_data).unwrap(); - - // then - assert_eq!(true, decoded[0].clone().into_bool().unwrap()); - assert_eq!(U256::from(100), decoded[1].clone().into_int().unwrap()); - } - - #[test] - pub fn test_get_i64_with_failure() { - // given - let byte_code = hex::decode(GET_I64_BYTE_CODE).unwrap(); - let input_data = prepare_function_call_input( - "f5e19bc0", - encode(&[ - Token::String( - "http://localhost:1/2/users/by/username/twitterdev?user.fields=public_metrics" - .to_string(), - ), - Token::String("/data/public_metrics/followers_count".to_string()), - ]), - ) - .unwrap(); - let (_, return_data) = execute_smart_contract(byte_code, input_data); - let types = vec![ethabi::ParamType::Bool, ethabi::ParamType::Int(2)]; - - // when - let decoded = ethabi::decode(&types, &return_data).unwrap(); - - // then - assert_eq!(false, decoded[0].clone().into_bool().unwrap()); - assert_eq!(U256::from(0), decoded[1].clone().into_int().unwrap()); - } - - //we want to check here that execution is not interrupted by http error - #[test] - pub fn test_get_i64_returns_second_error_in_case_of_first_request_failure() { - run(19532).unwrap(); - - // given - let byte_code = hex::decode(GET_I64_BYTE_CODE).unwrap(); - let input_data = prepare_function_call_input("ed043e0f", - encode( - &[ - // this one uses different port so service is unavailable - Token::String("http://localhost:1/2/users/by/username/twitterdev?user.fields=public_metrics".to_string()), - Token::String("/data/public_metrics/followers_count".to_string()), - Token::String("http://localhost:19532/2/users/by/username/twitterdev?user.fields=public_metrics".to_string()), - Token::String("/data/public_metrics/followers_count".to_string()) - ] - ) - ).unwrap(); - let (_, return_data) = execute_smart_contract(byte_code, input_data); - let types = vec![ethabi::ParamType::Bool, ethabi::ParamType::Int(2)]; - - // when - let decoded = ethabi::decode(&types, &return_data).unwrap(); - - // then - assert_eq!(true, decoded[0].clone().into_bool().unwrap()); - assert_eq!(U256::from(100), decoded[1].clone().into_int().unwrap()); - } - - #[test] - pub fn test_get_bool_with_success_and_true_result() { - run(19531).unwrap(); - - // given - let byte_code = hex::decode(GET_BOOL_BYTE_CODE).unwrap(); - let input_data = prepare_function_call_input("fe598591", encode(&[Token::String("http://localhost:19531/events/does-user-joined-evm-campaign?account=0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d".to_string()), Token::String("/hasJoined".to_string())])).unwrap(); - let (_, return_data) = execute_smart_contract(byte_code, input_data); - let types = vec![ethabi::ParamType::Bool, ethabi::ParamType::Bool]; - - // when - let decoded = ethabi::decode(&types, &return_data).unwrap(); - - // then - assert_eq!(true, decoded[0].clone().into_bool().unwrap()); - assert_eq!(true, decoded[1].clone().into_bool().unwrap()); - } - - #[test] - pub fn test_get_bool_with_failure() { - // given - let byte_code = hex::decode(GET_BOOL_BYTE_CODE).unwrap(); - let input_data = prepare_function_call_input("fe598591", encode(&[Token::String("http://localhost:1/events/does-user-joined-evm-campaign?account=0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d".to_string()), Token::String("/hasJoined".to_string())])).unwrap(); - let (_, return_data) = execute_smart_contract(byte_code, input_data); - let types = vec![ethabi::ParamType::Bool, ethabi::ParamType::Bool]; - - // when - let decoded = ethabi::decode(&types, &return_data).unwrap(); - - // then - assert_eq!(false, decoded[0].clone().into_bool().unwrap()); - assert_eq!(false, decoded[1].clone().into_bool().unwrap()); - } - - //we want to check here that execution is not interrupted by http error - #[test] - pub fn test_get_bool_returns_second_error_in_case_of_first_request_failure() { - run(19533).unwrap(); - - // given - let byte_code = hex::decode(GET_BOOL_BYTE_CODE).unwrap(); - let input_data = prepare_function_call_input("7083d8ec", - encode( - &[ - // this one uses different port so service is unavailable - Token::String("http://localhost:1/events/does-user-joined-evm-campaign?account=0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d".to_string()), - Token::String("/hasJoined".to_string()), - Token::String("http://localhost:19533/events/does-user-joined-evm-campaign?account=0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d".to_string()), - Token::String("/hasJoined".to_string()) - ] - ) - ).unwrap(); - let (_, return_data) = execute_smart_contract(byte_code, input_data); - let types = vec![ethabi::ParamType::Bool, ethabi::ParamType::Bool]; - - // when - let decoded = ethabi::decode(&types, &return_data).unwrap(); - - // then - assert_eq!(true, decoded[0].clone().into_bool().unwrap()); - assert_eq!(true, decoded[1].clone().into_bool().unwrap()); - } -} - #[cfg(test)] pub mod assertion_test { use crate::dynamic::{build, repository::InMemorySmartContractRepo}; use itp_types::Assertion; use lc_mock_server::run; use lc_stf_task_sender::AssertionBuildRequest; - use litentry_primitives::{Identity, IdentityString}; + use litentry_hex_utils::decode_hex; + use litentry_primitives::{Identity, IdentityString, Web3Network}; use sp_core::{crypto::AccountId32, H160}; #[test] @@ -316,6 +123,8 @@ pub mod assertion_test { // when let credential = build(&request, hash(1), repository.into()).unwrap(); + println!("Credential is: {:?}", credential); + // then assert!(credential.credential_subject.values[0]); } @@ -348,6 +157,8 @@ pub mod assertion_test { // when let credential = build(&request, hash(0), repository.into()).unwrap(); + println!("Credential is: {:?}", credential); + // then assert!(credential.credential_subject.values[0]); } @@ -419,6 +230,53 @@ pub mod assertion_test { assert!(!credential.credential_subject.values[0]); } + #[test] + pub fn test_token_holding_amount_ordi_true() { + let _ = env_logger::builder().is_test(true).try_init(); + run(19529).unwrap(); + // given + // bc1pgr5fw4p9gl9me0vzjklnlnap669caxc0gsk4j62gff2qktlw6naqm4m3d0 + let address = decode_hex( + "0x02e8c39e82aaaa143c3def8d3c7084a539b227244ac9067c3f7fc86cb73a0b7aed" + .as_bytes() + .to_vec(), + ) + .unwrap() + .as_slice() + .try_into() + .unwrap(); + + let network = Web3Network::BitcoinP2tr; + let identities = vec![(Identity::Bitcoin(address), vec![network])]; + let smart_contract_id = hash(3); + + let request = AssertionBuildRequest { + shard: Default::default(), + signer: AccountId32::new([0; 32]), + who: Identity::Substrate(AccountId32::new([0; 32]).into()), + assertion: Assertion::Dynamic(smart_contract_id), + identities, + top_hash: Default::default(), + parachain_block_number: Default::default(), + sidechain_block_number: Default::default(), + parachain_runtime_version: 0u32, + sidechain_runtime_version: 0u32, + maybe_key: None, + req_ext_hash: Default::default(), + should_create_id_graph: Default::default(), + }; + + let repository = InMemorySmartContractRepo::new(); + + // when + let credential = build(&request, smart_contract_id, repository.into()).unwrap(); + + println!("Credential is: {:?}", credential); + + // then + assert!(credential.credential_subject.values[0]); + } + fn hash(a: u64) -> H160 { H160::from_low_u64_be(a) } diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/repository.rs b/tee-worker/litentry/core/assertion-build/src/dynamic/repository.rs index 5352fcc8da..c953c386d4 100644 --- a/tee-worker/litentry/core/assertion-build/src/dynamic/repository.rs +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/repository.rs @@ -49,7 +49,7 @@ impl InMemorySmartContractRepo { map.insert( hash(0), ( - hex::decode("608060405234801561001057600080fd5b50610af2806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063e256184614610030575b600080fd5b61004361003e366004610661565b61005d565b60405161005495949392919061085f565b60405180910390f35b60608060608060008060405180608001604052806045815260200161098460459139604080518082018252601b81527f4261736963204964656e7469747920566572696669636174696f6e000000000060208083019190915260008054600181018255818052845160c08101909552608180865295965092947f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e56390930193909290916109c990830139805161011993925060209091019061041e565b506040518060a0016040528060738152602001610a4a6073913980516101479160019160209091019061041e565b5060008080805b8c518110156101c5576101798d828151811061016c5761016c610909565b6020026020010151610351565b1561018757600191506101b3565b6101a98d828151811061019c5761019c610909565b6020026020010151610380565b156101b357600192505b806101bd8161091f565b91505061014e565b508080156101d05750815b92508484600060018682805480602002602001604051908101604052809291908181526020016000905b828210156102a657838290600052602060002001805461021990610948565b80601f016020809104026020016040519081016040528092919081815260200182805461024590610948565b80156102925780601f1061026757610100808354040283529160200191610292565b820191906000526020600020905b81548152906001019060200180831161027557829003601f168201915b5050505050815260200190600101906101fa565b5050505092508180546102b890610948565b80601f01602080910402602001604051908101604052809291908181526020018280546102e490610948565b80156103315780601f1061030657610100808354040283529160200191610331565b820191906000526020600020905b81548152906001019060200180831161031457829003601f168201915b505050505091509950995099509950995050505050509295509295909350565b600061035c826103a9565b8061036b575061036b826103b6565b8061037a575061037a826103c3565b92915050565b600061038b826103d0565b8061039a575061039a826103dd565b8061037a575061037a826103ea565b600061037a8260006103f3565b600061037a8260016103f3565b600061037a8260026103f3565b600061037a8260036103f3565b600061037a8260046103f3565b600061037a8260055b60008163ffffffff16836000015163ffffffff1614156104155750600161037a565b50600092915050565b82805461042a90610948565b90600052602060002090601f01602090048101928261044c5760008555610492565b82601f1061046557805160ff1916838001178555610492565b82800160010185558215610492579182015b82811115610492578251825591602001919060010190610477565b5061049e9291506104a2565b5090565b5b8082111561049e57600081556001016104a3565b634e487b7160e01b600052604160045260246000fd5b6040516060810167ffffffffffffffff811182821017156104f0576104f06104b7565b60405290565b604051601f8201601f1916810167ffffffffffffffff8111828210171561051f5761051f6104b7565b604052919050565b600067ffffffffffffffff821115610541576105416104b7565b5060051b60200190565b803563ffffffff8116811461055f57600080fd5b919050565b600067ffffffffffffffff83111561057e5761057e6104b7565b610591601f8401601f19166020016104f6565b90508281528383830111156105a557600080fd5b828260208301376000602084830101529392505050565b600082601f8301126105cd57600080fd5b813560206105e26105dd83610527565b6104f6565b82815260059290921b8401810191818101908684111561060157600080fd5b8286015b8481101561065657803567ffffffffffffffff8111156106255760008081fd5b8701603f810189136106375760008081fd5b610648898683013560408401610564565b845250918301918301610605565b509695505050505050565b6000806040838503121561067457600080fd5b823567ffffffffffffffff8082111561068c57600080fd5b818501915085601f8301126106a057600080fd5b813560206106b06105dd83610527565b82815260059290921b840181019181810190898411156106cf57600080fd5b8286015b848110156107e2578035868111156106ea57600080fd5b87016060818d03601f1901121561070057600080fd5b6107086104cd565b61071386830161054b565b815260408201358881111561072757600080fd5b8201603f81018e1361073857600080fd5b6107498e8883013560408401610564565b878301525060608201358881111561076057600080fd5b8083019250508c603f83011261077557600080fd5b858201356107856105dd82610527565b81815260059190911b83018701870190878101908f8311156107a657600080fd5b6040850194505b828510156107cd576107be8561054b565b825293880193908801906107ad565b604084015250508452509183019183016106d3565b50965050860135925050808211156107f957600080fd5b50610806858286016105bc565b9150509250929050565b60008151808452602060005b8281101561083757848101820151868201830152810161081c565b828111156108485760008284880101525b5080601f19601f8401168601019250505092915050565b60a08152600061087260a0830188610810565b6020838203818501526108858289610810565b915083820360408501528187518084528284019150828160051b850101838a0160005b838110156108d657601f198784030185526108c4838351610810565b948601949250908501906001016108a8565b505086810360608801526108ea818a610810565b955050505050506108ff608083018415159052565b9695505050505050565b634e487b7160e01b600052603260045260246000fd5b600060001982141561094157634e487b7160e01b600052601160045260246000fd5b5060010190565b600181811c9082168061095c57607f821691505b6020821081141561097d57634e487b7160e01b600052602260045260246000fd5b5091905056fe596f75277665206964656e746966696564206174206c65617374206f6e65206163636f756e742f6164647265737320696e20626f7468205765623220616e6420576562332e7b22616e64223a205b7b2022737263223a2022246861735f776562325f6163636f756e74222c20226f70223a20223d3d222c2022647374223a20227472756522207d2c207b2022737263223a2022246861735f776562335f6163636f756e74222c20226f70223a20223d3d222c2022647374223a20227472756522207d205d207d68747470733a2f2f7261772e67697468756275736572636f6e74656e742e636f6d2f6c6974656e7472792f76632d6a736f6e736368656d612f6d61696e2f646973742f736368656d61732f312d62617369632d6964656e746974792d766572696669636174696f6e2f312d302d302e6a736f6ea264697066735822122008b51c7962c3c5639c7c2aac2c98e97f666aa49e961a5e962f030f4ac4a9a47d64736f6c634300080b0033").unwrap(), + hex::decode("608060405234801561001057600080fd5b50611931806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063e256184614610030575b600080fd5b61004a600480360381019061004591906110c9565b610064565b60405161005b9594939291906112f0565b60405180910390f35b60608060608060008060405180608001604052806045815260200161184460459139905060006040518060400160405280601b81526020017f4261736963204964656e7469747920566572696669636174696f6e000000000081525090506040518060a001604052806073815260200161188960739139600090805190602001906100f0929190610a70565b50600080600090506000805b8c51811015610177576101288d828151811061011b5761011a61135f565b5b6020026020010151610410565b156101365760019150610164565b6101598d828151811061014c5761014b61135f565b5b6020026020010151610442565b1561016357600192505b5b808061016f906113c7565b9150506100fc565b508080156101825750815b925060006040518060400160405280600267ffffffffffffffff8111156101ac576101ab610b8c565b5b6040519080825280602002602001820160405280156101e557816020015b6101d2610af6565b8152602001906001900390816101ca5790505b50815260200160011515815250905061026d8160006040518060400160405280601181526020017f246861735f776562325f6163636f756e7400000000000000000000000000000081525060046040518060400160405280600481526020017f7472756500000000000000000000000000000000000000000000000000000000815250610474565b506102e78160016040518060400160405280601181526020017f246861735f776562335f6163636f756e7400000000000000000000000000000081525060046040518060400160405280600481526020017f7472756500000000000000000000000000000000000000000000000000000000815250610474565b506000600167ffffffffffffffff81111561030557610304610b8c565b5b60405190808252806020026020018201604052801561033857816020015b60608152602001906001900390816103235790505b509050610344826104a6565b816000815181106103585761035761135f565b5b60200260200101819052508686826000888180546103759061143f565b80601f01602080910402602001604051908101604052809291908181526020018280546103a19061143f565b80156103ee5780601f106103c3576101008083540402835291602001916103ee565b820191906000526020600020905b8154815290600101906020018083116103d157829003601f168201915b505050505091509b509b509b509b509b50505050505050509295509295909350565b600061041b82610676565b8061042b575061042a8261068a565b5b8061043b575061043a8261069e565b5b9050919050565b600061044d826106b2565b8061045d575061045c826106c6565b5b8061046d575061046c826106da565b5b9050919050565b61047c610b29565b61048986868686866106ee565b600186602001901515908115158152505085905095945050505050565b606060006040518060400160405280600181526020017f7b0000000000000000000000000000000000000000000000000000000000000081525090506000836000015151111561064b57808360200151610535576040518060400160405280600681526020017f226f72223a5b000000000000000000000000000000000000000000000000000081525061056c565b6040518060400160405280600781526020017f22616e64223a5b000000000000000000000000000000000000000000000000008152505b60405160200161057d9291906114ad565b604051602081830303815290604052905060005b8360000151518110156106275760008111156105ca57816040516020016105b8919061151d565b60405160208183030381529060405291505b816105f2856000015183815181106105e5576105e461135f565b5b6020026020010151610744565b6040516020016106039291906114ad565b6040516020818303038152906040529150808061061f906113c7565b915050610591565b5080604051602001610639919061158b565b60405160208183030381529060405290505b8060405160200161065c91906115f9565b604051602081830303815290604052905080915050919050565b6000610683826000610785565b9050919050565b6000610697826001610785565b9050919050565b60006106ab826002610785565b9050919050565b60006106bf826003610785565b9050919050565b60006106d3826004610785565b9050919050565b60006106e7826005610785565b9050919050565b60405180606001604052808481526020018360058111156107125761071161161b565b5b815260200182815250856000015185815181106107325761073161135f565b5b60200260200101819052505050505050565b6060816000015161075883602001516107b3565b836040015160405160200161076f9392919061177a565b6040516020818303038152906040529050919050565b60008163ffffffff16836000015163ffffffff1614156107a857600190506107ad565b600090505b92915050565b6060600460058111156107c9576107c861161b565b5b8260058111156107dc576107db61161b565b5b141561081f576040518060400160405280600281526020017f3d3d0000000000000000000000000000000000000000000000000000000000008152509050610a6b565b600060058111156108335761083261161b565b5b8260058111156108465761084561161b565b5b1415610889576040518060400160405280600181526020017f3e000000000000000000000000000000000000000000000000000000000000008152509050610a6b565b6001600581111561089d5761089c61161b565b5b8260058111156108b0576108af61161b565b5b14156108f3576040518060400160405280600181526020017f3c000000000000000000000000000000000000000000000000000000000000008152509050610a6b565b600260058111156109075761090661161b565b5b82600581111561091a5761091961161b565b5b141561095d576040518060400160405280600281526020017f3e3d0000000000000000000000000000000000000000000000000000000000008152509050610a6b565b600360058111156109715761097061161b565b5b8260058111156109845761098361161b565b5b14156109c7576040518060400160405280600281526020017f3c3d0000000000000000000000000000000000000000000000000000000000008152509050610a6b565b6005808111156109da576109d961161b565b5b8260058111156109ed576109ec61161b565b5b1415610a30576040518060400160405280600281526020017f213d0000000000000000000000000000000000000000000000000000000000008152509050610a6b565b6040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a6290611823565b60405180910390fd5b919050565b828054610a7c9061143f565b90600052602060002090601f016020900481019282610a9e5760008555610ae5565b82601f10610ab757805160ff1916838001178555610ae5565b82800160010185558215610ae5579182015b82811115610ae4578251825591602001919060010190610ac9565b5b509050610af29190610b45565b5090565b60405180606001604052806060815260200160006005811115610b1c57610b1b61161b565b5b8152602001606081525090565b6040518060400160405280606081526020016000151581525090565b5b80821115610b5e576000816000905550600101610b46565b5090565b6000604051905090565b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b610bc482610b7b565b810181811067ffffffffffffffff82111715610be357610be2610b8c565b5b80604052505050565b6000610bf6610b62565b9050610c028282610bbb565b919050565b600067ffffffffffffffff821115610c2257610c21610b8c565b5b602082029050602081019050919050565b600080fd5b600080fd5b600080fd5b600063ffffffff82169050919050565b610c5b81610c42565b8114610c6657600080fd5b50565b600081359050610c7881610c52565b92915050565b600080fd5b600067ffffffffffffffff821115610c9e57610c9d610b8c565b5b610ca782610b7b565b9050602081019050919050565b82818337600083830152505050565b6000610cd6610cd184610c83565b610bec565b905082815260208101848484011115610cf257610cf1610c7e565b5b610cfd848285610cb4565b509392505050565b600082601f830112610d1a57610d19610b76565b5b8135610d2a848260208601610cc3565b91505092915050565b600067ffffffffffffffff821115610d4e57610d4d610b8c565b5b602082029050602081019050919050565b6000610d72610d6d84610d33565b610bec565b90508083825260208201905060208402830185811115610d9557610d94610c33565b5b835b81811015610dbe5780610daa8882610c69565b845260208401935050602081019050610d97565b5050509392505050565b600082601f830112610ddd57610ddc610b76565b5b8135610ded848260208601610d5f565b91505092915050565b600060608284031215610e0c57610e0b610c38565b5b610e166060610bec565b90506000610e2684828501610c69565b600083015250602082013567ffffffffffffffff811115610e4a57610e49610c3d565b5b610e5684828501610d05565b602083015250604082013567ffffffffffffffff811115610e7a57610e79610c3d565b5b610e8684828501610dc8565b60408301525092915050565b6000610ea5610ea084610c07565b610bec565b90508083825260208201905060208402830185811115610ec857610ec7610c33565b5b835b81811015610f0f57803567ffffffffffffffff811115610eed57610eec610b76565b5b808601610efa8982610df6565b85526020850194505050602081019050610eca565b5050509392505050565b600082601f830112610f2e57610f2d610b76565b5b8135610f3e848260208601610e92565b91505092915050565b600067ffffffffffffffff821115610f6257610f61610b8c565b5b602082029050602081019050919050565b600067ffffffffffffffff821115610f8e57610f8d610b8c565b5b610f9782610b7b565b9050602081019050919050565b6000610fb7610fb284610f73565b610bec565b905082815260208101848484011115610fd357610fd2610c7e565b5b610fde848285610cb4565b509392505050565b600082601f830112610ffb57610ffa610b76565b5b813561100b848260208601610fa4565b91505092915050565b600061102761102284610f47565b610bec565b9050808382526020820190506020840283018581111561104a57611049610c33565b5b835b8181101561109157803567ffffffffffffffff81111561106f5761106e610b76565b5b80860161107c8982610fe6565b8552602085019450505060208101905061104c565b5050509392505050565b600082601f8301126110b0576110af610b76565b5b81356110c0848260208601611014565b91505092915050565b600080604083850312156110e0576110df610b6c565b5b600083013567ffffffffffffffff8111156110fe576110fd610b71565b5b61110a85828601610f19565b925050602083013567ffffffffffffffff81111561112b5761112a610b71565b5b6111378582860161109b565b9150509250929050565b600081519050919050565b600082825260208201905092915050565b60005b8381101561117b578082015181840152602081019050611160565b8381111561118a576000848401525b50505050565b600061119b82611141565b6111a5818561114c565b93506111b581856020860161115d565b6111be81610b7b565b840191505092915050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b600082825260208201905092915050565b600061121182611141565b61121b81856111f5565b935061122b81856020860161115d565b61123481610b7b565b840191505092915050565b600061124b8383611206565b905092915050565b6000602082019050919050565b600061126b826111c9565b61127581856111d4565b935083602082028501611287856111e5565b8060005b858110156112c357848403895281516112a4858261123f565b94506112af83611253565b925060208a0199505060018101905061128b565b50829750879550505050505092915050565b60008115159050919050565b6112ea816112d5565b82525050565b600060a082019050818103600083015261130a8188611190565b9050818103602083015261131e8187611190565b905081810360408301526113328186611260565b905081810360608301526113468185611190565b905061135560808301846112e1565b9695505050505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000819050919050565b60006113d2826113bd565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156114055761140461138e565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000600282049050600182168061145757607f821691505b6020821081141561146b5761146a611410565b5b50919050565b600081905092915050565b600061148782611141565b6114918185611471565b93506114a181856020860161115d565b80840191505092915050565b60006114b9828561147c565b91506114c5828461147c565b91508190509392505050565b7f2c00000000000000000000000000000000000000000000000000000000000000600082015250565b6000611507600183611471565b9150611512826114d1565b600182019050919050565b6000611529828461147c565b9150611534826114fa565b915081905092915050565b7f5d00000000000000000000000000000000000000000000000000000000000000600082015250565b6000611575600183611471565b91506115808261153f565b600182019050919050565b6000611597828461147c565b91506115a282611568565b915081905092915050565b7f7d00000000000000000000000000000000000000000000000000000000000000600082015250565b60006115e3600183611471565b91506115ee826115ad565b600182019050919050565b6000611605828461147c565b9150611610826115d6565b915081905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b7f7b22737263223a22000000000000000000000000000000000000000000000000600082015250565b6000611680600883611471565b915061168b8261164a565b600882019050919050565b7f222c226f70223a22000000000000000000000000000000000000000000000000600082015250565b60006116cc600883611471565b91506116d782611696565b600882019050919050565b7f222c22647374223a220000000000000000000000000000000000000000000000600082015250565b6000611718600983611471565b9150611723826116e2565b600982019050919050565b7f227d000000000000000000000000000000000000000000000000000000000000600082015250565b6000611764600283611471565b915061176f8261172e565b600282019050919050565b600061178582611673565b9150611791828661147c565b915061179c826116bf565b91506117a8828561147c565b91506117b38261170b565b91506117bf828461147c565b91506117ca82611757565b9150819050949350505050565b7f556e737570706f72746564206f70657261746f72000000000000000000000000600082015250565b600061180d60148361114c565b9150611818826117d7565b602082019050919050565b6000602082019050818103600083015261183c81611800565b905091905056fe596f75277665206964656e746966696564206174206c65617374206f6e65206163636f756e742f6164647265737320696e20626f7468205765623220616e6420576562332e68747470733a2f2f7261772e67697468756275736572636f6e74656e742e636f6d2f6c6974656e7472792f76632d6a736f6e736368656d612f6d61696e2f646973742f736368656d61732f312d62617369632d6964656e746974792d766572696669636174696f6e2f312d302d302e6a736f6ea264697066735822122053e670b8fe1b1c4e4cefd4033a80c7271cc1d59fea6ede4d1494600bcc23380e64736f6c634300080b0033").unwrap(), vec![] ) ); @@ -57,7 +57,7 @@ impl InMemorySmartContractRepo { map.insert( hash(1), ( - hex::decode("608060405234801561001057600080fd5b50610d8b806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063e256184614610030575b600080fd5b61004361003e3660046107c1565b61005d565b6040516100549594939291906109cb565b60405180910390f35b6060806060806000806040518060c0016040528060868152602001610c5960869139604080518082018252601c81527f49444875622045564d2056657273696f6e204561726c7920426972640000000060208083019190915260008054600181018255818052845160608101909552603380865295965092947f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e5639093019390929091610cdf90830139805161011993925060209091019061057e565b506040518060a0016040528060758152602001610be46075913980516101479160019160209091019061057e565b506000805b8a51811015610289576101778b828151811061016a5761016a610a75565b6020026020010151610407565b15610277576000806101a58d848151811061019457610194610a75565b602002602001015160200151610436565b91509150811561026757816101bb575050610277565b60006101df604051806080016040528060448152602001610d126044913983610498565b604080518082018252600a8152690bda185cd29bda5b995960b21b60208083019190915282516000808252918101909352929350919081610242565b604080518082019091526060808252602082015281526020019060019003908161021b5790505b5090506000806102538585856104c7565b915091508115610261578098505b50505050505b8315610274575050610289565b50505b8061028181610a8b565b91505061014c565b508282600060018482805480602002602001604051908101604052809291908181526020016000905b8282101561035e5783829060005260206000200180546102d190610ab4565b80601f01602080910402602001604051908101604052809291908181526020018280546102fd90610ab4565b801561034a5780601f1061031f5761010080835404028352916020019161034a565b820191906000526020600020905b81548152906001019060200180831161032d57829003601f168201915b5050505050815260200190600101906102b2565b50505050925081805461037090610ab4565b80601f016020809104026020016040519081016040528092919081815260200182805461039c90610ab4565b80156103e95780601f106103be576101008083540402835291602001916103e9565b820191906000526020600020905b8154815290600101906020018083116103cc57829003601f168201915b50505050509150975097509750975097505050509295509295909350565b600061041282610531565b8061042157506104218261053e565b8061043057506104308261054b565b92915050565b6000606060008360405160200161044d9190610aef565b60408051601f1981840301815290829052805190925090611000818360208601600061041b600019f161047f57600080fd5b8094506040810193506110008101604052505050915091565b6060600083836040516020016104af929190610b09565b60408051808303601f19018152919052949350505050565b60008060008060008787876040516020016104e493929190610b38565b60408051601f198184030181528282528051909350919081836020860160006103e9600019f161051357600080fd5b8051602082015160409283019092529a909950975050505050505050565b6000610430826003610554565b6000610430826004610554565b60006104308260055b60008163ffffffff16836000015163ffffffff16141561057657506001610430565b506000610430565b82805461058a90610ab4565b90600052602060002090601f0160209004810192826105ac57600085556105f2565b82601f106105c557805160ff19168380011785556105f2565b828001600101855582156105f2579182015b828111156105f25782518255916020019190600101906105d7565b506105fe929150610602565b5090565b5b808211156105fe5760008155600101610603565b634e487b7160e01b600052604160045260246000fd5b6040516060810167ffffffffffffffff8111828210171561065057610650610617565b60405290565b604051601f8201601f1916810167ffffffffffffffff8111828210171561067f5761067f610617565b604052919050565b600067ffffffffffffffff8211156106a1576106a1610617565b5060051b60200190565b803563ffffffff811681146106bf57600080fd5b919050565b600067ffffffffffffffff8311156106de576106de610617565b6106f1601f8401601f1916602001610656565b905082815283838301111561070557600080fd5b828260208301376000602084830101529392505050565b600082601f83011261072d57600080fd5b8135602061074261073d83610687565b610656565b82815260059290921b8401810191818101908684111561076157600080fd5b8286015b848110156107b657803567ffffffffffffffff8111156107855760008081fd5b8701603f810189136107975760008081fd5b6107a88986830135604084016106c4565b845250918301918301610765565b509695505050505050565b600080604083850312156107d457600080fd5b823567ffffffffffffffff808211156107ec57600080fd5b818501915085601f83011261080057600080fd5b8135602061081061073d83610687565b82815260059290921b8401810191818101908984111561082f57600080fd5b8286015b848110156109415780358681111561084a57600080fd5b87016060818d03601f1901121561086057600080fd5b61086861062d565b6108738683016106ab565b815260408201358881111561088757600080fd5b8201603f81018e1361089857600080fd5b6108a98e88830135604084016106c4565b87830152506060820135888111156108c057600080fd5b8083019250508c603f8301126108d557600080fd5b858201356108e561073d82610687565b81815260059190911b830160400190878101908f83111561090557600080fd5b6040850194505b8285101561092c5761091d856106ab565b8252938801939088019061090c565b60408401525050845250918301918301610833565b509650508601359250508082111561095857600080fd5b506109658582860161071c565b9150509250929050565b60005b8381101561098a578181015183820152602001610972565b83811115610999576000848401525b50505050565b600081518084526109b781602086016020860161096f565b601f01601f19169290920160200192915050565b60a0815260006109de60a083018861099f565b6020838203818501526109f1828961099f565b915083820360408501528187518084528284019150828160051b850101838a0160005b83811015610a4257601f19878403018552610a3083835161099f565b94860194925090850190600101610a14565b50508681036060880152610a56818a61099f565b95505050505050610a6b608083018415159052565b9695505050505050565b634e487b7160e01b600052603260045260246000fd5b6000600019821415610aad57634e487b7160e01b600052601160045260246000fd5b5060010190565b600181811c90821680610ac857607f821691505b60208210811415610ae957634e487b7160e01b600052602260045260246000fd5b50919050565b602081526000610b02602083018461099f565b9392505050565b60008351610b1b81846020880161096f565b835190830190610b2f81836020880161096f565b01949350505050565b606081526000610b4b606083018661099f565b602083820381850152610b5e828761099f565b91506040848303818601528286518085528385019150838160051b86010184890160005b83811015610bd257878303601f1901855281518051878552610ba68886018261099f565b91890151858303868b0152919050610bbe818361099f565b968901969450505090860190600101610b82565b50909b9a505050505050505050505056fe68747470733a2f2f7261772e67697468756275736572636f6e74656e742e636f6d2f6c6974656e7472792f76632d6a736f6e736368656d612f6d61696e2f646973742f736368656d61732f31322d69646875622d65766d2d76657273696f6e2d6561726c792d626972642f312d302d302e6a736f6e546865207573657220697320616e206561726c7920626972642075736572206f6620746865204964656e746974794875622045564d2076657273696f6e20616e64206861732067656e657261746564206174206c6561737420312063726564656e7469616c20647572696e672032303233204175672031347468207e2041756720323173742e7b2022737263223a2022246861735f6a6f696e6564222c20226f70223a20223d3d222c2022647374223a20227472756522207d687474703a2f2f6c6f63616c686f73743a31393532372f6576656e74732f646f65732d757365722d6a6f696e65642d65766d2d63616d706169676e3f6163636f756e743da26469706673582212204f649e301bd283e006c1969af8be484a752224ee88424af5f91820ad5acb4e4464736f6c634300080b0033").unwrap(), + hex::decode("608060405234801561001057600080fd5b5061187e806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063e256184614610030575b600080fd5b61004a60048036038101906100459190610ebe565b610064565b60405161005b9594939291906110e5565b60405180910390f35b6060806060806000806040518060c00160405280608681526020016117c360869139905060006040518060400160405280601c81526020017f49444875622045564d2056657273696f6e204561726c7920426972640000000081525090506040518060a001604052806075815260200161174e60759139600090805190602001906100f092919061089a565b506000805b8a51811015610262576101218b828151811061011457610113611154565b5b6020026020010151610425565b1561024e576000806101508d848151811061013f5761013e611154565b5b602002602001015160200151610457565b91509150811561023e578161016657505061024f565b6000816040516020016101799190611257565b604051602081830303815290604052905060006040518060400160405280600a81526020017f2f6861734a6f696e656400000000000000000000000000000000000000000000815250905060008067ffffffffffffffff8111156101e0576101df610981565b5b60405190808252806020026020018201604052801561021957816020015b610206610920565b8152602001906001900390816101fe5790505b50905060008061022a8585856104bc565b915091508115610238578098505b50505050505b831561024b575050610262565b50505b5b808061025a906112b2565b9150506100f5565b50600060405180606001604052806040518060400160405280600b81526020017f246861735f6a6f696e65640000000000000000000000000000000000000000008152508152602001600460058111156102bf576102be6112fb565b5b81526020016040518060400160405280600481526020017f747275650000000000000000000000000000000000000000000000000000000081525081525090506000600167ffffffffffffffff81111561031c5761031b610981565b5b60405190808252806020026020018201604052801561034f57816020015b606081526020019060019003908161033a5790505b50905061035b82610532565b8160008151811061036f5761036e611154565b5b602002602001018190525084848260008681805461038c90611359565b80601f01602080910402602001604051908101604052809291908181526020018280546103b890611359565b80156104055780601f106103da57610100808354040283529160200191610405565b820191906000526020600020905b8154815290600101906020018083116103e857829003601f168201915b505050505091509950995099509950995050505050509295509295909350565b600061043082610573565b80610440575061043f82610587565b5b80610450575061044f8261059b565b5b9050919050565b6000606060008360405160200161046e91906113e0565b6040516020818303038152906040529050600081519050604051611000818360208601600061041b600019f16104a357600080fd5b8094506040810193506110008101604052505050915091565b60008060008060008787876040516020016104d993929190611508565b6040516020818303038152906040529050600081519050604051604081836020860160006103e9600019f161050d57600080fd5b8051945060208101519350604081016040525083839550955050505050935093915050565b6060816000015161054683602001516105af565b836040015160405160200161055d93929190611684565b6040516020818303038152906040529050919050565b600061058082600361086c565b9050919050565b600061059482600461086c565b9050919050565b60006105a882600561086c565b9050919050565b6060600460058111156105c5576105c46112fb565b5b8260058111156105d8576105d76112fb565b5b141561061b576040518060400160405280600281526020017f3d3d0000000000000000000000000000000000000000000000000000000000008152509050610867565b6000600581111561062f5761062e6112fb565b5b826005811115610642576106416112fb565b5b1415610685576040518060400160405280600181526020017f3e000000000000000000000000000000000000000000000000000000000000008152509050610867565b60016005811115610699576106986112fb565b5b8260058111156106ac576106ab6112fb565b5b14156106ef576040518060400160405280600181526020017f3c000000000000000000000000000000000000000000000000000000000000008152509050610867565b60026005811115610703576107026112fb565b5b826005811115610716576107156112fb565b5b1415610759576040518060400160405280600281526020017f3e3d0000000000000000000000000000000000000000000000000000000000008152509050610867565b6003600581111561076d5761076c6112fb565b5b8260058111156107805761077f6112fb565b5b14156107c3576040518060400160405280600281526020017f3c3d0000000000000000000000000000000000000000000000000000000000008152509050610867565b6005808111156107d6576107d56112fb565b5b8260058111156107e9576107e86112fb565b5b141561082c576040518060400160405280600281526020017f213d0000000000000000000000000000000000000000000000000000000000008152509050610867565b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161085e9061172d565b60405180910390fd5b919050565b60008163ffffffff16836000015163ffffffff16141561088f5760019050610894565b600090505b92915050565b8280546108a690611359565b90600052602060002090601f0160209004810192826108c8576000855561090f565b82601f106108e157805160ff191683800117855561090f565b8280016001018555821561090f579182015b8281111561090e5782518255916020019190600101906108f3565b5b50905061091c919061093a565b5090565b604051806040016040528060608152602001606081525090565b5b8082111561095357600081600090555060010161093b565b5090565b6000604051905090565b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6109b982610970565b810181811067ffffffffffffffff821117156109d8576109d7610981565b5b80604052505050565b60006109eb610957565b90506109f782826109b0565b919050565b600067ffffffffffffffff821115610a1757610a16610981565b5b602082029050602081019050919050565b600080fd5b600080fd5b600080fd5b600063ffffffff82169050919050565b610a5081610a37565b8114610a5b57600080fd5b50565b600081359050610a6d81610a47565b92915050565b600080fd5b600067ffffffffffffffff821115610a9357610a92610981565b5b610a9c82610970565b9050602081019050919050565b82818337600083830152505050565b6000610acb610ac684610a78565b6109e1565b905082815260208101848484011115610ae757610ae6610a73565b5b610af2848285610aa9565b509392505050565b600082601f830112610b0f57610b0e61096b565b5b8135610b1f848260208601610ab8565b91505092915050565b600067ffffffffffffffff821115610b4357610b42610981565b5b602082029050602081019050919050565b6000610b67610b6284610b28565b6109e1565b90508083825260208201905060208402830185811115610b8a57610b89610a28565b5b835b81811015610bb35780610b9f8882610a5e565b845260208401935050602081019050610b8c565b5050509392505050565b600082601f830112610bd257610bd161096b565b5b8135610be2848260208601610b54565b91505092915050565b600060608284031215610c0157610c00610a2d565b5b610c0b60606109e1565b90506000610c1b84828501610a5e565b600083015250602082013567ffffffffffffffff811115610c3f57610c3e610a32565b5b610c4b84828501610afa565b602083015250604082013567ffffffffffffffff811115610c6f57610c6e610a32565b5b610c7b84828501610bbd565b60408301525092915050565b6000610c9a610c95846109fc565b6109e1565b90508083825260208201905060208402830185811115610cbd57610cbc610a28565b5b835b81811015610d0457803567ffffffffffffffff811115610ce257610ce161096b565b5b808601610cef8982610beb565b85526020850194505050602081019050610cbf565b5050509392505050565b600082601f830112610d2357610d2261096b565b5b8135610d33848260208601610c87565b91505092915050565b600067ffffffffffffffff821115610d5757610d56610981565b5b602082029050602081019050919050565b600067ffffffffffffffff821115610d8357610d82610981565b5b610d8c82610970565b9050602081019050919050565b6000610dac610da784610d68565b6109e1565b905082815260208101848484011115610dc857610dc7610a73565b5b610dd3848285610aa9565b509392505050565b600082601f830112610df057610def61096b565b5b8135610e00848260208601610d99565b91505092915050565b6000610e1c610e1784610d3c565b6109e1565b90508083825260208201905060208402830185811115610e3f57610e3e610a28565b5b835b81811015610e8657803567ffffffffffffffff811115610e6457610e6361096b565b5b808601610e718982610ddb565b85526020850194505050602081019050610e41565b5050509392505050565b600082601f830112610ea557610ea461096b565b5b8135610eb5848260208601610e09565b91505092915050565b60008060408385031215610ed557610ed4610961565b5b600083013567ffffffffffffffff811115610ef357610ef2610966565b5b610eff85828601610d0e565b925050602083013567ffffffffffffffff811115610f2057610f1f610966565b5b610f2c85828601610e90565b9150509250929050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610f70578082015181840152602081019050610f55565b83811115610f7f576000848401525b50505050565b6000610f9082610f36565b610f9a8185610f41565b9350610faa818560208601610f52565b610fb381610970565b840191505092915050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b600082825260208201905092915050565b600061100682610f36565b6110108185610fea565b9350611020818560208601610f52565b61102981610970565b840191505092915050565b60006110408383610ffb565b905092915050565b6000602082019050919050565b600061106082610fbe565b61106a8185610fc9565b93508360208202850161107c85610fda565b8060005b858110156110b857848403895281516110998582611034565b94506110a483611048565b925060208a01995050600181019050611080565b50829750879550505050505092915050565b60008115159050919050565b6110df816110ca565b82525050565b600060a08201905081810360008301526110ff8188610f85565b905081810360208301526111138187610f85565b905081810360408301526111278186611055565b9050818103606083015261113b8185610f85565b905061114a60808301846110d6565b9695505050505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600081905092915050565b7f687474703a2f2f6c6f63616c686f73743a31393532372f6576656e74732f646f60008201527f65732d757365722d6a6f696e65642d65766d2d63616d706169676e3f6163636f60208201527f756e743d00000000000000000000000000000000000000000000000000000000604082015250565b6000611210604483611183565b915061121b8261118e565b604482019050919050565b600061123182610f36565b61123b8185611183565b935061124b818560208601610f52565b80840191505092915050565b600061126282611203565b915061126e8284611226565b915081905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000819050919050565b60006112bd826112a8565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156112f0576112ef611279565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000600282049050600182168061137157607f821691505b602082108114156113855761138461132a565b5b50919050565b600081519050919050565b600082825260208201905092915050565b60006113b28261138b565b6113bc8185611396565b93506113cc818560208601610f52565b6113d581610970565b840191505092915050565b600060208201905081810360008301526113fa81846113a7565b905092915050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b6000604083016000830151848203600086015261144b8282610ffb565b915050602083015184820360208601526114658282610ffb565b9150508091505092915050565b600061147e838361142e565b905092915050565b6000602082019050919050565b600061149e82611402565b6114a8818561140d565b9350836020820285016114ba8561141e565b8060005b858110156114f657848403895281516114d78582611472565b94506114e283611486565b925060208a019950506001810190506114be565b50829750879550505050505092915050565b600060608201905081810360008301526115228186610f85565b905081810360208301526115368185610f85565b9050818103604083015261154a8184611493565b9050949350505050565b7f7b22737263223a22000000000000000000000000000000000000000000000000600082015250565b600061158a600883611183565b915061159582611554565b600882019050919050565b7f222c226f70223a22000000000000000000000000000000000000000000000000600082015250565b60006115d6600883611183565b91506115e1826115a0565b600882019050919050565b7f222c22647374223a220000000000000000000000000000000000000000000000600082015250565b6000611622600983611183565b915061162d826115ec565b600982019050919050565b7f227d000000000000000000000000000000000000000000000000000000000000600082015250565b600061166e600283611183565b915061167982611638565b600282019050919050565b600061168f8261157d565b915061169b8286611226565b91506116a6826115c9565b91506116b28285611226565b91506116bd82611615565b91506116c98284611226565b91506116d482611661565b9150819050949350505050565b7f556e737570706f72746564206f70657261746f72000000000000000000000000600082015250565b6000611717601483610f41565b9150611722826116e1565b602082019050919050565b600060208201905081810360008301526117468161170a565b905091905056fe68747470733a2f2f7261772e67697468756275736572636f6e74656e742e636f6d2f6c6974656e7472792f76632d6a736f6e736368656d612f6d61696e2f646973742f736368656d61732f31322d69646875622d65766d2d76657273696f6e2d6561726c792d626972642f312d302d302e6a736f6e546865207573657220697320616e206561726c7920626972642075736572206f6620746865204964656e746974794875622045564d2076657273696f6e20616e64206861732067656e657261746564206174206c6561737420312063726564656e7469616c20647572696e672032303233204175672031347468207e2041756720323173742ea264697066735822122090cf23f152f2d9cfea04cb86965f7493d24f0fa9625060e087d9cd2566c4d51164736f6c634300080b0033").unwrap(), vec![] ) ); @@ -65,10 +65,19 @@ impl InMemorySmartContractRepo { map.insert( hash(2), ( - hex::decode("608060405234801561001057600080fd5b50611148806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063e256184614610030575b600080fd5b61004361003e366004610b55565b61005d565b604051610054959493929190610d5f565b60405180910390f35b6060806060806000806040518060600160405280602e81526020016110e5602e9139905060006040518060400160405280601781526020017f5477697474657220466f6c6c6f77657220416d6f756e7400000000000000000081525090506040518060a00160405280606f8152602001610fdb606f913980516100e89160019160209091019061091b565b50600080805b8b51811015610220576101198c828151811061010c5761010c610e09565b6020026020010151610579565b1561020e57600061015f6040518060600160405280602b8152602001611081602b91398e848151811061014e5761014e610e09565b60200260200101516020015161058c565b905060006101a2826040518060400160405280601b81526020017f3f757365722e6669656c64733d7075626c69635f6d657472696373000000000081525061058c565b905060006101c98e6000815181106101bc576101bc610e09565b60200260200101516105bb565b90506000806101f184604051806060016040528060248152602001610fb7602491398561065e565b915091508115610208576102058188610e35565b96505b50505050505b8061021881610e86565b9150506100ee565b5060008060008360070b1215801561023c575060018360070b13155b1561024d5750600090506001610318565b60018360070b138015610264575060648360070b13155b156102755750600190506064610318565b60648360070b13801561028d57506103e88360070b13155b1561029f5750606490506103e8610318565b6103e88360070b1380156102b857506127108360070b13155b156102cb57506103e89050612710610318565b6127108360070b1380156102e55750620186a08360070b13155b156102f957506127109050620186a0610318565b620186a08360070b13156103185750620186a09050677fffffffffffffff5b8160070b60001415935060006103516040518060600160405280603981526020016110ac6039913961034c8560070b6106c8565b61058c565b90506103758160405180606001604052806037815260200161104a6037913961058c565b90506103878161034c8460070b6106c8565b90506103b2816040518060400160405280600781526020016622207d205d207d60c81b81525061058c565b6000805460018101825590805281519192506103f7917f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e56390910190602084019061091b565b508686600060018882805480602002602001604051908101604052809291908181526020016000905b828210156104cc57838290600052602060002001805461043f90610ea1565b80601f016020809104026020016040519081016040528092919081815260200182805461046b90610ea1565b80156104b85780601f1061048d576101008083540402835291602001916104b8565b820191906000526020600020905b81548152906001019060200180831161049b57829003601f168201915b505050505081526020019060010190610420565b5050505092508180546104de90610ea1565b80601f016020809104026020016040519081016040528092919081815260200182805461050a90610ea1565b80156105575780601f1061052c57610100808354040283529160200191610557565b820191906000526020600020905b81548152906001019060200180831161053a57829003601f168201915b505050505091509b509b509b509b509b50505050505050509295509295909350565b600061058682600061073a565b92915050565b6060600083836040516020016105a3929190610edc565b60408051808303601f19018152919052949350505050565b60408051600180825281830190925260609160009190816020015b60408051808201909152606080825260208201528152602001906001900390816105d657505060408051608081018252600d9181019182526c30baba3437b934bd30ba34b7b760991b60608201529081529091506020810161063785610764565b8152508160008151811061064d5761064d610e09565b602090810291909101015292915050565b600080600080600087878760405160200161067b93929190610f0b565b60408051601f198184030181528282528051909350919081836020860160006103e8600019f16106aa57600080fd5b8051602082015160409283019092529a909950975050505050505050565b6060600082126106e75760405180602001604052806000815250610702565b604051806040016040528060018152602001602d60f81b8152505b61071361070e8461078f565b6107a6565b604051602001610724929190610edc565b6040516020818303038152906040529050919050565b60008163ffffffff16836000015163ffffffff16141561075c57506001610586565b506000610586565b60606105866040518060400160405280600781526020016602132b0b932b9160cd1b8152508361058c565b6000808212156107a25781600003610586565b5090565b606060006107b383610843565b600101905060008167ffffffffffffffff8111156107d3576107d36109ab565b6040519080825280601f01601f1916602001820160405280156107fd576020820181803683370190505b5090508181016020015b600019016f181899199a1a9b1b9c1cb0b131b232b360811b600a86061a8153600a85049450846108365761083b565b610807565b509392505050565b60008072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b83106108825772184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b830492506040015b6d04ee2d6d415b85acef810000000083106108ae576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc1000083106108cc57662386f26fc10000830492506010015b6305f5e10083106108e4576305f5e100830492506008015b61271083106108f857612710830492506004015b6064831061090a576064830492506002015b600a83106105865760010192915050565b82805461092790610ea1565b90600052602060002090601f016020900481019282610949576000855561098f565b82601f1061096257805160ff191683800117855561098f565b8280016001018555821561098f579182015b8281111561098f578251825591602001919060010190610974565b506107a29291505b808211156107a25760008155600101610997565b634e487b7160e01b600052604160045260246000fd5b6040516060810167ffffffffffffffff811182821017156109e4576109e46109ab565b60405290565b604051601f8201601f1916810167ffffffffffffffff81118282101715610a1357610a136109ab565b604052919050565b600067ffffffffffffffff821115610a3557610a356109ab565b5060051b60200190565b803563ffffffff81168114610a5357600080fd5b919050565b600067ffffffffffffffff831115610a7257610a726109ab565b610a85601f8401601f19166020016109ea565b9050828152838383011115610a9957600080fd5b828260208301376000602084830101529392505050565b600082601f830112610ac157600080fd5b81356020610ad6610ad183610a1b565b6109ea565b82815260059290921b84018101918181019086841115610af557600080fd5b8286015b84811015610b4a57803567ffffffffffffffff811115610b195760008081fd5b8701603f81018913610b2b5760008081fd5b610b3c898683013560408401610a58565b845250918301918301610af9565b509695505050505050565b60008060408385031215610b6857600080fd5b823567ffffffffffffffff80821115610b8057600080fd5b818501915085601f830112610b9457600080fd5b81356020610ba4610ad183610a1b565b82815260059290921b84018101918181019089841115610bc357600080fd5b8286015b84811015610cd557803586811115610bde57600080fd5b87016060818d03601f19011215610bf457600080fd5b610bfc6109c1565b610c07868301610a3f565b8152604082013588811115610c1b57600080fd5b8201603f81018e13610c2c57600080fd5b610c3d8e8883013560408401610a58565b8783015250606082013588811115610c5457600080fd5b8083019250508c603f830112610c6957600080fd5b85820135610c79610ad182610a1b565b81815260059190911b830160400190878101908f831115610c9957600080fd5b6040850194505b82851015610cc057610cb185610a3f565b82529388019390880190610ca0565b60408401525050845250918301918301610bc7565b5096505086013592505080821115610cec57600080fd5b50610cf985828601610ab0565b9150509250929050565b60005b83811015610d1e578181015183820152602001610d06565b83811115610d2d576000848401525b50505050565b60008151808452610d4b816020860160208601610d03565b601f01601f19169290920160200192915050565b60a081526000610d7260a0830188610d33565b602083820381850152610d858289610d33565b915083820360408501528187518084528284019150828160051b850101838a0160005b83811015610dd657601f19878403018552610dc4838351610d33565b94860194925090850190600101610da8565b50508681036060880152610dea818a610d33565b95505050505050610dff608083018415159052565b9695505050505050565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b60008160070b8360070b6000821282677fffffffffffffff03821381151615610e6057610e60610e1f565b82677fffffffffffffff19038212811615610e7d57610e7d610e1f565b50019392505050565b6000600019821415610e9a57610e9a610e1f565b5060010190565b600181811c90821680610eb557607f821691505b60208210811415610ed657634e487b7160e01b600052602260045260246000fd5b50919050565b60008351610eee818460208801610d03565b835190830190610f02818360208801610d03565b01949350505050565b606081526000610f1e6060830186610d33565b602083820381850152610f318287610d33565b91506040848303818601528286518085528385019150838160051b86010184890160005b83811015610fa557878303601f1901855281518051878552610f7988860182610d33565b91890151858303868b0152919050610f918183610d33565b968901969450505090860190600101610f55565b50909b9a505050505050505050505056fe2f646174612f7075626c69635f6d6574726963732f666f6c6c6f776572735f636f756e7468747470733a2f2f7261772e67697468756275736572636f6e74656e742e636f6d2f6c6974656e7472792f76632d6a736f6e736368656d612f6d61696e2f646973742f736368656d61732f362d747769747465722d666f6c6c6f7765722d616d6f756e742f312d312d312e6a736f6e22207d2c207b2022737263223a2022246861735f776562335f6163636f756e74222c20226f70223a20223c3d222c2022647374223a2022687474703a2f2f6c6f63616c686f73743a31393532382f322f75736572732f62792f757365726e616d652f7b22616e64223a205b7b2022737263223a202224746f74616c5f666f6c6c6f77657273222c20226f70223a20223e222c2022647374223a20225468652072616e6765206f662074686520757365722773205477697474657220666f6c6c6f77657220636f756e74a264697066735822122043552c15b5a126b734447b17ad16ec5cb3b87a35973c7763e655f3e13e9a32db64736f6c634300080b0033").unwrap(), + hex::decode("608060405234801561001057600080fd5b5061206f806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063e256184614610030575b600080fd5b61004a60048036038101906100459190611509565b610064565b60405161005b959493929190611730565b60405180910390f35b6060806060806000806040518060600160405280602e815260200161200c602e9139905060006040518060400160405280601781526020017f5477697474657220466f6c6c6f77657220416d6f756e7400000000000000000081525090506040518060a00160405280606f8152602001611f79606f9139600090805190602001906100f0929190610e96565b506000806000905060005b8b518110156102a2576101278c828151811061011a5761011961179f565b5b60200260200101516105b3565b1561028f5760008c82815181106101415761014061179f565b5b60200260200101516020015160405160200161015d91906118c8565b60405160208183030381529060405290506000600167ffffffffffffffff81111561018b5761018a610fcc565b5b6040519080825280602002602001820160405280156101c457816020015b6101b1610f1c565b8152602001906001900390816101a95790505b50905060405180604001604052806040518060400160405280600d81526020017f617574686f72697a6174696f6e0000000000000000000000000000000000000081525081526020018e6000815181106102215761022061179f565b5b6020026020010151815250816000815181106102405761023f61179f565b5b602002602001018190525060008061027184604051806060016040528060248152602001611fe860249139856105c7565b91509150811561028a5780866102879190611931565b95505b505050505b808061029a906119b7565b9150506100fb565b5060008060008360070b121580156102be575060018360070b13155b156102d05760009150600190506103a5565b60018360070b1380156102e7575060648360070b13155b156102f95760019150606490506103a4565b60648360070b13801561031157506103e88360070b13155b1561032457606491506103e890506103a3565b6103e88360070b13801561033d57506127108360070b13155b15610351576103e8915061271090506103a2565b6127108360070b13801561036b5750620186a08360070b13155b15610380576127109150620186a090506103a1565b620186a08360070b13156103a057620186a09150677fffffffffffffff90505b5b5b5b5b5b6001935060006040518060400160405280601081526020017f24746f74616c5f666f6c6c6f7765727300000000000000000000000000000000815250905060006040518060400160405280600267ffffffffffffffff81111561040b5761040a610fcc565b5b60405190808252806020026020018201604052801561044457816020015b610431610f36565b8152602001906001900390816104295790505b50815260200160011515815250905061046d8160008460006104688960070b61063d565b6106cb565b506104888160018460036104838860070b61063d565b6106cb565b506000600167ffffffffffffffff8111156104a6576104a5610fcc565b5b6040519080825280602002602001820160405280156104d957816020015b60608152602001906001900390816104c45790505b5090506104e5826106fd565b816000815181106104f9576104f861179f565b5b602002602001018190525088888260008a81805461051690611a2f565b80601f016020809104026020016040519081016040528092919081815260200182805461054290611a2f565b801561058f5780601f106105645761010080835404028352916020019161058f565b820191906000526020600020905b81548152906001019060200180831161057257829003601f168201915b505050505091509d509d509d509d509d505050505050505050509295509295909350565b60006105c08260006108cd565b9050919050565b60008060008060008787876040516020016105e493929190611b67565b6040516020818303038152906040529050600081519050604051604081836020860160006103e8600019f161061857600080fd5b8051945060208101519350604081016040525083839550955050505050935093915050565b60606000821261065c5760405180602001604052806000815250610693565b6040518060400160405280600181526020017f2d000000000000000000000000000000000000000000000000000000000000008152505b6106a461069f846108fb565b610917565b6040516020016106b5929190611bb3565b6040516020818303038152906040529050919050565b6106d3610f69565b6106e086868686866109ef565b600186602001901515908115158152505085905095945050505050565b606060006040518060400160405280600181526020017f7b000000000000000000000000000000000000000000000000000000000000008152509050600083600001515111156108a25780836020015161078c576040518060400160405280600681526020017f226f72223a5b00000000000000000000000000000000000000000000000000008152506107c3565b6040518060400160405280600781526020017f22616e64223a5b000000000000000000000000000000000000000000000000008152505b6040516020016107d4929190611bb3565b604051602081830303815290604052905060005b83600001515181101561087e576000811115610821578160405160200161080f9190611c23565b60405160208183030381529060405291505b816108498560000151838151811061083c5761083b61179f565b5b6020026020010151610a45565b60405160200161085a929190611bb3565b60405160208183030381529060405291508080610876906119b7565b9150506107e8565b50806040516020016108909190611c91565b60405160208183030381529060405290505b806040516020016108b39190611cff565b604051602081830303815290604052905080915050919050565b60008163ffffffff16836000015163ffffffff1614156108f057600190506108f5565b600090505b92915050565b60008082121561090e5781600003610910565b815b9050919050565b60606000600161092684610a86565b01905060008167ffffffffffffffff81111561094557610944610fcc565b5b6040519080825280601f01601f1916602001820160405280156109775781602001600182028036833780820191505090505b509050600082602001820190505b6001156109e4578080600190039150507f3031323334353637383961626364656600000000000000000000000000000000600a86061a8153600a85816109ce576109cd611d21565b5b04945060008514156109df576109e4565b610985565b819350505050919050565b6040518060600160405280848152602001836005811115610a1357610a12611d50565b5b81526020018281525085600001518581518110610a3357610a3261179f565b5b60200260200101819052505050505050565b60608160000151610a598360200151610bd9565b8360400151604051602001610a7093929190611eaf565b6040516020818303038152906040529050919050565b600080600090507a184f03e93ff9f4daa797ed6e38ed64bf6a1f0100000000000000008310610ae4577a184f03e93ff9f4daa797ed6e38ed64bf6a1f0100000000000000008381610ada57610ad9611d21565b5b0492506040810190505b6d04ee2d6d415b85acef81000000008310610b21576d04ee2d6d415b85acef81000000008381610b1757610b16611d21565b5b0492506020810190505b662386f26fc100008310610b5057662386f26fc100008381610b4657610b45611d21565b5b0492506010810190505b6305f5e1008310610b79576305f5e1008381610b6f57610b6e611d21565b5b0492506008810190505b6127108310610b9e576127108381610b9457610b93611d21565b5b0492506004810190505b60648310610bc15760648381610bb757610bb6611d21565b5b0492506002810190505b600a8310610bd0576001810190505b80915050919050565b606060046005811115610bef57610bee611d50565b5b826005811115610c0257610c01611d50565b5b1415610c45576040518060400160405280600281526020017f3d3d0000000000000000000000000000000000000000000000000000000000008152509050610e91565b60006005811115610c5957610c58611d50565b5b826005811115610c6c57610c6b611d50565b5b1415610caf576040518060400160405280600181526020017f3e000000000000000000000000000000000000000000000000000000000000008152509050610e91565b60016005811115610cc357610cc2611d50565b5b826005811115610cd657610cd5611d50565b5b1415610d19576040518060400160405280600181526020017f3c000000000000000000000000000000000000000000000000000000000000008152509050610e91565b60026005811115610d2d57610d2c611d50565b5b826005811115610d4057610d3f611d50565b5b1415610d83576040518060400160405280600281526020017f3e3d0000000000000000000000000000000000000000000000000000000000008152509050610e91565b60036005811115610d9757610d96611d50565b5b826005811115610daa57610da9611d50565b5b1415610ded576040518060400160405280600281526020017f3c3d0000000000000000000000000000000000000000000000000000000000008152509050610e91565b600580811115610e0057610dff611d50565b5b826005811115610e1357610e12611d50565b5b1415610e56576040518060400160405280600281526020017f213d0000000000000000000000000000000000000000000000000000000000008152509050610e91565b6040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610e8890611f58565b60405180910390fd5b919050565b828054610ea290611a2f565b90600052602060002090601f016020900481019282610ec45760008555610f0b565b82601f10610edd57805160ff1916838001178555610f0b565b82800160010185558215610f0b579182015b82811115610f0a578251825591602001919060010190610eef565b5b509050610f189190610f85565b5090565b604051806040016040528060608152602001606081525090565b60405180606001604052806060815260200160006005811115610f5c57610f5b611d50565b5b8152602001606081525090565b6040518060400160405280606081526020016000151581525090565b5b80821115610f9e576000816000905550600101610f86565b5090565b6000604051905090565b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b61100482610fbb565b810181811067ffffffffffffffff8211171561102357611022610fcc565b5b80604052505050565b6000611036610fa2565b90506110428282610ffb565b919050565b600067ffffffffffffffff82111561106257611061610fcc565b5b602082029050602081019050919050565b600080fd5b600080fd5b600080fd5b600063ffffffff82169050919050565b61109b81611082565b81146110a657600080fd5b50565b6000813590506110b881611092565b92915050565b600080fd5b600067ffffffffffffffff8211156110de576110dd610fcc565b5b6110e782610fbb565b9050602081019050919050565b82818337600083830152505050565b6000611116611111846110c3565b61102c565b905082815260208101848484011115611132576111316110be565b5b61113d8482856110f4565b509392505050565b600082601f83011261115a57611159610fb6565b5b813561116a848260208601611103565b91505092915050565b600067ffffffffffffffff82111561118e5761118d610fcc565b5b602082029050602081019050919050565b60006111b26111ad84611173565b61102c565b905080838252602082019050602084028301858111156111d5576111d4611073565b5b835b818110156111fe57806111ea88826110a9565b8452602084019350506020810190506111d7565b5050509392505050565b600082601f83011261121d5761121c610fb6565b5b813561122d84826020860161119f565b91505092915050565b60006060828403121561124c5761124b611078565b5b611256606061102c565b90506000611266848285016110a9565b600083015250602082013567ffffffffffffffff81111561128a5761128961107d565b5b61129684828501611145565b602083015250604082013567ffffffffffffffff8111156112ba576112b961107d565b5b6112c684828501611208565b60408301525092915050565b60006112e56112e084611047565b61102c565b9050808382526020820190506020840283018581111561130857611307611073565b5b835b8181101561134f57803567ffffffffffffffff81111561132d5761132c610fb6565b5b80860161133a8982611236565b8552602085019450505060208101905061130a565b5050509392505050565b600082601f83011261136e5761136d610fb6565b5b813561137e8482602086016112d2565b91505092915050565b600067ffffffffffffffff8211156113a2576113a1610fcc565b5b602082029050602081019050919050565b600067ffffffffffffffff8211156113ce576113cd610fcc565b5b6113d782610fbb565b9050602081019050919050565b60006113f76113f2846113b3565b61102c565b905082815260208101848484011115611413576114126110be565b5b61141e8482856110f4565b509392505050565b600082601f83011261143b5761143a610fb6565b5b813561144b8482602086016113e4565b91505092915050565b600061146761146284611387565b61102c565b9050808382526020820190506020840283018581111561148a57611489611073565b5b835b818110156114d157803567ffffffffffffffff8111156114af576114ae610fb6565b5b8086016114bc8982611426565b8552602085019450505060208101905061148c565b5050509392505050565b600082601f8301126114f0576114ef610fb6565b5b8135611500848260208601611454565b91505092915050565b600080604083850312156115205761151f610fac565b5b600083013567ffffffffffffffff81111561153e5761153d610fb1565b5b61154a85828601611359565b925050602083013567ffffffffffffffff81111561156b5761156a610fb1565b5b611577858286016114db565b9150509250929050565b600081519050919050565b600082825260208201905092915050565b60005b838110156115bb5780820151818401526020810190506115a0565b838111156115ca576000848401525b50505050565b60006115db82611581565b6115e5818561158c565b93506115f581856020860161159d565b6115fe81610fbb565b840191505092915050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b600082825260208201905092915050565b600061165182611581565b61165b8185611635565b935061166b81856020860161159d565b61167481610fbb565b840191505092915050565b600061168b8383611646565b905092915050565b6000602082019050919050565b60006116ab82611609565b6116b58185611614565b9350836020820285016116c785611625565b8060005b8581101561170357848403895281516116e4858261167f565b94506116ef83611693565b925060208a019950506001810190506116cb565b50829750879550505050505092915050565b60008115159050919050565b61172a81611715565b82525050565b600060a082019050818103600083015261174a81886115d0565b9050818103602083015261175e81876115d0565b9050818103604083015261177281866116a0565b9050818103606083015261178681856115d0565b90506117956080830184611721565b9695505050505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600081905092915050565b7f687474703a2f2f6c6f63616c686f73743a31393532382f322f75736572732f6260008201527f792f757365726e616d652f000000000000000000000000000000000000000000602082015250565b6000611835602b836117ce565b9150611840826117d9565b602b82019050919050565b600061185682611581565b61186081856117ce565b935061187081856020860161159d565b80840191505092915050565b7f3f757365722e6669656c64733d7075626c69635f6d6574726963730000000000600082015250565b60006118b2601b836117ce565b91506118bd8261187c565b601b82019050919050565b60006118d382611828565b91506118df828461184b565b91506118ea826118a5565b915081905092915050565b60008160070b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600061193c826118f5565b9150611947836118f5565b925081677fffffffffffffff0383136000831215161561196a57611969611902565b5b817fffffffffffffffffffffffffffffffffffffffffffffffff80000000000000000383126000831216156119a2576119a1611902565b5b828201905092915050565b6000819050919050565b60006119c2826119ad565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156119f5576119f4611902565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b60006002820490506001821680611a4757607f821691505b60208210811415611a5b57611a5a611a00565b5b50919050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b60006040830160008301518482036000860152611aaa8282611646565b91505060208301518482036020860152611ac48282611646565b9150508091505092915050565b6000611add8383611a8d565b905092915050565b6000602082019050919050565b6000611afd82611a61565b611b078185611a6c565b935083602082028501611b1985611a7d565b8060005b85811015611b555784840389528151611b368582611ad1565b9450611b4183611ae5565b925060208a01995050600181019050611b1d565b50829750879550505050505092915050565b60006060820190508181036000830152611b8181866115d0565b90508181036020830152611b9581856115d0565b90508181036040830152611ba98184611af2565b9050949350505050565b6000611bbf828561184b565b9150611bcb828461184b565b91508190509392505050565b7f2c00000000000000000000000000000000000000000000000000000000000000600082015250565b6000611c0d6001836117ce565b9150611c1882611bd7565b600182019050919050565b6000611c2f828461184b565b9150611c3a82611c00565b915081905092915050565b7f5d00000000000000000000000000000000000000000000000000000000000000600082015250565b6000611c7b6001836117ce565b9150611c8682611c45565b600182019050919050565b6000611c9d828461184b565b9150611ca882611c6e565b915081905092915050565b7f7d00000000000000000000000000000000000000000000000000000000000000600082015250565b6000611ce96001836117ce565b9150611cf482611cb3565b600182019050919050565b6000611d0b828461184b565b9150611d1682611cdc565b915081905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b7f7b22737263223a22000000000000000000000000000000000000000000000000600082015250565b6000611db56008836117ce565b9150611dc082611d7f565b600882019050919050565b7f222c226f70223a22000000000000000000000000000000000000000000000000600082015250565b6000611e016008836117ce565b9150611e0c82611dcb565b600882019050919050565b7f222c22647374223a220000000000000000000000000000000000000000000000600082015250565b6000611e4d6009836117ce565b9150611e5882611e17565b600982019050919050565b7f227d000000000000000000000000000000000000000000000000000000000000600082015250565b6000611e996002836117ce565b9150611ea482611e63565b600282019050919050565b6000611eba82611da8565b9150611ec6828661184b565b9150611ed182611df4565b9150611edd828561184b565b9150611ee882611e40565b9150611ef4828461184b565b9150611eff82611e8c565b9150819050949350505050565b7f556e737570706f72746564206f70657261746f72000000000000000000000000600082015250565b6000611f4260148361158c565b9150611f4d82611f0c565b602082019050919050565b60006020820190508181036000830152611f7181611f35565b905091905056fe68747470733a2f2f7261772e67697468756275736572636f6e74656e742e636f6d2f6c6974656e7472792f76632d6a736f6e736368656d612f6d61696e2f646973742f736368656d61732f362d747769747465722d666f6c6c6f7765722d616d6f756e742f312d302d302e6a736f6e2f646174612f7075626c69635f6d6574726963732f666f6c6c6f776572735f636f756e745468652072616e6765206f662074686520757365722773205477697474657220666f6c6c6f77657220636f756e74a26469706673582212209ff57514694394ff5370932758496dcd286b2307f371c98c7eb1ceeedfc15adb64736f6c634300080b0033").unwrap(), vec!["twitter_api_key".to_string()] ) ); + // token holding amount + // ordi + map.insert( + hash(3), + ( + hex::decode("608060405234801561001057600080fd5b50612810806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063e256184614610030575b600080fd5b61004a60048036038101906100459190611950565b610064565b60405161005b959493929190611b77565b60405180910390f35b6060806060806000806040518060600160405280603081526020016127ab60309139905060006040518060400160405280601481526020017f546f6b656e20486f6c64696e6720416d6f756e7400000000000000000000000081525090506040518060a00160405280606d815260200161273e606d9139600090805190602001906100f09291906112dd565b5060006100fd8a8a6101e1565b9050600080600061010d846102b9565b925092509250600061011f838361041d565b90506000808511806101315750600086115b905087878360008481805461014590611c15565b80601f016020809104026020016040519081016040528092919081815260200182805461017190611c15565b80156101be5780601f10610193576101008083540402835291602001916101be565b820191906000526020600020905b8154815290600101906020018083116101a157829003601f168201915b505050505091509c509c509c509c509c5050505050505050509295509295909350565b6000806000905060008451905060005b818110156102ad57600086828151811061020e5761020d611c47565b5b602002602001015190506000816040015151905060005b818163ffffffff16101561029757600083604001518263ffffffff168151811061025257610251611c47565b5b60200260200101519050610265816105e9565b156102835761027584828b610602565b876102809190611caf565b96505b50808061028f90611d05565b915050610225565b50505080806102a590611d32565b9150506101f1565b50819250505092915050565b6000806000806102c76107ba565b90506000600182516102d99190611d7b565b90506000806000600190505b84518163ffffffff161015610367576102fc610922565b600a6103089190611eef565b858263ffffffff168151811061032157610320611c47565b5b60200260200101516103339190611f3a565b891015610354576001816103479190611f94565b63ffffffff169350610367565b808061035f90611d05565b9150506102e5565b50600184516103769190611d7b565b8314156103c2578383815181106103905761038f611c47565b5b602002602001015191507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9050610409565b8383815181106103d5576103d4611c47565b5b60200260200101519150836001846103ed9190611caf565b815181106103fe576103fd611c47565b5b602002602001015190505b828282965096509650505050509193909250565b606060006040518060400160405280600f81526020017f24686f6c64696e675f616d6f756e74000000000000000000000000000000000081525090506000604051806040016040528060008613610475576002610478565b60035b60ff1667ffffffffffffffff81111561049457610493611413565b5b6040519080825280602002602001820160405280156104cd57816020015b6104ba611363565b8152602001906001900390816104b25790505b5081526020016001151581525090506105278160006040518060400160405280600681526020017f24746f6b656e0000000000000000000000000000000000000000000000000000815250600461052261092b565b610968565b5061053f81600184600261053a8a61099a565b610968565b5060008413156105625761056081600284600161055b89610a72565b610968565b505b6000600167ffffffffffffffff81111561057f5761057e611413565b5b6040519080825280602002602001820160405280156105b257816020015b606081526020019060019003908161059d5790505b5090506105be82610b00565b816000815181106105d2576105d1611c47565b5b602002602001018190525080935050505092915050565b6000600963ffffffff168263ffffffff16149050919050565b6000806000610615858760200151610cd0565b9150915081156107ac57600061062961092b565b8260405160200161063b92919061210e565b60405160208183030381529060405290506000600167ffffffffffffffff81111561066957610668611413565b5b6040519080825280602002602001820160405280156106a257816020015b61068f611396565b8152602001906001900390816106875790505b50905060405180604001604052806040518060400160405280600781526020017f6170692d6b6579000000000000000000000000000000000000000000000000008152508152602001876000815181106106ff576106fe611c47565b5b60200260200101518152508160008151811061071e5761071d611c47565b5b602002602001018190525060008061076c846040518060400160405280601e81526020017f2f646174612f6c6973742f302f617661696c61626c655f62616c616e6365000081525085610d39565b9150915081156107a75760008061078a83610785610922565b610db2565b9150915081156107a45780985050505050505050506107b3565b50505b505050505b6000925050505b9392505050565b60606000600867ffffffffffffffff8111156107d9576107d8611413565b5b6040519080825280602002602001820160405280156108075781602001602082028036833780820191505090505b5090506000816000815181106108205761081f611c47565b5b60200260200101818152505060018160018151811061084257610841611c47565b5b60200260200101818152505060058160028151811061086457610863611c47565b5b60200260200101818152505060148160038151811061088657610885611c47565b5b6020026020010181815250506032816004815181106108a8576108a7611c47565b5b6020026020010181815250506064816005815181106108ca576108c9611c47565b5b60200260200101818152505060c8816006815181106108ec576108eb611c47565b5b6020026020010181815250506101f48160078151811061090f5761090e611c47565b5b6020026020010181815250508091505090565b60006012905090565b60606040518060400160405280600481526020017f6f72646900000000000000000000000000000000000000000000000000000000815250905090565b6109706113b0565b61097d8686868686610e1a565b600186602001901515908115158152505085905095945050505050565b6060600060016109a984610e70565b01905060008167ffffffffffffffff8111156109c8576109c7611413565b5b6040519080825280601f01601f1916602001820160405280156109fa5781602001600182028036833780820191505090505b509050600082602001820190505b600115610a67578080600190039150507f3031323334353637383961626364656600000000000000000000000000000000600a86061a8153600a8581610a5157610a50612153565b5b0494506000851415610a6257610a67565b610a08565b819350505050919050565b606060008212610a915760405180602001604052806000815250610ac8565b6040518060400160405280600181526020017f2d000000000000000000000000000000000000000000000000000000000000008152505b610ad9610ad484610fc3565b61099a565b604051602001610aea929190612182565b6040516020818303038152906040529050919050565b606060006040518060400160405280600181526020017f7b00000000000000000000000000000000000000000000000000000000000000815250905060008360000151511115610ca557808360200151610b8f576040518060400160405280600681526020017f226f72223a5b0000000000000000000000000000000000000000000000000000815250610bc6565b6040518060400160405280600781526020017f22616e64223a5b000000000000000000000000000000000000000000000000008152505b604051602001610bd7929190612182565b604051602081830303815290604052905060005b836000015151811015610c81576000811115610c245781604051602001610c1291906121f2565b60405160208183030381529060405291505b81610c4c85600001518381518110610c3f57610c3e611c47565b5b6020026020010151610fdf565b604051602001610c5d929190612182565b60405160208183030381529060405291508080610c7990611d32565b915050610beb565b5080604051602001610c939190612260565b60405160208183030381529060405290505b80604051602001610cb691906122ce565b604051602081830303815290604052905080915050919050565b6000606060008484604051602001610ce9929190612354565b6040516020818303038152906040529050600081519050604051611000818360208601600061041c600019f1610d1e57600080fd5b80945060408101935061100081016040525050509250929050565b60006060600060606000878787604051602001610d589392919061248a565b604051602081830303815290604052905060008151905060405161100081836020860160006103ea600019f1610d8d57600080fd5b8051945060408101935061100081016040525083839550955050505050935093915050565b60008060008484604051602001610dca9291906124e5565b60405160208183030381529060405290506000815190506040516082818360208601600061041e600019f1610dfe57600080fd5b8051945060208101519350608281016040525050509250929050565b6040518060600160405280848152602001836005811115610e3e57610e3d612515565b5b81526020018281525085600001518581518110610e5e57610e5d611c47565b5b60200260200101819052505050505050565b600080600090507a184f03e93ff9f4daa797ed6e38ed64bf6a1f0100000000000000008310610ece577a184f03e93ff9f4daa797ed6e38ed64bf6a1f0100000000000000008381610ec457610ec3612153565b5b0492506040810190505b6d04ee2d6d415b85acef81000000008310610f0b576d04ee2d6d415b85acef81000000008381610f0157610f00612153565b5b0492506020810190505b662386f26fc100008310610f3a57662386f26fc100008381610f3057610f2f612153565b5b0492506010810190505b6305f5e1008310610f63576305f5e1008381610f5957610f58612153565b5b0492506008810190505b6127108310610f88576127108381610f7e57610f7d612153565b5b0492506004810190505b60648310610fab5760648381610fa157610fa0612153565b5b0492506002810190505b600a8310610fba576001810190505b80915050919050565b600080821215610fd65781600003610fd8565b815b9050919050565b60608160000151610ff38360200151611020565b836040015160405160200161100a93929190612674565b6040516020818303038152906040529050919050565b60606004600581111561103657611035612515565b5b82600581111561104957611048612515565b5b141561108c576040518060400160405280600281526020017f3d3d00000000000000000000000000000000000000000000000000000000000081525090506112d8565b600060058111156110a05761109f612515565b5b8260058111156110b3576110b2612515565b5b14156110f6576040518060400160405280600181526020017f3e0000000000000000000000000000000000000000000000000000000000000081525090506112d8565b6001600581111561110a57611109612515565b5b82600581111561111d5761111c612515565b5b1415611160576040518060400160405280600181526020017f3c0000000000000000000000000000000000000000000000000000000000000081525090506112d8565b6002600581111561117457611173612515565b5b82600581111561118757611186612515565b5b14156111ca576040518060400160405280600281526020017f3e3d00000000000000000000000000000000000000000000000000000000000081525090506112d8565b600360058111156111de576111dd612515565b5b8260058111156111f1576111f0612515565b5b1415611234576040518060400160405280600281526020017f3c3d00000000000000000000000000000000000000000000000000000000000081525090506112d8565b60058081111561124757611246612515565b5b82600581111561125a57611259612515565b5b141561129d576040518060400160405280600281526020017f213d00000000000000000000000000000000000000000000000000000000000081525090506112d8565b6040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016112cf9061271d565b60405180910390fd5b919050565b8280546112e990611c15565b90600052602060002090601f01602090048101928261130b5760008555611352565b82601f1061132457805160ff1916838001178555611352565b82800160010185558215611352579182015b82811115611351578251825591602001919060010190611336565b5b50905061135f91906113cc565b5090565b6040518060600160405280606081526020016000600581111561138957611388612515565b5b8152602001606081525090565b604051806040016040528060608152602001606081525090565b6040518060400160405280606081526020016000151581525090565b5b808211156113e55760008160009055506001016113cd565b5090565b6000604051905090565b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b61144b82611402565b810181811067ffffffffffffffff8211171561146a57611469611413565b5b80604052505050565b600061147d6113e9565b90506114898282611442565b919050565b600067ffffffffffffffff8211156114a9576114a8611413565b5b602082029050602081019050919050565b600080fd5b600080fd5b600080fd5b600063ffffffff82169050919050565b6114e2816114c9565b81146114ed57600080fd5b50565b6000813590506114ff816114d9565b92915050565b600080fd5b600067ffffffffffffffff82111561152557611524611413565b5b61152e82611402565b9050602081019050919050565b82818337600083830152505050565b600061155d6115588461150a565b611473565b90508281526020810184848401111561157957611578611505565b5b61158484828561153b565b509392505050565b600082601f8301126115a1576115a06113fd565b5b81356115b184826020860161154a565b91505092915050565b600067ffffffffffffffff8211156115d5576115d4611413565b5b602082029050602081019050919050565b60006115f96115f4846115ba565b611473565b9050808382526020820190506020840283018581111561161c5761161b6114ba565b5b835b81811015611645578061163188826114f0565b84526020840193505060208101905061161e565b5050509392505050565b600082601f830112611664576116636113fd565b5b81356116748482602086016115e6565b91505092915050565b600060608284031215611693576116926114bf565b5b61169d6060611473565b905060006116ad848285016114f0565b600083015250602082013567ffffffffffffffff8111156116d1576116d06114c4565b5b6116dd8482850161158c565b602083015250604082013567ffffffffffffffff811115611701576117006114c4565b5b61170d8482850161164f565b60408301525092915050565b600061172c6117278461148e565b611473565b9050808382526020820190506020840283018581111561174f5761174e6114ba565b5b835b8181101561179657803567ffffffffffffffff811115611774576117736113fd565b5b808601611781898261167d565b85526020850194505050602081019050611751565b5050509392505050565b600082601f8301126117b5576117b46113fd565b5b81356117c5848260208601611719565b91505092915050565b600067ffffffffffffffff8211156117e9576117e8611413565b5b602082029050602081019050919050565b600067ffffffffffffffff82111561181557611814611413565b5b61181e82611402565b9050602081019050919050565b600061183e611839846117fa565b611473565b90508281526020810184848401111561185a57611859611505565b5b61186584828561153b565b509392505050565b600082601f830112611882576118816113fd565b5b813561189284826020860161182b565b91505092915050565b60006118ae6118a9846117ce565b611473565b905080838252602082019050602084028301858111156118d1576118d06114ba565b5b835b8181101561191857803567ffffffffffffffff8111156118f6576118f56113fd565b5b808601611903898261186d565b855260208501945050506020810190506118d3565b5050509392505050565b600082601f830112611937576119366113fd565b5b813561194784826020860161189b565b91505092915050565b60008060408385031215611967576119666113f3565b5b600083013567ffffffffffffffff811115611985576119846113f8565b5b611991858286016117a0565b925050602083013567ffffffffffffffff8111156119b2576119b16113f8565b5b6119be85828601611922565b9150509250929050565b600081519050919050565b600082825260208201905092915050565b60005b83811015611a025780820151818401526020810190506119e7565b83811115611a11576000848401525b50505050565b6000611a22826119c8565b611a2c81856119d3565b9350611a3c8185602086016119e4565b611a4581611402565b840191505092915050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b600082825260208201905092915050565b6000611a98826119c8565b611aa28185611a7c565b9350611ab28185602086016119e4565b611abb81611402565b840191505092915050565b6000611ad28383611a8d565b905092915050565b6000602082019050919050565b6000611af282611a50565b611afc8185611a5b565b935083602082028501611b0e85611a6c565b8060005b85811015611b4a5784840389528151611b2b8582611ac6565b9450611b3683611ada565b925060208a01995050600181019050611b12565b50829750879550505050505092915050565b60008115159050919050565b611b7181611b5c565b82525050565b600060a0820190508181036000830152611b918188611a17565b90508181036020830152611ba58187611a17565b90508181036040830152611bb98186611ae7565b90508181036060830152611bcd8185611a17565b9050611bdc6080830184611b68565b9695505050505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b60006002820490506001821680611c2d57607f821691505b60208210811415611c4157611c40611be6565b5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6000819050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000611cba82611c76565b9150611cc583611c76565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115611cfa57611cf9611c80565b5b828201905092915050565b6000611d10826114c9565b915063ffffffff821415611d2757611d26611c80565b5b600182019050919050565b6000611d3d82611c76565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415611d7057611d6f611c80565b5b600182019050919050565b6000611d8682611c76565b9150611d9183611c76565b925082821015611da457611da3611c80565b5b828203905092915050565b60008160011c9050919050565b6000808291508390505b6001851115611e0657808604811115611de257611de1611c80565b5b6001851615611df15780820291505b8081029050611dff85611daf565b9450611dc6565b94509492505050565b600082611e1f5760019050611edb565b81611e2d5760009050611edb565b8160018114611e435760028114611e4d57611e7c565b6001915050611edb565b60ff841115611e5f57611e5e611c80565b5b8360020a915084821115611e7657611e75611c80565b5b50611edb565b5060208310610133831016604e8410600b8410161715611eb15782820a905083811115611eac57611eab611c80565b5b611edb565b611ebe8484846001611dbc565b92509050818404811115611ed557611ed4611c80565b5b81810290505b9392505050565b600060ff82169050919050565b6000611efa82611c76565b9150611f0583611ee2565b9250611f327fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8484611e0f565b905092915050565b6000611f4582611c76565b9150611f5083611c76565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0483118215151615611f8957611f88611c80565b5b828202905092915050565b6000611f9f826114c9565b9150611faa836114c9565b925082821015611fbd57611fbc611c80565b5b828203905092915050565b600081905092915050565b7f687474703a2f2f6c6f63616c686f73743a31393532392f6170692f312f62726360008201527f32302f62616c616e636500000000000000000000000000000000000000000000602082015250565b600061202f602a83611fc8565b915061203a82611fd3565b602a82019050919050565b7f3f7469636b3d0000000000000000000000000000000000000000000000000000600082015250565b600061207b600683611fc8565b915061208682612045565b600682019050919050565b600061209c826119c8565b6120a68185611fc8565b93506120b68185602086016119e4565b80840191505092915050565b7f26616464726573733d0000000000000000000000000000000000000000000000600082015250565b60006120f8600983611fc8565b9150612103826120c2565b600982019050919050565b600061211982612022565b91506121248261206e565b91506121308285612091565b915061213b826120eb565b91506121478284612091565b91508190509392505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b600061218e8285612091565b915061219a8284612091565b91508190509392505050565b7f2c00000000000000000000000000000000000000000000000000000000000000600082015250565b60006121dc600183611fc8565b91506121e7826121a6565b600182019050919050565b60006121fe8284612091565b9150612209826121cf565b915081905092915050565b7f5d00000000000000000000000000000000000000000000000000000000000000600082015250565b600061224a600183611fc8565b915061225582612214565b600182019050919050565b600061226c8284612091565b91506122778261223d565b915081905092915050565b7f7d00000000000000000000000000000000000000000000000000000000000000600082015250565b60006122b8600183611fc8565b91506122c382612282565b600182019050919050565b60006122da8284612091565b91506122e5826122ab565b915081905092915050565b6122f9816114c9565b82525050565b600081519050919050565b600082825260208201905092915050565b6000612326826122ff565b612330818561230a565b93506123408185602086016119e4565b61234981611402565b840191505092915050565b600060408201905061236960008301856122f0565b818103602083015261237b818461231b565b90509392505050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b600060408301600083015184820360008601526123cd8282611a8d565b915050602083015184820360208601526123e78282611a8d565b9150508091505092915050565b600061240083836123b0565b905092915050565b6000602082019050919050565b600061242082612384565b61242a818561238f565b93508360208202850161243c856123a0565b8060005b85811015612478578484038952815161245985826123f4565b945061246483612408565b925060208a01995050600181019050612440565b50829750879550505050505092915050565b600060608201905081810360008301526124a48186611a17565b905081810360208301526124b88185611a17565b905081810360408301526124cc8184612415565b9050949350505050565b6124df81611ee2565b82525050565b600060408201905081810360008301526124ff8185611a17565b905061250e60208301846124d6565b9392505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b7f7b22737263223a22000000000000000000000000000000000000000000000000600082015250565b600061257a600883611fc8565b915061258582612544565b600882019050919050565b7f222c226f70223a22000000000000000000000000000000000000000000000000600082015250565b60006125c6600883611fc8565b91506125d182612590565b600882019050919050565b7f222c22647374223a220000000000000000000000000000000000000000000000600082015250565b6000612612600983611fc8565b915061261d826125dc565b600982019050919050565b7f227d000000000000000000000000000000000000000000000000000000000000600082015250565b600061265e600283611fc8565b915061266982612628565b600282019050919050565b600061267f8261256d565b915061268b8286612091565b9150612696826125b9565b91506126a28285612091565b91506126ad82612605565b91506126b98284612091565b91506126c482612651565b9150819050949350505050565b7f556e737570706f72746564206f70657261746f72000000000000000000000000600082015250565b60006127076014836119d3565b9150612712826126d1565b602082019050919050565b60006020820190508181036000830152612736816126fa565b905091905056fe68747470733a2f2f7261772e67697468756275736572636f6e74656e742e636f6d2f6c6974656e7472792f76632d6a736f6e736368656d612f6d61696e2f646973742f736368656d61732f32352d746f6b656e2d686f6c64696e672d616d6f756e742f312d312d302e6a736f6e54686520616d6f756e74206f66206120706172746963756c617220746f6b656e20796f752061726520686f6c64696e67a2646970667358221220916c6f3f8237735f4bd3e8457550bc6079a42c4c3958743e9905dc5401961c4c64736f6c634300080b0033").unwrap(), + vec!["geniidata_api_key".to_string()] + ) + ); InMemorySmartContractRepo { map: map.into() } } } diff --git a/tee-worker/litentry/core/evm-dynamic-assertions/Cargo.toml b/tee-worker/litentry/core/evm-dynamic-assertions/Cargo.toml index a3cb6f2ef1..cca4082a6b 100644 --- a/tee-worker/litentry/core/evm-dynamic-assertions/Cargo.toml +++ b/tee-worker/litentry/core/evm-dynamic-assertions/Cargo.toml @@ -8,8 +8,12 @@ edition = "2021" [dependencies] # std dependecies +base58 = { version = "0.2", default-features = false } +blake2-rfc = { version = "0.2.18", default-features = false } codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } http = { version = "0.2", optional = true } +rust_decimal = { version = "1.35.0", default-features = false } +ss58-registry = { version = "1.40", default-features = false } thiserror = { version = "1.0.26", optional = true } # sgx dependencies @@ -29,12 +33,15 @@ serde_json = { version = "1.0", default-features = false, features = ["alloc"] } itc-rest-client = { path = "../../../core/rest-client", default-features = false } itp-settings = { path = "../../../core-primitives/settings" } itp-sgx-io = { path = "../../../core-primitives/sgx/io", default-features = false } +itp-utils = { path = "../../../core-primitives/utils", default-features = false } lc-dynamic-assertion = { path = "../dynamic-assertion", default-features = false } - +litentry-primitives = { path = "../../primitives", default-features = false } [dev-dependencies] http_req = { features = ["rust-tls"], branch = "master", git = "https://github.com/integritee-network/http_req" } +lc-mock-server = { path = "../mock-server" } litentry-primitives = { path = "../../primitives" } +litentry-hex-utils = { path = "../../../../primitives/hex" } [features] default = ["std"] diff --git a/tee-worker/litentry/core/evm-dynamic-assertions/src/lib.rs b/tee-worker/litentry/core/evm-dynamic-assertions/src/lib.rs index d643020ce4..cd9975f81a 100644 --- a/tee-worker/litentry/core/evm-dynamic-assertions/src/lib.rs +++ b/tee-worker/litentry/core/evm-dynamic-assertions/src/lib.rs @@ -113,11 +113,15 @@ impl> let call_result = execute_smart_contract(smart_contract_byte_code, input); - let (description, assertion_type, assertions, schema_url, meet) = - decode_result(&call_result.1) - .map_err(|_| "Could not decode evm assertion execution result")?; - - Ok(AssertionResult { description, assertion_type, assertions, schema_url, meet }) + if call_result.0.is_succeed() { + let (description, assertion_type, assertions, schema_url, meet) = + decode_result(&call_result.1) + .map_err(|_| "Could not decode evm assertion execution result")?; + + Ok(AssertionResult { description, assertion_type, assertions, schema_url, meet }) + } else { + Err(std::format!("Fail to execution evm dynamic assertion: {:?}", call_result.0)) + } } } @@ -176,29 +180,7 @@ pub fn secret_to_token(secret: &String) -> Token { } pub fn network_to_token(network: &Web3Network) -> Token { - Token::Uint( - match network { - Web3Network::Polkadot => 0, - Web3Network::Kusama => 1, - Web3Network::Litentry => 2, - Web3Network::Litmus => 3, - Web3Network::LitentryRococo => 4, - Web3Network::Khala => 5, - Web3Network::SubstrateTestnet => 6, - Web3Network::Ethereum => 7, - Web3Network::Bsc => 8, - Web3Network::BitcoinP2tr => 9, - Web3Network::BitcoinP2pkh => 10, - Web3Network::BitcoinP2sh => 11, - Web3Network::BitcoinP2wpkh => 12, - Web3Network::BitcoinP2wsh => 13, - Web3Network::Polygon => 14, - Web3Network::Arbitrum => 15, - Web3Network::Solana => 16, - Web3Network::Combo => 17, - } - .into(), - ) + Token::Uint(network.get_code().into()) } #[allow(clippy::result_unit_err)] @@ -240,6 +222,20 @@ fn hash(a: u64) -> H160 { H160::from_low_u64_be(a) } +pub fn success_precompile_output(token: ethabi::Token) -> evm::executor::stack::PrecompileOutput { + evm::executor::stack::PrecompileOutput { + exit_status: evm::ExitSucceed::Returned, + output: ethabi::encode(&[ethabi::Token::Bool(true), token]), + } +} + +pub fn failure_precompile_output(token: ethabi::Token) -> evm::executor::stack::PrecompileOutput { + evm::executor::stack::PrecompileOutput { + exit_status: evm::ExitSucceed::Returned, + output: ethabi::encode(&[ethabi::Token::Bool(false), token]), + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/hex_to_number.rs b/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/hex_to_number.rs new file mode 100644 index 0000000000..2977d3583e --- /dev/null +++ b/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/hex_to_number.rs @@ -0,0 +1,162 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . + +use crate::{failure_precompile_output, precompiles::PrecompileResult, success_precompile_output}; +use ethabi::ethereum_types::U256; +use std::vec::Vec; + +pub fn hex_to_number(input: Vec) -> PrecompileResult { + let decoded = match ethabi::decode(&[ethabi::ParamType::String], &input) { + Ok(d) => d, + Err(e) => { + log::debug!("Could not decode string {:?}, reason: {:?}", input, e); + return Ok(failure_precompile_output(ethabi::Token::Uint(Default::default()))) + }, + }; + + let string_value = decoded.get(0).and_then(|v| v.clone().into_string()); + + let value = match string_value { + Some(s) => { + let begin = if s.starts_with("0x") { 2 } else { 0 }; + match U256::from_str_radix(&s[begin..], 16) { + Ok(n) => n, + Err(e) => { + log::debug!("Cannot parse hex {:?} to U256, reason: {:?}", s, e); + return Ok(failure_precompile_output(ethabi::Token::Uint(Default::default()))) + }, + } + }, + None => { + log::debug!("Could not decode input {:?}, reason: string value is invalid", input); + return Ok(failure_precompile_output(ethabi::Token::Uint(Default::default()))) + }, + }; + + Ok(success_precompile_output(ethabi::Token::Uint(value))) +} + +#[cfg(test)] +pub mod test { + use crate::{ + failure_precompile_output, precompiles::hex_to_number::hex_to_number, + success_precompile_output, + }; + use ethabi::{encode, Token}; + + #[test] + pub fn test_hex_to_number() { + // given + let encoded = encode(&[Token::String("0x16345785d8a0001".into())]); + + // when + let result = hex_to_number(encoded).unwrap(); + + // then + assert_eq!(success_precompile_output(Token::Uint(100000000000000001_u128.into())), result); + + // given + let encoded = encode(&[Token::String("16345785d8a0001".into())]); + + // when + let result = hex_to_number(encoded).unwrap(); + + // then + assert_eq!(success_precompile_output(Token::Uint(100000000000000001_u128.into())), result); + } + + #[test] + pub fn test_hex_to_number_fail() { + // given + let encoded = encode(&[Token::String("16345785d8a0001XYZ".into())]); + + // when + let result = hex_to_number(encoded).unwrap(); + + // then + assert_eq!(failure_precompile_output(Token::Uint(Default::default())), result) + } +} + +#[cfg(test)] +pub mod integration_test { + use crate::{execute_smart_contract, prepare_function_call_input}; + use ethabi::{decode, encode, ethereum_types::U256, ParamType, Token}; + + // tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/HexToNumber.sol + const FUNCTION_HASH: &str = "24315f7d"; // callHexToNumber(string) + const BYTE_CODE: &str = "608060405234801561001057600080fd5b506103ba806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c806324315f7d14610030575b600080fd5b61004a60048036038101906100459190610234565b610061565b6040516100589291906102b1565b60405180910390f35b60008061006d83610076565b91509150915091565b60008060008360405160200161008c9190610362565b60405160208183030381529060405290506000815190506040516082818360208601600061041d600019f16100c057600080fd5b805194506020810151935060828101604052505050915091565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b610141826100f8565b810181811067ffffffffffffffff821117156101605761015f610109565b5b80604052505050565b60006101736100da565b905061017f8282610138565b919050565b600067ffffffffffffffff82111561019f5761019e610109565b5b6101a8826100f8565b9050602081019050919050565b82818337600083830152505050565b60006101d76101d284610184565b610169565b9050828152602081018484840111156101f3576101f26100f3565b5b6101fe8482856101b5565b509392505050565b600082601f83011261021b5761021a6100ee565b5b813561022b8482602086016101c4565b91505092915050565b60006020828403121561024a576102496100e4565b5b600082013567ffffffffffffffff811115610268576102676100e9565b5b61027484828501610206565b91505092915050565b60008115159050919050565b6102928161027d565b82525050565b6000819050919050565b6102ab81610298565b82525050565b60006040820190506102c66000830185610289565b6102d360208301846102a2565b9392505050565b600081519050919050565b600082825260208201905092915050565b60005b838110156103145780820151818401526020810190506102f9565b83811115610323576000848401525b50505050565b6000610334826102da565b61033e81856102e5565b935061034e8185602086016102f6565b610357816100f8565b840191505092915050565b6000602082019050818103600083015261037c8184610329565b90509291505056fea2646970667358221220784bc28feed715287f74788b5cdceef4065dd0050b48dea8843dbc838459bed064736f6c634300080b0033"; + + #[test] + pub fn test_hex_to_number() { + let byte_code = hex::decode(BYTE_CODE).unwrap(); + let return_types = vec![ParamType::Bool, ParamType::Uint(256)]; + + // given + let input_data = prepare_function_call_input( + FUNCTION_HASH, + encode(&[Token::String("0x16345785d8a0001".to_string())]), + ) + .unwrap(); + + // when + let (_, return_data) = execute_smart_contract(byte_code.clone(), input_data); + + // then + let decoded = decode(&return_types, &return_data).unwrap(); + assert_eq!(true, decoded[0].clone().into_bool().unwrap()); + let expected_result: U256 = 100000000000000001_u128.into(); + assert_eq!(expected_result, decoded[1].clone().into_uint().unwrap()); + + // given + let input_data = prepare_function_call_input( + FUNCTION_HASH, + encode(&[Token::String("16345785d8a0001".to_string())]), + ) + .unwrap(); + + // when + let (_, return_data) = execute_smart_contract(byte_code.clone(), input_data); + + // then + let decoded = decode(&return_types, &return_data).unwrap(); + assert_eq!(true, decoded[0].clone().into_bool().unwrap()); + let expected_result: U256 = 100000000000000001_u128.into(); + assert_eq!(expected_result, decoded[1].clone().into_uint().unwrap()); + } + + #[test] + pub fn test_hex_to_number_fail() { + let byte_code = hex::decode(BYTE_CODE).unwrap(); + let return_types = vec![ParamType::Bool, ParamType::Uint(256)]; + + // given + let input_data = prepare_function_call_input( + FUNCTION_HASH, + encode(&[Token::String("123XYZ".to_string())]), + ) + .unwrap(); + + // when + let (_, return_data) = execute_smart_contract(byte_code.clone(), input_data); + + // then + let decoded = decode(&return_types, &return_data).unwrap(); + assert_eq!(false, decoded[0].clone().into_bool().unwrap()); + let expected_result: U256 = U256::zero(); + assert_eq!(expected_result, decoded[1].clone().into_uint().unwrap()); + } +} diff --git a/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/http_get.rs b/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/http_get.rs index 978af45cc1..bb7c5993e5 100644 --- a/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/http_get.rs +++ b/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/http_get.rs @@ -23,12 +23,15 @@ http_get_precompile_fn!(http_get_string, String, as_str); #[cfg(test)] pub mod test { - use crate::precompiles::{ - http_get::{http_get_bool, http_get_i64, http_get_string}, - mocks::MockedHttpClient, + use crate::{ + failure_precompile_output, + precompiles::{ + http_get::{http_get_bool, http_get_i64, http_get_string}, + mocks::MockedHttpClient, + }, + success_precompile_output, }; - use ethabi::ethereum_types::U256; - use evm::ExitSucceed; + use ethabi::{encode, ethereum_types::U256, Token}; #[test] pub fn test_get_bool() { @@ -40,11 +43,7 @@ pub mod test { let result = http_get_bool(data, client).unwrap(); // then - assert!(matches!(result.exit_status, ExitSucceed::Returned)); - assert_eq!( - ethabi::encode(&[ethabi::Token::Bool(true), ethabi::Token::Bool(true)]), - result.output - ) + assert_eq!(success_precompile_output(Token::Bool(true)), result) } #[test] @@ -57,14 +56,7 @@ pub mod test { let result = http_get_i64(data, client).unwrap(); // then - assert!(matches!(result.exit_status, ExitSucceed::Returned)); - assert_eq!( - ethabi::encode(&[ - ethabi::Token::Bool(true), - ethabi::Token::Uint(U256::try_from(10).unwrap()) - ]), - result.output - ) + assert_eq!(success_precompile_output(Token::Uint(U256::try_from(10).unwrap())), result) } #[test] @@ -77,14 +69,7 @@ pub mod test { let result = http_get_string(data, client).unwrap(); // then - assert!(matches!(result.exit_status, ExitSucceed::Returned)); - assert_eq!( - ethabi::encode(&[ - ethabi::Token::Bool(true), - ethabi::Token::String("string".to_string()) - ]), - result.output - ) + assert_eq!(success_precompile_output(Token::String("string".to_string())), result) } #[test] @@ -97,11 +82,7 @@ pub mod test { let result = http_get_string(data, client).unwrap(); // then - assert!(matches!(result.exit_status, ExitSucceed::Returned)); - assert_eq!( - ethabi::encode(&[ethabi::Token::Bool(false), ethabi::Token::String("".to_string())]), - result.output - ) + assert_eq!(failure_precompile_output(Token::String(Default::default())), result) } #[test] @@ -114,11 +95,7 @@ pub mod test { let result = http_get_string(data, client).unwrap(); // then - assert!(matches!(result.exit_status, ExitSucceed::Returned)); - assert_eq!( - ethabi::encode(&[ethabi::Token::Bool(false), ethabi::Token::String("".to_string())]), - result.output - ) + assert_eq!(failure_precompile_output(Token::String(Default::default())), result) } #[test] @@ -131,11 +108,7 @@ pub mod test { let result = http_get_string(data, client).unwrap(); // then - assert!(matches!(result.exit_status, ExitSucceed::Returned)); - assert_eq!( - ethabi::encode(&[ethabi::Token::Bool(false), ethabi::Token::String("".to_string())]), - result.output - ) + assert_eq!(failure_precompile_output(Token::String(Default::default())), result) } #[test] @@ -148,11 +121,7 @@ pub mod test { let result = http_get_bool(data, client).unwrap(); // then - assert!(matches!(result.exit_status, ExitSucceed::Returned)); - assert_eq!( - ethabi::encode(&[ethabi::Token::Bool(false), ethabi::Token::Bool(false)]), - result.output - ) + assert_eq!(failure_precompile_output(Token::Bool(Default::default())), result) } #[test] @@ -165,11 +134,7 @@ pub mod test { let result = http_get_bool(data.to_vec(), client).unwrap(); // then - assert!(matches!(result.exit_status, ExitSucceed::Returned)); - assert_eq!( - ethabi::encode(&[ethabi::Token::Bool(false), ethabi::Token::Bool(false)]), - result.output - ) + assert_eq!(failure_precompile_output(Token::Bool(Default::default())), result) } #[test] @@ -182,18 +147,281 @@ pub mod test { let result = http_get_string(data, client).unwrap(); // then - assert!(matches!(result.exit_status, ExitSucceed::Returned)); - assert_eq!( - ethabi::encode(&[ethabi::Token::Bool(false), ethabi::Token::String("".to_string())]), - result.output - ) + assert_eq!(failure_precompile_output(Token::String(Default::default())), result) } fn prepare_input_data(url: &str, pointer: &str) -> Vec { - ethabi::encode(&[ - ethabi::Token::String(url.to_string()), - ethabi::Token::String(pointer.to_string()), - ethabi::Token::Array(vec![]), + encode(&[ + Token::String(url.to_string()), + Token::String(pointer.to_string()), + Token::Array(vec![]), ]) } } + +#[cfg(test)] +pub mod integration_test { + use crate::{execute_smart_contract, prepare_function_call_input}; + use ethabi::{decode, encode, ethereum_types::U256, ParamType, Token}; + use lc_mock_server::run; + + // tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/GetI64.sol + const GET_I64_FUNCTION_HASH_0: &str = "f5e19bc0"; // callGetI64(string,string) + const GET_I64_FUNCTION_HASH_1: &str = "ed043e0f"; // callGetI64TwiceAndReturnSecondResult(string,string,string,string) + const GET_I64_BYTE_CODE: &str = "608060405234801561001057600080fd5b50610783806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063ed043e0f1461003b578063f5e19bc01461006c575b600080fd5b6100556004803603810190610050919061037a565b61009d565b604051610063929190610488565b60405180910390f35b610086600480360381019061008191906104b1565b61011e565b604051610094929190610488565b60405180910390f35b60008060008067ffffffffffffffff8111156100bc576100bb61024f565b5b6040519080825280602002602001820160405280156100f557816020015b6100e2610206565b8152602001906001900390816100da5790505b509050610103878783610190565b5050610110858583610190565b925092505094509492505050565b60008060008067ffffffffffffffff81111561013d5761013c61024f565b5b60405190808252806020026020018201604052801561017657816020015b610163610206565b81526020019060019003908161015b5790505b509050610184858583610190565b92509250509250929050565b60008060008060008787876040516020016101ad93929190610701565b6040516020818303038152906040529050600081519050604051604081836020860160006103e8600019f16101e157600080fd5b8051945060208101519350604081016040525083839550955050505050935093915050565b604051806040016040528060608152602001606081525090565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6102878261023e565b810181811067ffffffffffffffff821117156102a6576102a561024f565b5b80604052505050565b60006102b9610220565b90506102c5828261027e565b919050565b600067ffffffffffffffff8211156102e5576102e461024f565b5b6102ee8261023e565b9050602081019050919050565b82818337600083830152505050565b600061031d610318846102ca565b6102af565b90508281526020810184848401111561033957610338610239565b5b6103448482856102fb565b509392505050565b600082601f83011261036157610360610234565b5b813561037184826020860161030a565b91505092915050565b600080600080608085870312156103945761039361022a565b5b600085013567ffffffffffffffff8111156103b2576103b161022f565b5b6103be8782880161034c565b945050602085013567ffffffffffffffff8111156103df576103de61022f565b5b6103eb8782880161034c565b935050604085013567ffffffffffffffff81111561040c5761040b61022f565b5b6104188782880161034c565b925050606085013567ffffffffffffffff8111156104395761043861022f565b5b6104458782880161034c565b91505092959194509250565b60008115159050919050565b61046681610451565b82525050565b60008160070b9050919050565b6104828161046c565b82525050565b600060408201905061049d600083018561045d565b6104aa6020830184610479565b9392505050565b600080604083850312156104c8576104c761022a565b5b600083013567ffffffffffffffff8111156104e6576104e561022f565b5b6104f28582860161034c565b925050602083013567ffffffffffffffff8111156105135761051261022f565b5b61051f8582860161034c565b9150509250929050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610563578082015181840152602081019050610548565b83811115610572576000848401525b50505050565b600061058382610529565b61058d8185610534565b935061059d818560208601610545565b6105a68161023e565b840191505092915050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b600082825260208201905092915050565b60006105f982610529565b61060381856105dd565b9350610613818560208601610545565b61061c8161023e565b840191505092915050565b6000604083016000830151848203600086015261064482826105ee565b9150506020830151848203602086015261065e82826105ee565b9150508091505092915050565b60006106778383610627565b905092915050565b6000602082019050919050565b6000610697826105b1565b6106a181856105bc565b9350836020820285016106b3856105cd565b8060005b858110156106ef57848403895281516106d0858261066b565b94506106db8361067f565b925060208a019950506001810190506106b7565b50829750879550505050505092915050565b6000606082019050818103600083015261071b8186610578565b9050818103602083015261072f8185610578565b90508181036040830152610743818461068c565b905094935050505056fea26469706673582212207c6995442fefa9ad2c5b108cffcea33d88d6360353d695bdc6669f09b1fb3cbb64736f6c634300080b0033"; + // tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/GetBool.sol + const GET_BOOL_FUNCTION_HASH_0: &str = "fe598591"; // callGetBool(string,string) + const GET_BOOL_FUNCTION_HASH_1: &str = "7083d8ec"; // callGetBoolTwiceAndReturnSecondResult(string,string,string,string) + const GET_BOOL_BYTE_CODE: &str = "608060405234801561001057600080fd5b50610767806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80637083d8ec1461003b578063fe5985911461006c575b600080fd5b6100556004803603810190610050919061037a565b61009d565b60405161006392919061046c565b60405180910390f35b61008660048036038101906100819190610495565b61011e565b60405161009492919061046c565b60405180910390f35b60008060008067ffffffffffffffff8111156100bc576100bb61024f565b5b6040519080825280602002602001820160405280156100f557816020015b6100e2610206565b8152602001906001900390816100da5790505b509050610103878783610190565b5050610110858583610190565b925092505094509492505050565b60008060008067ffffffffffffffff81111561013d5761013c61024f565b5b60405190808252806020026020018201604052801561017657816020015b610163610206565b81526020019060019003908161015b5790505b509050610184858583610190565b92509250509250929050565b60008060008060008787876040516020016101ad939291906106e5565b6040516020818303038152906040529050600081519050604051604081836020860160006103e9600019f16101e157600080fd5b8051945060208101519350604081016040525083839550955050505050935093915050565b604051806040016040528060608152602001606081525090565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6102878261023e565b810181811067ffffffffffffffff821117156102a6576102a561024f565b5b80604052505050565b60006102b9610220565b90506102c5828261027e565b919050565b600067ffffffffffffffff8211156102e5576102e461024f565b5b6102ee8261023e565b9050602081019050919050565b82818337600083830152505050565b600061031d610318846102ca565b6102af565b90508281526020810184848401111561033957610338610239565b5b6103448482856102fb565b509392505050565b600082601f83011261036157610360610234565b5b813561037184826020860161030a565b91505092915050565b600080600080608085870312156103945761039361022a565b5b600085013567ffffffffffffffff8111156103b2576103b161022f565b5b6103be8782880161034c565b945050602085013567ffffffffffffffff8111156103df576103de61022f565b5b6103eb8782880161034c565b935050604085013567ffffffffffffffff81111561040c5761040b61022f565b5b6104188782880161034c565b925050606085013567ffffffffffffffff8111156104395761043861022f565b5b6104458782880161034c565b91505092959194509250565b60008115159050919050565b61046681610451565b82525050565b6000604082019050610481600083018561045d565b61048e602083018461045d565b9392505050565b600080604083850312156104ac576104ab61022a565b5b600083013567ffffffffffffffff8111156104ca576104c961022f565b5b6104d68582860161034c565b925050602083013567ffffffffffffffff8111156104f7576104f661022f565b5b6105038582860161034c565b9150509250929050565b600081519050919050565b600082825260208201905092915050565b60005b8381101561054757808201518184015260208101905061052c565b83811115610556576000848401525b50505050565b60006105678261050d565b6105718185610518565b9350610581818560208601610529565b61058a8161023e565b840191505092915050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b600082825260208201905092915050565b60006105dd8261050d565b6105e781856105c1565b93506105f7818560208601610529565b6106008161023e565b840191505092915050565b6000604083016000830151848203600086015261062882826105d2565b9150506020830151848203602086015261064282826105d2565b9150508091505092915050565b600061065b838361060b565b905092915050565b6000602082019050919050565b600061067b82610595565b61068581856105a0565b935083602082028501610697856105b1565b8060005b858110156106d357848403895281516106b4858261064f565b94506106bf83610663565b925060208a0199505060018101905061069b565b50829750879550505050505092915050565b600060608201905081810360008301526106ff818661055c565b90508181036020830152610713818561055c565b905081810360408301526107278184610670565b905094935050505056fea264697066735822122029e9d00dcee526443754516f9675d482d1df8c85c193c0ea11236c4163ca496f64736f6c634300080b0033"; + // tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/GetString.sol + const GET_STRING_FUNCTION_HASH_0: &str = "73260cf2"; // callGetString(string,string) + const GET_STRING_FUNCTION_HASH_1: &str = "4069716b"; // callGetStringTwiceAndReturnSecondResult(string,string,string,string) + const GET_STRING_BYTE_CODE: &str = "608060405234801561001057600080fd5b506107e9806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80634069716b1461003b57806373260cf21461006c575b600080fd5b610055600480360381019061005091906103f5565b61009d565b60405161006392919061056f565b60405180910390f35b6100866004803603810190610081919061059f565b61011f565b60405161009492919061056f565b60405180910390f35b6000606060008067ffffffffffffffff8111156100bd576100bc6102ca565b5b6040519080825280602002602001820160405280156100f657816020015b6100e3610281565b8152602001906001900390816100db5790505b509050610104878783610192565b5050610111858583610208565b925092505094509492505050565b6000606060008067ffffffffffffffff81111561013f5761013e6102ca565b5b60405190808252806020026020018201604052801561017857816020015b610165610281565b81526020019060019003908161015d5790505b509050610186858583610208565b92509250509250929050565b60008060008060008787876040516020016101af93929190610767565b6040516020818303038152906040529050600081519050604051604081836020860160006103e8600019f16101e357600080fd5b8051945060208101519350604081016040525083839550955050505050935093915050565b6000606060006060600087878760405160200161022793929190610767565b604051602081830303815290604052905060008151905060405161100081836020860160006103ea600019f161025c57600080fd5b8051945060408101935061100081016040525083839550955050505050935093915050565b604051806040016040528060608152602001606081525090565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b610302826102b9565b810181811067ffffffffffffffff82111715610321576103206102ca565b5b80604052505050565b600061033461029b565b905061034082826102f9565b919050565b600067ffffffffffffffff8211156103605761035f6102ca565b5b610369826102b9565b9050602081019050919050565b82818337600083830152505050565b600061039861039384610345565b61032a565b9050828152602081018484840111156103b4576103b36102b4565b5b6103bf848285610376565b509392505050565b600082601f8301126103dc576103db6102af565b5b81356103ec848260208601610385565b91505092915050565b6000806000806080858703121561040f5761040e6102a5565b5b600085013567ffffffffffffffff81111561042d5761042c6102aa565b5b610439878288016103c7565b945050602085013567ffffffffffffffff81111561045a576104596102aa565b5b610466878288016103c7565b935050604085013567ffffffffffffffff811115610487576104866102aa565b5b610493878288016103c7565b925050606085013567ffffffffffffffff8111156104b4576104b36102aa565b5b6104c0878288016103c7565b91505092959194509250565b60008115159050919050565b6104e1816104cc565b82525050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610521578082015181840152602081019050610506565b83811115610530576000848401525b50505050565b6000610541826104e7565b61054b81856104f2565b935061055b818560208601610503565b610564816102b9565b840191505092915050565b600060408201905061058460008301856104d8565b81810360208301526105968184610536565b90509392505050565b600080604083850312156105b6576105b56102a5565b5b600083013567ffffffffffffffff8111156105d4576105d36102aa565b5b6105e0858286016103c7565b925050602083013567ffffffffffffffff811115610601576106006102aa565b5b61060d858286016103c7565b9150509250929050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b600082825260208201905092915050565b600061065f826104e7565b6106698185610643565b9350610679818560208601610503565b610682816102b9565b840191505092915050565b600060408301600083015184820360008601526106aa8282610654565b915050602083015184820360208601526106c48282610654565b9150508091505092915050565b60006106dd838361068d565b905092915050565b6000602082019050919050565b60006106fd82610617565b6107078185610622565b93508360208202850161071985610633565b8060005b85811015610755578484038952815161073685826106d1565b9450610741836106e5565b925060208a0199505060018101905061071d565b50829750879550505050505092915050565b600060608201905081810360008301526107818186610536565b905081810360208301526107958185610536565b905081810360408301526107a981846106f2565b905094935050505056fea264697066735822122068d3d33b54fcdaec5e45509b8b96565a9f8246b11e88a0b6037d878ac7dd6f2a64736f6c634300080b0033"; + + #[test] + pub fn test_get_i64() { + let url = run(0).unwrap(); + let byte_code = hex::decode(GET_I64_BYTE_CODE).unwrap(); + let return_types = vec![ParamType::Bool, ParamType::Int(2)]; + + // given + let input_data = prepare_function_call_input( + GET_I64_FUNCTION_HASH_0, + encode(&[ + Token::String(format!( + "{}/2/users/by/username/twitterdev?user.fields=public_metrics", + url + )), + Token::String("/data/public_metrics/followers_count".to_string()), + ]), + ) + .unwrap(); + + // when + let (_, return_data) = execute_smart_contract(byte_code, input_data); + + // then + let decoded = decode(&return_types, &return_data).unwrap(); + assert_eq!(true, decoded[0].clone().into_bool().unwrap()); + assert_eq!(U256::from(100), decoded[1].clone().into_int().unwrap()); + } + + #[test] + pub fn test_get_i64_fail() { + let byte_code = hex::decode(GET_I64_BYTE_CODE).unwrap(); + let return_types = vec![ParamType::Bool, ParamType::Int(2)]; + + // given + let input_data = prepare_function_call_input( + GET_I64_FUNCTION_HASH_0, + encode(&[ + Token::String( + "http://localhost:1/2/users/by/username/twitterdev?user.fields=public_metrics" + .into(), + ), + Token::String("/data/public_metrics/followers_count".to_string()), + ]), + ) + .unwrap(); + + // when + let (_, return_data) = execute_smart_contract(byte_code, input_data); + + // then + let decoded = decode(&return_types, &return_data).unwrap(); + assert_eq!(false, decoded[0].clone().into_bool().unwrap()); + assert_eq!(U256::from(0), decoded[1].clone().into_int().unwrap()); + } + + // we want to check here that execution is not interrupted by http error + #[test] + pub fn test_get_i64_returns_second_error_in_case_of_first_request_failure() { + let url = run(0).unwrap(); + let byte_code = hex::decode(GET_I64_BYTE_CODE).unwrap(); + let return_types = vec![ParamType::Bool, ParamType::Int(2)]; + + // given + let input_data = prepare_function_call_input( + GET_I64_FUNCTION_HASH_1, + encode(&[ + // this one uses different port so service is unavailable + Token::String( + "http://localhost:1/2/users/by/username/twitterdev?user.fields=public_metrics" + .to_string(), + ), + Token::String("/data/public_metrics/followers_count".to_string()), + Token::String(format!( + "{}/2/users/by/username/twitterdev?user.fields=public_metrics", + url + )), + Token::String("/data/public_metrics/followers_count".to_string()), + ]), + ) + .unwrap(); + + // when + let (_, return_data) = execute_smart_contract(byte_code, input_data); + + // then + let decoded = decode(&return_types, &return_data).unwrap(); + assert_eq!(true, decoded[0].clone().into_bool().unwrap()); + assert_eq!(U256::from(100), decoded[1].clone().into_int().unwrap()); + } + + #[test] + pub fn test_get_bool() { + let url = run(0).unwrap(); + let byte_code = hex::decode(GET_BOOL_BYTE_CODE).unwrap(); + let return_types = vec![ParamType::Bool, ParamType::Bool]; + + // given + let input_data = prepare_function_call_input(GET_BOOL_FUNCTION_HASH_0, encode(&[ + Token::String(format!("{}/events/does-user-joined-evm-campaign?account=0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d", url)), + Token::String("/hasJoined".to_string())])).unwrap(); + + // when + let (_, return_data) = execute_smart_contract(byte_code, input_data); + + // then + let decoded = decode(&return_types, &return_data).unwrap(); + assert_eq!(true, decoded[0].clone().into_bool().unwrap()); + assert_eq!(true, decoded[1].clone().into_bool().unwrap()); + } + + #[test] + pub fn test_get_bool_fail() { + let byte_code = hex::decode(GET_BOOL_BYTE_CODE).unwrap(); + let return_types = vec![ParamType::Bool, ParamType::Bool]; + + // given + let input_data = prepare_function_call_input(GET_BOOL_FUNCTION_HASH_0, encode(&[ + Token::String("http://localhost:1/events/does-user-joined-evm-campaign?account=0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d".into()), + Token::String("/hasJoined".to_string())])).unwrap(); + + // when + let (_, return_data) = execute_smart_contract(byte_code, input_data); + + // then + let decoded = decode(&return_types, &return_data).unwrap(); + assert_eq!(false, decoded[0].clone().into_bool().unwrap()); + assert_eq!(false, decoded[1].clone().into_bool().unwrap()); + } + + // we want to check here that execution is not interrupted by http error + #[test] + pub fn test_get_bool_returns_second_error_in_case_of_first_request_failure() { + let url = run(0).unwrap(); + let byte_code = hex::decode(GET_BOOL_BYTE_CODE).unwrap(); + let return_types = vec![ParamType::Bool, ParamType::Bool]; + + // given + let input_data = prepare_function_call_input( + GET_BOOL_FUNCTION_HASH_1, + encode( + &[ + // this one uses different port so service is unavailable + Token::String("http://localhost:1/events/does-user-joined-evm-campaign?account=0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d".to_string()), + Token::String("/hasJoined".to_string()), + Token::String(format!("{}/events/does-user-joined-evm-campaign?account=0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d", url)), + Token::String("/hasJoined".to_string()) + ] + ) + ).unwrap(); + + // when + let (_, return_data) = execute_smart_contract(byte_code, input_data); + + // then + let decoded = decode(&return_types, &return_data).unwrap(); + assert_eq!(true, decoded[0].clone().into_bool().unwrap()); + assert_eq!(true, decoded[1].clone().into_bool().unwrap()); + } + + #[test] + pub fn test_get_string() { + let url = run(0).unwrap(); + let byte_code = hex::decode(GET_STRING_BYTE_CODE).unwrap(); + let return_types = vec![ParamType::Bool, ParamType::String]; + + // given + let input_data = prepare_function_call_input( + GET_STRING_FUNCTION_HASH_0, + encode(&[ + Token::String(format!( + "{}/v1/blocks/e4068e6a326243468f35dcdc0c43f686/children", + url + )), + Token::String("/object".to_string()), + ]), + ) + .unwrap(); + + // when + let (_, return_data) = execute_smart_contract(byte_code, input_data); + + // then + let decoded = decode(&return_types, &return_data).unwrap(); + assert_eq!(true, decoded[0].clone().into_bool().unwrap()); + assert_eq!("list", decoded[1].clone().into_string().unwrap()); + } + + #[test] + pub fn test_get_string_fail() { + let byte_code = hex::decode(GET_STRING_BYTE_CODE).unwrap(); + let return_types = vec![ParamType::Bool, ParamType::String]; + + // given + let input_data = prepare_function_call_input( + GET_STRING_FUNCTION_HASH_0, + encode(&[ + Token::String( + "http://localhost:1/v1/blocks/e4068e6a326243468f35dcdc0c43f686/children".into(), + ), + Token::String("/object".to_string()), + ]), + ) + .unwrap(); + + // when + let (_, return_data) = execute_smart_contract(byte_code, input_data); + + // then + let decoded = decode(&return_types, &return_data).unwrap(); + assert_eq!(false, decoded[0].clone().into_bool().unwrap()); + assert_eq!("", decoded[1].clone().into_string().unwrap()); + } + + // we want to check here that execution is not interrupted by http error + #[test] + pub fn test_get_string_returns_second_error_in_case_of_first_request_failure() { + let url = run(0).unwrap(); + let byte_code = hex::decode(GET_STRING_BYTE_CODE).unwrap(); + let return_types = vec![ParamType::Bool, ParamType::String]; + + // given + let input_data = prepare_function_call_input( + GET_STRING_FUNCTION_HASH_1, + encode(&[ + // this one uses different port so service is unavailable + Token::String( + "http://localhost:1/v1/blocks/e4068e6a326243468f35dcdc0c43f686/children".into(), + ), + Token::String("/object".to_string()), + Token::String(format!( + "{}/v1/blocks/e4068e6a326243468f35dcdc0c43f686/children", + url + )), + Token::String("/object".to_string()), + ]), + ) + .unwrap(); + + // when + let (_, return_data) = execute_smart_contract(byte_code, input_data); + + // then + let decoded = decode(&return_types, &return_data).unwrap(); + assert_eq!(true, decoded[0].clone().into_bool().unwrap()); + assert_eq!("list", decoded[1].clone().into_string().unwrap()); + } +} diff --git a/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/identity_to_string.rs b/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/identity_to_string.rs new file mode 100644 index 0000000000..f9a9f7b6ca --- /dev/null +++ b/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/identity_to_string.rs @@ -0,0 +1,398 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . + +use crate::{failure_precompile_output, precompiles::PrecompileResult, success_precompile_output}; +use base58::ToBase58; +use blake2_rfc::blake2b::Blake2b; +use litentry_primitives::{p2pkh_address, p2sh_address, p2tr_address, p2wpkh_address, Web3Network}; +use ss58_registry::Ss58AddressFormat; +use std::{format, string::String, vec, vec::Vec}; + +pub fn identity_to_string(input: Vec) -> PrecompileResult { + let decoded = + match ethabi::decode(&[ethabi::ParamType::Uint(32), ethabi::ParamType::Bytes], &input) { + Ok(d) => d, + Err(e) => { + log::debug!("Could not decode input {:?}, reason: {:?}", input, e); + return Ok(failure_precompile_output(ethabi::Token::String(Default::default()))) + }, + }; + + let network_type = decoded.get(0).and_then(|v| v.clone().into_uint().map(|t| t.as_u32() as u8)); + let identity_value = decoded.get(1).and_then(|v| v.clone().into_bytes()); + + let value = match (network_type, identity_value) { + // Substrate + (Some(n), Some(v)) if n <= Web3Network::SubstrateTestnet.get_code() => { + let network = match web3_network_to_chain(n) { + Ok(s) => s, + Err(e) => { + log::debug!("{:?}", e); + return Ok(failure_precompile_output(ethabi::Token::String(Default::default()))) + }, + }; + match ss58_address_of(v.as_ref(), &network) { + Ok(s) => s, + Err(e) => { + log::debug!("Cannot parse {:?} to ss58 address, reason: {:?}", v, e); + return Ok(failure_precompile_output(ethabi::Token::String(Default::default()))) + }, + } + }, + // Evm + (Some(n), Some(v)) + if [ + Web3Network::Ethereum.get_code(), + Web3Network::Bsc.get_code(), + Web3Network::Polygon.get_code(), + Web3Network::Arbitrum.get_code(), + Web3Network::Combo.get_code(), + ] + .contains(&n) => + format!("0x{}", hex::encode(&v)), + // Bitcoin + (Some(n), Some(v)) + if n >= Web3Network::BitcoinP2tr.get_code() + && n <= Web3Network::BitcoinP2wsh.get_code() => + { + let address = hex::encode(&v); + pubkey_to_address(n, &address) + }, + // Solana + (Some(n), Some(v)) if n == Web3Network::Solana.get_code() => v.to_base58(), + _ => { + log::debug!( + "Could not decode input {:?}, reason: network type or identity value is invalid", + input + ); + return Ok(failure_precompile_output(ethabi::Token::String(Default::default()))) + }, + }; + + Ok(success_precompile_output(ethabi::Token::String(value))) +} + +// mostly copied from https://github.com/hack-ink/substrate-minimal/blob/main/subcryptor/src/lib.rs +// no_std version is used here +fn ss58_address_of(public_key: &[u8], network: &str) -> core::result::Result { + let network = Ss58AddressFormat::try_from(network).map_err(|e| { + format!("Fail to parse ss58 address, network: {:?}, reason: {:?}", network, e) + })?; + let prefix = u16::from(network); + let mut bytes = match prefix { + 0..=63 => vec![prefix as u8], + 64..=16_383 => { + let first = ((prefix & 0b0000_0000_1111_1100) as u8) >> 2; + let second = ((prefix >> 8) as u8) | ((prefix & 0b0000_0000_0000_0011) as u8) << 6; + + vec![first | 0b01000000, second] + }, + _ => Err(format!("Fail to parse ss58 address, network: {:?}", network))?, + }; + + bytes.extend(public_key); + + let blake2b = { + let mut context = Blake2b::new(64); + context.update(b"SS58PRE"); + context.update(&bytes); + context.finalize() + }; + + bytes.extend(&blake2b.as_bytes()[0..2]); + + Ok(bytes.to_base58()) +} + +fn web3_network_to_chain(network: u8) -> Result { + Web3Network::from_code(network) + .map(|v| v.get_name()) + .ok_or(format!("Invalid network: {:?}", network)) +} + +fn pubkey_to_address(network: u8, pubkey: &str) -> String { + match network { + // BitcoinP2tr + 9 => p2tr_address(pubkey), + // BitcoinP2pkh + 10 => p2pkh_address(pubkey), + // BitcoinP2sh + 11 => p2sh_address(pubkey), + // BitcoinP2wpkh + 12 => p2wpkh_address(pubkey), + // BitcoinP2wsh and others + _ => "".into(), + } +} + +#[cfg(test)] +pub mod test { + use crate::{ + failure_precompile_output, precompiles::identity_to_string::identity_to_string, + success_precompile_output, + }; + use base58::FromBase58; + use ethabi::{encode, Token}; + use litentry_hex_utils::decode_hex; + use litentry_primitives::Web3Network; + + #[test] + fn test_substrate_identity_to_string() { + let address = "0xd4e35b16ec6b417386b948e7eaf5cc642a243096cecf366e6313689b90969f42"; + + vec![ + (Web3Network::Polkadot.get_code(), "15p8h3KAmkREatSn2e9TkD7ALJDo5UXZC56q7Bat2QQdxRgn"), + (Web3Network::Kusama.get_code(), "HPTD2PyYLAgu1FhqhuWW1e1dGWPBqnbZxD6LYsUx7bcXD1j"), + (Web3Network::Litentry.get_code(), "4BDaho6fgmXmRhzA79RCT9MLNLeunA3h3EGuBNXDNuqkgerR"), + (Web3Network::Litmus.get_code(), "jcS3pqDZ5mnXNxkLTBM3kHa5ypL4pSi39CWGoCASC51onUzHW"), + ] + .into_iter() + .for_each(|(network, expected_address)| { + // given + let encoded = encode(&[ + Token::Uint(network.into()), + Token::Bytes(decode_hex(address.as_bytes().to_vec()).unwrap()), + ]); + + // when + let result = identity_to_string(encoded).unwrap(); + + // then + assert_eq!(success_precompile_output(Token::String(expected_address.into())), result); + }); + + // Unsupported networks below + // LitentryRococo + // Khala + // SubstrateTestnet + } + + #[test] + fn test_evm_identity_to_string() { + let address = "0x582d872a1b094fc48f5de31d3b73f2d9be47def1"; + + vec![ + Web3Network::Ethereum, + Web3Network::Bsc, + Web3Network::Polygon, + Web3Network::Arbitrum, + Web3Network::Combo, + ] + .into_iter() + .map(|v| v.get_code()) + .for_each(|network| { + // given + let encoded = encode(&[ + Token::Uint(network.into()), + Token::Bytes(decode_hex(address.as_bytes().to_vec()).unwrap()), + ]); + + // when + let result = identity_to_string(encoded).unwrap(); + + // then + assert_eq!(success_precompile_output(Token::String(address.into())), result); + }); + } + + #[test] + fn test_bitcoin_identity_to_string() { + // given + let address = "0x02e8c39e82aaaa143c3def8d3c7084a539b227244ac9067c3f7fc86cb73a0b7aed"; + // BitcoinP2tr + let encoded = encode(&[ + Token::Uint(Web3Network::BitcoinP2tr.get_code().into()), + Token::Bytes(decode_hex(address.as_bytes().to_vec()).unwrap()), + ]); + + // when + let result = identity_to_string(encoded).unwrap(); + + // then + assert_eq!( + success_precompile_output(Token::String( + "bc1pgr5fw4p9gl9me0vzjklnlnap669caxc0gsk4j62gff2qktlw6naqm4m3d0".into() + )), + result + ); + } + + #[test] + fn test_solana_identity_to_string() { + // given + let address = "EJpLyTeE8XHG9CeREeHd6pr6hNhaRnTRJx4Z5DPhEJJ6"; + let encoded = encode(&[ + Token::Uint(Web3Network::Solana.get_code().into()), + Token::Bytes(address.from_base58().unwrap()), + ]); + + // when + let result = identity_to_string(encoded).unwrap(); + + // then + assert_eq!(success_precompile_output(Token::String(address.into())), result); + } + + #[test] + fn test_identity_to_string_fail() { + // given + let encoded = encode(&[Token::Uint(Web3Network::Ethereum.get_code().into())]); + + // when + let result = identity_to_string(encoded).unwrap(); + + // then + assert_eq!(failure_precompile_output(Token::String(Default::default())), result); + } +} + +#[cfg(test)] +pub mod integration_test { + use crate::{execute_smart_contract, prepare_function_call_input}; + use base58::FromBase58; + use ethabi::{decode, encode, ParamType, Token}; + use litentry_hex_utils::decode_hex; + use litentry_primitives::Web3Network; + + // tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/IdentityToString.sol + const FUNCTION_HASH: &str = "10e6b834"; // callIdentityToString(uint32,bytes) + const BYTE_CODE: &str = "608060405234801561001057600080fd5b50610472806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c806310e6b83414610030575b600080fd5b61004a60048036038101906100459190610279565b610061565b604051610058929190610378565b60405180910390f35b6000606061006f848461007a565b915091509250929050565b600060606000848460405160200161009392919061040c565b6040516020818303038152906040529050600081519050604051611000818360208601600061041c600019f16100c857600080fd5b80945060408101935061100081016040525050509250929050565b6000604051905090565b600080fd5b600080fd5b600063ffffffff82169050919050565b610110816100f7565b811461011b57600080fd5b50565b60008135905061012d81610107565b92915050565b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6101868261013d565b810181811067ffffffffffffffff821117156101a5576101a461014e565b5b80604052505050565b60006101b86100e3565b90506101c4828261017d565b919050565b600067ffffffffffffffff8211156101e4576101e361014e565b5b6101ed8261013d565b9050602081019050919050565b82818337600083830152505050565b600061021c610217846101c9565b6101ae565b90508281526020810184848401111561023857610237610138565b5b6102438482856101fa565b509392505050565b600082601f8301126102605761025f610133565b5b8135610270848260208601610209565b91505092915050565b600080604083850312156102905761028f6100ed565b5b600061029e8582860161011e565b925050602083013567ffffffffffffffff8111156102bf576102be6100f2565b5b6102cb8582860161024b565b9150509250929050565b60008115159050919050565b6102ea816102d5565b82525050565b600081519050919050565b600082825260208201905092915050565b60005b8381101561032a57808201518184015260208101905061030f565b83811115610339576000848401525b50505050565b600061034a826102f0565b61035481856102fb565b935061036481856020860161030c565b61036d8161013d565b840191505092915050565b600060408201905061038d60008301856102e1565b818103602083015261039f818461033f565b90509392505050565b6103b1816100f7565b82525050565b600081519050919050565b600082825260208201905092915050565b60006103de826103b7565b6103e881856103c2565b93506103f881856020860161030c565b6104018161013d565b840191505092915050565b600060408201905061042160008301856103a8565b818103602083015261043381846103d3565b9050939250505056fea2646970667358221220a8e59fddeaf8d08bc21acecdf46a244285a286724932b9533e674b6c2d22046464736f6c634300080b0033"; + + #[test] + pub fn test_substrate_identity_to_string() { + let byte_code = hex::decode(BYTE_CODE).unwrap(); + let return_types = vec![ParamType::Bool, ParamType::String]; + + let address = "0xd4e35b16ec6b417386b948e7eaf5cc642a243096cecf366e6313689b90969f42"; + + vec![ + (Web3Network::Polkadot.get_code(), "15p8h3KAmkREatSn2e9TkD7ALJDo5UXZC56q7Bat2QQdxRgn"), + (Web3Network::Kusama.get_code(), "HPTD2PyYLAgu1FhqhuWW1e1dGWPBqnbZxD6LYsUx7bcXD1j"), + (Web3Network::Litentry.get_code(), "4BDaho6fgmXmRhzA79RCT9MLNLeunA3h3EGuBNXDNuqkgerR"), + (Web3Network::Litmus.get_code(), "jcS3pqDZ5mnXNxkLTBM3kHa5ypL4pSi39CWGoCASC51onUzHW"), + ] + .into_iter() + .for_each(|(network, expected_address)| { + // given + let input_data = prepare_function_call_input( + FUNCTION_HASH, + encode(&[ + Token::Uint(network.into()), + Token::Bytes(decode_hex(address.as_bytes().to_vec()).unwrap()), + ]), + ) + .unwrap(); + + // when + let (_, return_data) = execute_smart_contract(byte_code.clone(), input_data); + + // then + let decoded = decode(&return_types, &return_data).unwrap(); + assert_eq!(true, decoded[0].clone().into_bool().unwrap()); + assert_eq!(expected_address, decoded[1].clone().into_string().unwrap()); + }); + } + + #[test] + fn test_evm_identity_to_string() { + let byte_code = hex::decode(BYTE_CODE).unwrap(); + let return_types = vec![ParamType::Bool, ParamType::String]; + + let address = "0x582d872a1b094fc48f5de31d3b73f2d9be47def1"; + + vec![ + Web3Network::Ethereum, + Web3Network::Bsc, + Web3Network::Polygon, + Web3Network::Arbitrum, + Web3Network::Combo, + ] + .into_iter() + .map(|v| v.get_code()) + .for_each(|network| { + // given + let input_data = prepare_function_call_input( + FUNCTION_HASH, + encode(&[ + Token::Uint(network.into()), + Token::Bytes(decode_hex(address.as_bytes().to_vec()).unwrap()), + ]), + ) + .unwrap(); + + // when + let (_, return_data) = execute_smart_contract(byte_code.clone(), input_data); + + // then + let decoded = decode(&return_types, &return_data).unwrap(); + assert_eq!(true, decoded[0].clone().into_bool().unwrap()); + assert_eq!(address, decoded[1].clone().into_string().unwrap()); + }); + } + + #[test] + fn test_bitcoin_identity_to_string() { + let byte_code = hex::decode(BYTE_CODE).unwrap(); + let return_types = vec![ParamType::Bool, ParamType::String]; + + // given + let address = "0x02e8c39e82aaaa143c3def8d3c7084a539b227244ac9067c3f7fc86cb73a0b7aed"; + let input_data = prepare_function_call_input( + FUNCTION_HASH, + encode(&[ + Token::Uint(Web3Network::BitcoinP2tr.get_code().into()), + Token::Bytes(decode_hex(address.as_bytes().to_vec()).unwrap()), + ]), + ) + .unwrap(); + let (_, return_data) = execute_smart_contract(byte_code.clone(), input_data); + + // when + let decoded = decode(&return_types, &return_data).unwrap(); + + // then + assert_eq!(true, decoded[0].clone().into_bool().unwrap()); + assert_eq!( + "bc1pgr5fw4p9gl9me0vzjklnlnap669caxc0gsk4j62gff2qktlw6naqm4m3d0", + decoded[1].clone().into_string().unwrap() + ); + } + + #[test] + fn test_solana_identity_to_string() { + let byte_code = hex::decode(BYTE_CODE).unwrap(); + let return_types = vec![ParamType::Bool, ParamType::String]; + + // given + let address = "EJpLyTeE8XHG9CeREeHd6pr6hNhaRnTRJx4Z5DPhEJJ6"; + let input_data = prepare_function_call_input( + FUNCTION_HASH, + encode(&[ + Token::Uint(Web3Network::Solana.get_code().into()), + Token::Bytes(address.from_base58().unwrap()), + ]), + ) + .unwrap(); + + // when + let (_, return_data) = execute_smart_contract(byte_code.clone(), input_data); + + // then + let decoded = decode(&return_types, &return_data).unwrap(); + assert_eq!(true, decoded[0].clone().into_bool().unwrap()); + assert_eq!(address, decoded[1].clone().into_string().unwrap()); + } +} diff --git a/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/macros.rs b/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/macros.rs index e7780c9032..7ff95bf6a7 100644 --- a/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/macros.rs +++ b/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/macros.rs @@ -38,13 +38,7 @@ macro_rules! http_get_precompile_fn { Ok(d) => d, Err(e) => { log::debug!("Could not decode bytes {:?}, reason: {:?}", input, e); - return Ok(evm::executor::stack::PrecompileOutput { - exit_status: evm::ExitSucceed::Returned, - output: ethabi::encode(&[ - ethabi::Token::Bool(false), - ethabi::Token::$token(Default::default()), - ]), - }) + return Ok(failure_precompile_output(ethabi::Token::$token(Default::default()))) }, }; // safe to unwrap @@ -53,13 +47,7 @@ macro_rules! http_get_precompile_fn { Ok(v) => v, Err(e) => { log::debug!("Could not parse url {:?}, reason: {:?}", url, e); - return Ok(evm::executor::stack::PrecompileOutput { - exit_status: evm::ExitSucceed::Returned, - output: ethabi::encode(&[ - ethabi::Token::Bool(false), - ethabi::Token::$token(Default::default()), - ]), - }) + return Ok(failure_precompile_output(ethabi::Token::$token(Default::default()))) }, }; @@ -104,64 +92,35 @@ macro_rules! http_get_precompile_fn { Ok(resp) => resp, Err(e) => { log::debug!("Error while performing http call: {:?}", e); - - return Ok(evm::executor::stack::PrecompileOutput { - exit_status: evm::ExitSucceed::Returned, - output: ethabi::encode(&[ - ethabi::Token::Bool(false), - ethabi::Token::$token(Default::default()), - ]), - }) + return Ok(failure_precompile_output(ethabi::Token::$token(Default::default()))) }, }; let value: serde_json::Value = match serde_json::from_slice(&resp.1) { Ok(v) => v, Err(e) => { log::debug!("Could not parse json {:?}, reason: {:?}", resp.1, e); - return Ok(evm::executor::stack::PrecompileOutput { - exit_status: evm::ExitSucceed::Returned, - output: ethabi::encode(&[ - ethabi::Token::Bool(false), - ethabi::Token::$token(Default::default()), - ]), - }) + return Ok(failure_precompile_output(ethabi::Token::$token(Default::default()))) }, }; let result = match value.pointer(&pointer) { Some(v) => v, None => { log::debug!("No value under given pointer: :{:?}", pointer); - return Ok(evm::executor::stack::PrecompileOutput { - exit_status: evm::ExitSucceed::Returned, - output: ethabi::encode(&[ - ethabi::Token::Bool(false), - ethabi::Token::$token(Default::default()), - ]), - }) + return Ok(failure_precompile_output(ethabi::Token::$token(Default::default()))) }, }; let encoded = match result.$parse_fn_name() { - Some(v) => - ethabi::encode(&[ethabi::Token::Bool(true), ethabi::Token::$token(v.into())]), + Some(v) => ethabi::Token::$token(v.into()), None => { log::debug!( "There is no value or it might be of different type, pointer: ${:?}", pointer ); - return Ok(evm::executor::stack::PrecompileOutput { - exit_status: evm::ExitSucceed::Returned, - output: ethabi::encode(&[ - ethabi::Token::Bool(false), - ethabi::Token::$token(Default::default()), - ]), - }) + return Ok(failure_precompile_output(ethabi::Token::$token(Default::default()))) }, }; - Ok(evm::executor::stack::PrecompileOutput { - exit_status: evm::ExitSucceed::Returned, - output: encoded, - }) + Ok(success_precompile_output(encoded)) } }; } diff --git a/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/mod.rs b/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/mod.rs index 42978ecda8..34c36c7d53 100644 --- a/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/mod.rs +++ b/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/mod.rs @@ -21,7 +21,11 @@ extern crate sgx_tstd as std; use crate::sgx_reexport_prelude::*; use crate::precompiles::{ + hex_to_number::hex_to_number, http_get::{http_get_bool, http_get_i64, http_get_string}, + identity_to_string::identity_to_string, + parse_decimal::parse_decimal, + parse_int::parse_int, to_hex::to_hex, }; use ethabi::ethereum_types::H160; @@ -31,8 +35,12 @@ use evm::executor::stack::{ use itc_rest_client::http_client::HttpClient; use std::result::Result as StdResult; +mod hex_to_number; mod http_get; +mod identity_to_string; mod macros; +mod parse_decimal; +mod parse_int; mod to_hex; #[cfg(test)] @@ -59,6 +67,10 @@ impl PrecompileSet for Precompiles { a if a == hash(1001) => Some(http_get_bool(handle.input().to_vec(), client)), a if a == hash(1002) => Some(http_get_string(handle.input().to_vec(), client)), a if a == hash(1051) => Some(to_hex(handle.input().to_vec())), + a if a == hash(1052) => Some(identity_to_string(handle.input().to_vec())), + a if a == hash(1053) => Some(hex_to_number(handle.input().to_vec())), + a if a == hash(1054) => Some(parse_decimal(handle.input().to_vec())), + a if a == hash(1055) => Some(parse_int(handle.input().to_vec())), _ => None, } } @@ -73,6 +85,14 @@ impl PrecompileSet for Precompiles { IsPrecompileResult::Answer { is_precompile: true, extra_cost: 0 }, a if a == hash(1051) => IsPrecompileResult::Answer { is_precompile: true, extra_cost: 0 }, + a if a == hash(1052) => + IsPrecompileResult::Answer { is_precompile: true, extra_cost: 0 }, + a if a == hash(1053) => + IsPrecompileResult::Answer { is_precompile: true, extra_cost: 0 }, + a if a == hash(1054) => + IsPrecompileResult::Answer { is_precompile: true, extra_cost: 0 }, + a if a == hash(1055) => + IsPrecompileResult::Answer { is_precompile: true, extra_cost: 0 }, _ => IsPrecompileResult::Answer { is_precompile: false, extra_cost: 0 }, } } diff --git a/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/parse_decimal.rs b/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/parse_decimal.rs new file mode 100644 index 0000000000..1717a18028 --- /dev/null +++ b/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/parse_decimal.rs @@ -0,0 +1,162 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . + +use crate::{ + alloc::string::ToString, failure_precompile_output, precompiles::PrecompileResult, + success_precompile_output, +}; +use ethabi::ethereum_types::U256; +use rust_decimal::prelude::{Decimal, FromStr}; +use std::vec::Vec; + +pub fn parse_decimal(input: Vec) -> PrecompileResult { + let decoded = + match ethabi::decode(&[ethabi::ParamType::String, ethabi::ParamType::Uint(8)], &input) { + Ok(d) => d, + Err(e) => { + log::debug!("Could not decode input {:?}, reason: {:?}", input, e); + return Ok(failure_precompile_output(ethabi::Token::Uint(Default::default()))) + }, + }; + + let string_value = decoded.get(0).and_then(|v| v.clone().into_string()); + let decimals = decoded + .get(1) + .and_then(|t| t.clone().into_uint()) + .map(|v| v.as_u32()) + .unwrap_or(0); + + let value = match string_value { + Some(s) => { + let decimal = match Decimal::from_str(s.as_str()) { + Ok(d) => d, + Err(e) => { + log::debug!("Cannot parse string {:?} to decimal, reason: {:?}", s, e); + return Ok(failure_precompile_output(ethabi::Token::Uint(Default::default()))) + }, + }; + + let processed_decimal_string = + (decimal * Decimal::new(10_i64.pow(decimals), 0)).normalize().to_string(); + match U256::from_dec_str(processed_decimal_string.as_str()) { + Ok(n) => n, + Err(e) => { + log::debug!( + "Cannot parse decimal {:?} to U256, reason: {:?}", + processed_decimal_string, + e + ); + return Ok(failure_precompile_output(ethabi::Token::Uint(Default::default()))) + }, + } + }, + None => { + log::debug!("Could not decode input {:?}, reason: string value is invalid", input); + return Ok(failure_precompile_output(ethabi::Token::Uint(Default::default()))) + }, + }; + + Ok(success_precompile_output(ethabi::Token::Uint(value))) +} + +#[cfg(test)] +pub mod test { + use crate::{ + failure_precompile_output, precompiles::parse_decimal::parse_decimal, + success_precompile_output, + }; + use ethabi::{encode, Token}; + + #[test] + pub fn test_parse_decimal() { + // given + let encoded = + encode(&[Token::String("1.00000000000000001".into()), Token::Uint(18.into())]); + + // when + let result = parse_decimal(encoded).unwrap(); + + // then + assert_eq!(success_precompile_output(Token::Uint(1000000000000000010_u128.into())), result) + } + + #[test] + pub fn test_parse_decimal_fail() { + // given + let encoded = + encode(&[Token::String("1.0000000000000000A".to_string()), Token::Uint(18.into())]); + + // when + let result = parse_decimal(encoded).unwrap(); + + // then + assert_eq!(failure_precompile_output(Token::Uint(Default::default())), result) + } +} + +#[cfg(test)] +pub mod integration_test { + use crate::{execute_smart_contract, prepare_function_call_input}; + use ethabi::{decode, encode, ethereum_types::U256, ParamType, Token}; + + // tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/ParseDecimal.sol + const FUNCTION_HASH: &str = "1abfaf23"; // callParseDecimal(string,uint8) + const BYTE_CODE: &str = "608060405234801561001057600080fd5b5061042a806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c80631abfaf2314610030575b600080fd5b61004a60048036038101906100459190610274565b610061565b604051610058929190610304565b60405180910390f35b60008061006e8484610079565b915091509250929050565b600080600084846040516020016100919291906103c4565b60405160208183030381529060405290506000815190506040516082818360208601600061041e600019f16100c557600080fd5b8051945060208101519350608281016040525050509250929050565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b610148826100ff565b810181811067ffffffffffffffff8211171561016757610166610110565b5b80604052505050565b600061017a6100e1565b9050610186828261013f565b919050565b600067ffffffffffffffff8211156101a6576101a5610110565b5b6101af826100ff565b9050602081019050919050565b82818337600083830152505050565b60006101de6101d98461018b565b610170565b9050828152602081018484840111156101fa576101f96100fa565b5b6102058482856101bc565b509392505050565b600082601f830112610222576102216100f5565b5b81356102328482602086016101cb565b91505092915050565b600060ff82169050919050565b6102518161023b565b811461025c57600080fd5b50565b60008135905061026e81610248565b92915050565b6000806040838503121561028b5761028a6100eb565b5b600083013567ffffffffffffffff8111156102a9576102a86100f0565b5b6102b58582860161020d565b92505060206102c68582860161025f565b9150509250929050565b60008115159050919050565b6102e5816102d0565b82525050565b6000819050919050565b6102fe816102eb565b82525050565b600060408201905061031960008301856102dc565b61032660208301846102f5565b9392505050565b600081519050919050565b600082825260208201905092915050565b60005b8381101561036757808201518184015260208101905061034c565b83811115610376576000848401525b50505050565b60006103878261032d565b6103918185610338565b93506103a1818560208601610349565b6103aa816100ff565b840191505092915050565b6103be8161023b565b82525050565b600060408201905081810360008301526103de818561037c565b90506103ed60208301846103b5565b939250505056fea2646970667358221220e2176c1afbb0895b7b8e73026b1ecb7859a6286cca205ecd1d1520f81539788764736f6c634300080b0033"; + + #[test] + pub fn test_parse_decimal() { + let byte_code = hex::decode(BYTE_CODE).unwrap(); + let return_types = vec![ParamType::Bool, ParamType::Uint(256)]; + + // given + let input_data = prepare_function_call_input( + FUNCTION_HASH, + encode(&[Token::String("1.00000000000000001".to_string()), Token::Uint(18.into())]), + ) + .unwrap(); + + // when + let (_, return_data) = execute_smart_contract(byte_code.clone(), input_data); + + // then + let decoded = decode(&return_types, &return_data).unwrap(); + assert_eq!(true, decoded[0].clone().into_bool().unwrap()); + let expected_result: U256 = 1000000000000000010_u128.into(); + assert_eq!(expected_result, decoded[1].clone().into_uint().unwrap()); + } + + #[test] + pub fn test_parse_decimal_fail() { + let byte_code = hex::decode(BYTE_CODE).unwrap(); + let return_types = vec![ParamType::Bool, ParamType::Uint(256)]; + + // given + let input_data = prepare_function_call_input( + FUNCTION_HASH, + encode(&[Token::String("1.0000000000000000A".to_string()), Token::Uint(18.into())]), + ) + .unwrap(); + + // when + let (_, return_data) = execute_smart_contract(byte_code.clone(), input_data); + + // then + let decoded = decode(&return_types, &return_data).unwrap(); + assert_eq!(false, decoded[0].clone().into_bool().unwrap()); + let expected_result: U256 = U256::zero(); + assert_eq!(expected_result, decoded[1].clone().into_uint().unwrap()); + } +} diff --git a/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/parse_int.rs b/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/parse_int.rs new file mode 100644 index 0000000000..1b097632c6 --- /dev/null +++ b/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/parse_int.rs @@ -0,0 +1,133 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . + +use crate::{failure_precompile_output, precompiles::PrecompileResult, success_precompile_output}; +use ethabi::ethereum_types::U256; +use std::vec::Vec; + +pub fn parse_int(input: Vec) -> PrecompileResult { + let decoded = match ethabi::decode(&[ethabi::ParamType::String], &input) { + Ok(d) => d, + Err(e) => { + log::debug!("Could not decode string {:?}, reason: {:?}", input, e); + return Ok(failure_precompile_output(ethabi::Token::Uint(Default::default()))) + }, + }; + + let string_value = decoded.get(0).and_then(|v| v.clone().into_string()); + + let value = match string_value { + Some(v) => match U256::from_dec_str(v.as_str()) { + Ok(n) => n, + Err(e) => { + log::debug!("Cannot parse string {:?} to U256, reason: {:?}", v, e); + return Ok(failure_precompile_output(ethabi::Token::Uint(Default::default()))) + }, + }, + None => { + log::debug!("Could not decode input {:?}, reason: string value is invalid", input); + return Ok(failure_precompile_output(ethabi::Token::Uint(Default::default()))) + }, + }; + + Ok(success_precompile_output(ethabi::Token::Uint(value))) +} + +#[cfg(test)] +pub mod test { + use crate::{ + failure_precompile_output, precompiles::parse_int::parse_int, success_precompile_output, + }; + use ethabi::{encode, Token}; + + #[test] + fn test_parse_int() { + // given + let encoded = encode(&[Token::String("100000000000000001".into())]); + + // when + let result = parse_int(encoded).unwrap(); + + // then + assert_eq!(success_precompile_output(Token::Uint(100000000000000001_u128.into())), result) + } + + #[test] + fn test_parse_int_fail() { + // given + let encoded = encode(&[Token::String("123XYZ".to_string())]); + + // when + let result = parse_int(encoded).unwrap(); + + // then + assert_eq!(failure_precompile_output(Token::Uint(Default::default())), result) + } +} + +#[cfg(test)] +pub mod integration_test { + use crate::{execute_smart_contract, prepare_function_call_input}; + use ethabi::{decode, encode, ethereum_types::U256, ParamType, Token}; + + // tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/ParseInt.sol + const FUNCTION_HASH: &str = "1fc5c204"; // callParseInt(string) + const BYTE_CODE: &str = "608060405234801561001057600080fd5b506103ba806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c80631fc5c20414610030575b600080fd5b61004a60048036038101906100459190610234565b610061565b6040516100589291906102b1565b60405180910390f35b60008061006d83610076565b91509150915091565b60008060008360405160200161008c9190610362565b60405160208183030381529060405290506000815190506040516082818360208601600061041f600019f16100c057600080fd5b805194506020810151935060828101604052505050915091565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b610141826100f8565b810181811067ffffffffffffffff821117156101605761015f610109565b5b80604052505050565b60006101736100da565b905061017f8282610138565b919050565b600067ffffffffffffffff82111561019f5761019e610109565b5b6101a8826100f8565b9050602081019050919050565b82818337600083830152505050565b60006101d76101d284610184565b610169565b9050828152602081018484840111156101f3576101f26100f3565b5b6101fe8482856101b5565b509392505050565b600082601f83011261021b5761021a6100ee565b5b813561022b8482602086016101c4565b91505092915050565b60006020828403121561024a576102496100e4565b5b600082013567ffffffffffffffff811115610268576102676100e9565b5b61027484828501610206565b91505092915050565b60008115159050919050565b6102928161027d565b82525050565b6000819050919050565b6102ab81610298565b82525050565b60006040820190506102c66000830185610289565b6102d360208301846102a2565b9392505050565b600081519050919050565b600082825260208201905092915050565b60005b838110156103145780820151818401526020810190506102f9565b83811115610323576000848401525b50505050565b6000610334826102da565b61033e81856102e5565b935061034e8185602086016102f6565b610357816100f8565b840191505092915050565b6000602082019050818103600083015261037c8184610329565b90509291505056fea26469706673582212201792beef9f71280990133d525ed3ac2f774f78b67e37f1c9606aa22a009a71f664736f6c634300080b0033"; + + #[test] + pub fn test_parse_int() { + let byte_code = hex::decode(BYTE_CODE).unwrap(); + let return_types = vec![ParamType::Bool, ParamType::Uint(256)]; + + // given + let input_data = prepare_function_call_input( + FUNCTION_HASH, + encode(&[Token::String("100000000000000001".to_string())]), + ) + .unwrap(); + + // when + let (_, return_data) = execute_smart_contract(byte_code.clone(), input_data); + + // then + let decoded = decode(&return_types, &return_data).unwrap(); + assert_eq!(true, decoded[0].clone().into_bool().unwrap()); + let expected_result: U256 = 100000000000000001_u128.into(); + assert_eq!(expected_result, decoded[1].clone().into_uint().unwrap()); + } + + #[test] + pub fn test_parse_int_fail() { + let byte_code = hex::decode(BYTE_CODE).unwrap(); + let return_types = vec![ParamType::Bool, ParamType::Uint(256)]; + + // given + let input_data = prepare_function_call_input( + FUNCTION_HASH, + encode(&[Token::String("123XYZ".to_string())]), + ) + .unwrap(); + + // when + let (_, return_data) = execute_smart_contract(byte_code.clone(), input_data); + + // then + let decoded = decode(&return_types, &return_data).unwrap(); + assert_eq!(false, decoded[0].clone().into_bool().unwrap()); + let expected_result: U256 = U256::zero(); + assert_eq!(expected_result, decoded[1].clone().into_uint().unwrap()); + } +} diff --git a/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/to_hex.rs b/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/to_hex.rs index 64123ac6ea..52a2e2f048 100644 --- a/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/to_hex.rs +++ b/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/to_hex.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Litentry. If not, see . -use crate::precompiles::PrecompileResult; +use crate::{failure_precompile_output, precompiles::PrecompileResult, success_precompile_output}; use std::{format, vec::Vec}; pub fn to_hex(input: Vec) -> PrecompileResult { @@ -22,48 +22,83 @@ pub fn to_hex(input: Vec) -> PrecompileResult { Ok(d) => d, Err(e) => { log::debug!("Could not decode bytes {:?}, reason: {:?}", input, e); - let encoded = ethabi::encode(&[ - ethabi::Token::Bool(true), - ethabi::Token::String(Default::default()), - ]); - return Ok(evm::executor::stack::PrecompileOutput { - exit_status: evm::ExitSucceed::Returned, - output: encoded, - }) + return Ok(failure_precompile_output(ethabi::Token::String(Default::default()))) + }, + }; + let bytes = match decoded.get(0).and_then(|v| v.clone().into_bytes()) { + Some(v) => v, + None => { + log::debug!("Could not convert decoded[0] to bytes"); + return Ok(failure_precompile_output(ethabi::Token::String(Default::default()))) }, }; - // safe to unwrap - let bytes = decoded.get(0).unwrap().clone().into_bytes().unwrap(); let hex_encoded = format!("0x{}", hex::encode(&bytes)); - let encoded = ethabi::encode(&[ethabi::Token::Bool(true), ethabi::Token::String(hex_encoded)]); - Ok(evm::executor::stack::PrecompileOutput { - exit_status: evm::ExitSucceed::Returned, - output: encoded, - }) + Ok(success_precompile_output(ethabi::Token::String(hex_encoded))) } #[cfg(test)] pub mod test { - use crate::precompiles::to_hex::to_hex; - use evm::ExitSucceed; + use crate::{ + failure_precompile_output, precompiles::to_hex::to_hex, success_precompile_output, + }; + use ethabi::{encode, Token}; #[test] pub fn test_to_hex() { // given let bytes = [1, 2, 3, 4]; - let encoded = ethabi::encode(&[ethabi::Token::Bytes(bytes.to_vec())]); + let encoded = encode(&[Token::Bytes(bytes.to_vec())]); // when let result = to_hex(encoded).unwrap(); - //then - assert!(matches!(result.exit_status, ExitSucceed::Returned)); - assert_eq!( - ethabi::encode(&[ - ethabi::Token::Bool(true), - ethabi::Token::String("0x01020304".to_string()) - ]), - result.output + // then + assert_eq!(success_precompile_output(Token::String("0x01020304".to_string())), result) + } + + #[test] + pub fn test_to_hex_fail() { + // given + let encoded = encode(&[]); + + // when + let result = to_hex(encoded).unwrap(); + + // then + assert_eq!(failure_precompile_output(Token::String(Default::default())), result) + } +} + +#[cfg(test)] +pub mod integration_test { + use crate::{execute_smart_contract, prepare_function_call_input}; + use ethabi::{decode, encode, ParamType, Token}; + + // tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/ToHex.sol + const FUNCTION_HASH: &str = "8876183c"; // callToHex(string) + const BYTE_CODE: &str = "608060405234801561001057600080fd5b506103ff806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c80638876183c14610030575b600080fd5b61004a60048036038101906100459190610236565b610061565b604051610058929190610322565b60405180910390f35b6000606061006e83610077565b91509150915091565b6000606060008360405160200161008e91906103a7565b6040516020818303038152906040529050600081519050604051611000818360208601600061041b600019f16100c357600080fd5b8094506040810193506110008101604052505050915091565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b610143826100fa565b810181811067ffffffffffffffff821117156101625761016161010b565b5b80604052505050565b60006101756100dc565b9050610181828261013a565b919050565b600067ffffffffffffffff8211156101a1576101a061010b565b5b6101aa826100fa565b9050602081019050919050565b82818337600083830152505050565b60006101d96101d484610186565b61016b565b9050828152602081018484840111156101f5576101f46100f5565b5b6102008482856101b7565b509392505050565b600082601f83011261021d5761021c6100f0565b5b813561022d8482602086016101c6565b91505092915050565b60006020828403121561024c5761024b6100e6565b5b600082013567ffffffffffffffff81111561026a576102696100eb565b5b61027684828501610208565b91505092915050565b60008115159050919050565b6102948161027f565b82525050565b600081519050919050565b600082825260208201905092915050565b60005b838110156102d45780820151818401526020810190506102b9565b838111156102e3576000848401525b50505050565b60006102f48261029a565b6102fe81856102a5565b935061030e8185602086016102b6565b610317816100fa565b840191505092915050565b6000604082019050610337600083018561028b565b818103602083015261034981846102e9565b90509392505050565b600081519050919050565b600082825260208201905092915050565b600061037982610352565b610383818561035d565b93506103938185602086016102b6565b61039c816100fa565b840191505092915050565b600060208201905081810360008301526103c1818461036e565b90509291505056fea26469706673582212209868a7cc2e186fcf1850b88ae8ea9657e8ae69edb105e38004a6a97e91d2a34e64736f6c634300080b0033"; + + #[test] + pub fn test_to_hex() { + let byte_code = hex::decode(BYTE_CODE).unwrap(); + let return_types = vec![ParamType::Bool, ParamType::String]; + + // given + let input_data = prepare_function_call_input( + FUNCTION_HASH, + encode(&[Token::String("test".to_string())]), ) + .unwrap(); + + // when + let (_, return_data) = execute_smart_contract(byte_code, input_data); + + // then + let decoded = decode(&return_types, &return_data).unwrap(); + assert_eq!(true, decoded[0].clone().into_bool().unwrap()); + assert_eq!( + format!("0x{}", &hex::encode("test")), + decoded[1].clone().into_string().unwrap() + ); } } diff --git a/tee-worker/litentry/core/mock-server/src/geniidata.rs b/tee-worker/litentry/core/mock-server/src/geniidata.rs index 51d964c6db..8f8b48c4fe 100644 --- a/tee-worker/litentry/core/mock-server/src/geniidata.rs +++ b/tee-worker/litentry/core/mock-server/src/geniidata.rs @@ -17,36 +17,85 @@ #![allow(opaque_hidden_inferred_bound)] use lc_data_providers::geniidata::{GeniidataResponse, ResponseData, ResponseItem}; -use std::vec::Vec; +use std::{collections::HashMap, vec::Vec}; use warp::{http::Response, Filter}; + pub(crate) fn query() -> impl Filter + Clone { - warp::get().and(warp::path!("api" / "1" / "brc20" / "balance")).map(|| { - let items = vec![ - ("ordi", "100.000000000000000000"), - ("rats", "18000000.000000000000000000"), - ("MMSS", "1000.000000000000000000"), - ]; - let list: Vec = items - .into_iter() - .map(|(tick, balance)| ResponseItem { - tick: tick.to_string(), - address: "bc1pmkk62aua2pghenz4nps5jgllfaer29ulgpmjm4p5wlc4ewjx3p3ql260rj" - .to_string(), - overall_balance: balance.to_string(), - transferable_balance: balance.to_string(), - available_balance: balance.to_string(), - }) - .collect(); - let res = GeniidataResponse { - code: 0, - message: "success".to_string(), - data: ResponseData { - count: 16435, - limit: "20".to_string(), - offset: "0".to_string(), - list, - }, - }; - Response::builder().body(serde_json::to_string(&res).unwrap()) - }) + warp::get() + .and(warp::path!("api" / "1" / "brc20" / "balance")) + .and(warp::query::>()) + .map(|params: HashMap| { + let default = String::default(); + let tick = params.get("tick").unwrap_or(&default).as_str(); + let address = params.get("address").unwrap_or(&default).as_str(); + + let _expected_address = + "bc1pgr5fw4p9gl9me0vzjklnlnap669caxc0gsk4j62gff2qktlw6naqm4m3d0"; + + match (tick, address) { + ("ordi", _expected_address) => { + let balance = "100.000000000000000000"; + let res = GeniidataResponse { + code: 0, + message: "success".into(), + data: ResponseData { + count: 1, + limit: "20".into(), + offset: "0".into(), + list: vec![ResponseItem { + tick: "ordi".into(), + address: _expected_address.into(), + overall_balance: balance.into(), + transferable_balance: balance.into(), + available_balance: balance.into(), + }], + }, + }; + Response::builder().body(serde_json::to_string(&res).unwrap()) + }, + ("rats", _expected_address) => { + let res = GeniidataResponse { + code: 0, + message: "success".into(), + data: ResponseData { + count: 0, + limit: "20".into(), + offset: "0".into(), + list: vec![], + }, + }; + Response::builder().body(serde_json::to_string(&res).unwrap()) + }, + _ => { + let items = vec![ + ("ordi", "100.000000000000000000"), + ("rats", "18000000.000000000000000000"), + ("MMSS", "1000.000000000000000000"), + ]; + let list: Vec = items + .into_iter() + .map(|(tick, balance)| ResponseItem { + tick: tick.to_string(), + address: + "bc1pmkk62aua2pghenz4nps5jgllfaer29ulgpmjm4p5wlc4ewjx3p3ql260rj" + .to_string(), + overall_balance: balance.to_string(), + transferable_balance: balance.to_string(), + available_balance: balance.to_string(), + }) + .collect(); + let res = GeniidataResponse { + code: 0, + message: "success".to_string(), + data: ResponseData { + count: 16435, + limit: "20".to_string(), + offset: "0".to_string(), + list, + }, + }; + Response::builder().body(serde_json::to_string(&res).unwrap()) + }, + } + }) } From 40db291da87871f8f7228074d2ecc33fd2105d1a Mon Sep 17 00:00:00 2001 From: Kasper Ziemianek Date: Mon, 10 Jun 2024 13:43:20 +0200 Subject: [PATCH 08/10] HTTP post precompiles (#2793) * HTTP post precompiles * DynamicAssertion.sol * review suggestions --- tee-worker/Cargo.lock | 1 + tee-worker/enclave-runtime/Cargo.lock | 1 + .../src/dynamic/contracts/libraries/Http.sol | 119 +++++ .../src/dynamic/contracts/tests/PostBool.sol | 46 ++ .../src/dynamic/contracts/tests/PostI64.sol | 46 ++ .../dynamic/contracts/tests/PostString.sol | 51 +++ .../src/precompiles/http_get.rs | 6 +- .../src/precompiles/http_post.rs | 407 ++++++++++++++++++ .../src/precompiles/macros.rs | 115 +++++ .../src/precompiles/mod.rs | 11 + 10 files changed, 800 insertions(+), 3 deletions(-) create mode 100644 tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/PostBool.sol create mode 100644 tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/PostI64.sol create mode 100644 tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/PostString.sol create mode 100644 tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/http_post.rs diff --git a/tee-worker/Cargo.lock b/tee-worker/Cargo.lock index 21a598e9ad..38f0b74483 100644 --- a/tee-worker/Cargo.lock +++ b/tee-worker/Cargo.lock @@ -3475,6 +3475,7 @@ name = "itp-enclave-metrics" version = "0.9.0" dependencies = [ "lc-stf-task-sender", + "litentry-primitives", "parity-scale-codec", "sgx_tstd", "substrate-fixed 0.5.9 (git+https://github.com/encointer/substrate-fixed?tag=v0.5.9)", diff --git a/tee-worker/enclave-runtime/Cargo.lock b/tee-worker/enclave-runtime/Cargo.lock index 199185c3bd..17fc9ed1fe 100644 --- a/tee-worker/enclave-runtime/Cargo.lock +++ b/tee-worker/enclave-runtime/Cargo.lock @@ -2355,6 +2355,7 @@ name = "itp-enclave-metrics" version = "0.9.0" dependencies = [ "lc-stf-task-sender", + "litentry-primitives", "parity-scale-codec", "sgx_tstd", "substrate-fixed 0.5.9 (git+https://github.com/encointer/substrate-fixed?tag=v0.5.9)", diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/libraries/Http.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/libraries/Http.sol index 8cf256da12..46370f4da5 100644 --- a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/libraries/Http.sol +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/libraries/Http.sol @@ -125,4 +125,123 @@ library Http { return (success, value); } + + function PostI64( + string memory url, + string memory jsonPointer, + string memory payload, + HttpHeader[] memory headers + ) internal returns (bool, int64) { + bool success; + int64 value; + + bytes memory encoded_params = abi.encode( + url, + jsonPointer, + payload, + headers + ); + uint256 encoded_params_len = encoded_params.length; + assembly { + let memPtr := mload(0x40) + if iszero( + call( + not(0), + 0x03EB, + 0, + add(encoded_params, 0x20), + encoded_params_len, + memPtr, + 0x40 + ) + ) { + revert(0, 0) + } + success := mload(memPtr) + value := mload(add(memPtr, 0x20)) + mstore(0x40, add(memPtr, 0x40)) + } + + return (success, value); + } + + function PostBool( + string memory url, + string memory jsonPointer, + string memory payload, + HttpHeader[] memory headers + ) internal returns (bool, bool) { + bool success; + bool value; + + bytes memory encoded_params = abi.encode( + url, + jsonPointer, + payload, + headers + ); + uint256 encoded_params_len = encoded_params.length; + + assembly { + let memPtr := mload(0x40) + if iszero( + call( + not(0), + 0x03EC, + 0, + add(encoded_params, 0x20), + encoded_params_len, + memPtr, + 0x40 + ) + ) { + revert(0, 0) + } + success := mload(memPtr) + value := mload(add(memPtr, 0x20)) + mstore(0x40, add(memPtr, 0x40)) + } + + return (success, value); + } + + function PostString( + string memory url, + string memory jsonPointer, + string memory payload, + HttpHeader[] memory headers + ) internal returns (bool, string memory) { + bool success; + string memory value; + + bytes memory encoded_params = abi.encode( + url, + jsonPointer, + payload, + headers + ); + uint256 encoded_params_len = encoded_params.length; + + assembly { + let memPtr := mload(0x40) + if iszero( + call( + not(0), + 0x03ED, + 0, + add(encoded_params, 0x20), + encoded_params_len, + memPtr, + 0x1000 + ) + ) { + revert(0, 0) + } + success := mload(memPtr) + value := add(memPtr, 0x40) + mstore(0x40, add(memPtr, 0x1000)) + } + + return (success, value); + } } diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/PostBool.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/PostBool.sol new file mode 100644 index 0000000000..825da427b1 --- /dev/null +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/PostBool.sol @@ -0,0 +1,46 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . + +// SPDX-License-Identifier: GPL-3.0-or-later + +pragma solidity ^0.8.8; + +import "../libraries/Http.sol"; + +contract PostBool { + function callPostBool( + string memory url, + string memory jsonPointer, + string memory payload + ) public returns (bool, bool) { + HttpHeader[] memory headers = new HttpHeader[](0); + return Http.PostBool(url, jsonPointer, payload, headers); + } + + function callPostBoolTwiceAndReturnSecondResult( + string memory firstUrl, + string memory firstJsonPointer, + string memory firstPayload, + string memory secondUrl, + string memory secondJsonPointer, + string memory secondPayload + ) public returns (bool, bool) { + HttpHeader[] memory headers = new HttpHeader[](0); + Http.PostBool(firstUrl, firstJsonPointer, firstPayload, headers); + return + Http.PostBool(secondUrl, secondJsonPointer, secondPayload, headers); + } +} diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/PostI64.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/PostI64.sol new file mode 100644 index 0000000000..fcd0012182 --- /dev/null +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/PostI64.sol @@ -0,0 +1,46 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . + +// SPDX-License-Identifier: GPL-3.0-or-later + +pragma solidity ^0.8.8; + +import "../libraries/Http.sol"; + +contract PostI64 { + function callPostI64( + string memory url, + string memory jsonPointer, + string memory payload + ) public returns (bool, int64) { + HttpHeader[] memory headers = new HttpHeader[](0); + return Http.PostI64(url, jsonPointer, payload, headers); + } + + function callPostI64TwiceAndReturnSecondResult( + string memory firstUrl, + string memory firstJsonPointer, + string memory firstPayload, + string memory secondUrl, + string memory secondJsonPointer, + string memory secondPayload + ) public returns (bool, int64) { + HttpHeader[] memory headers = new HttpHeader[](0); + Http.PostI64(firstUrl, firstJsonPointer, firstPayload, headers); + return + Http.PostI64(secondUrl, secondJsonPointer, secondPayload, headers); + } +} diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/PostString.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/PostString.sol new file mode 100644 index 0000000000..195222adb7 --- /dev/null +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/PostString.sol @@ -0,0 +1,51 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . + +// SPDX-License-Identifier: GPL-3.0-or-later + +pragma solidity ^0.8.8; + +import "../libraries/Http.sol"; + +contract PostString { + function callPostString( + string memory url, + string memory jsonPointer, + string memory payload + ) public returns (bool, string memory) { + HttpHeader[] memory headers = new HttpHeader[](0); + return Http.PostString(url, jsonPointer, payload, headers); + } + + function callPostStringTwiceAndReturnSecondResult( + string memory firstUrl, + string memory firstJsonPointer, + string memory firstPayload, + string memory secondUrl, + string memory secondJsonPointer, + string memory secondPayload + ) public returns (bool, string memory) { + HttpHeader[] memory headers = new HttpHeader[](0); + Http.PostString(firstUrl, firstJsonPointer, firstPayload, headers); + return + Http.PostString( + secondUrl, + secondJsonPointer, + secondPayload, + headers + ); + } +} diff --git a/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/http_get.rs b/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/http_get.rs index bb7c5993e5..b893820dce 100644 --- a/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/http_get.rs +++ b/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/http_get.rs @@ -235,7 +235,7 @@ pub mod integration_test { // we want to check here that execution is not interrupted by http error #[test] - pub fn test_get_i64_returns_second_error_in_case_of_first_request_failure() { + pub fn test_get_i64_returns_second_result_in_case_of_first_request_failure() { let url = run(0).unwrap(); let byte_code = hex::decode(GET_I64_BYTE_CODE).unwrap(); let return_types = vec![ParamType::Bool, ParamType::Int(2)]; @@ -309,7 +309,7 @@ pub mod integration_test { // we want to check here that execution is not interrupted by http error #[test] - pub fn test_get_bool_returns_second_error_in_case_of_first_request_failure() { + pub fn test_get_bool_returns_second_result_in_case_of_first_request_failure() { let url = run(0).unwrap(); let byte_code = hex::decode(GET_BOOL_BYTE_CODE).unwrap(); let return_types = vec![ParamType::Bool, ParamType::Bool]; @@ -393,7 +393,7 @@ pub mod integration_test { // we want to check here that execution is not interrupted by http error #[test] - pub fn test_get_string_returns_second_error_in_case_of_first_request_failure() { + pub fn test_get_string_returns_second_result_in_case_of_first_request_failure() { let url = run(0).unwrap(); let byte_code = hex::decode(GET_STRING_BYTE_CODE).unwrap(); let return_types = vec![ParamType::Bool, ParamType::String]; diff --git a/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/http_post.rs b/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/http_post.rs new file mode 100644 index 0000000000..91e561ae16 --- /dev/null +++ b/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/http_post.rs @@ -0,0 +1,407 @@ +use crate::*; +use itc_rest_client::http_client::SendHttpRequest; + +http_post_precompile_fn!(http_post_bool, Bool, as_bool); +http_post_precompile_fn!(http_post_i64, Uint, as_i64); +http_post_precompile_fn!(http_post_string, String, as_str); + +#[cfg(test)] +pub mod test { + use crate::{ + failure_precompile_output, + precompiles::{ + http_post::{http_post_bool, http_post_i64, http_post_string}, + mocks::MockedHttpClient, + }, + success_precompile_output, + }; + use ethabi::ethereum_types::U256; + use evm::ExitSucceed; + + #[test] + pub fn test_post_bool() { + // given + let client = MockedHttpClient::default(); + let data = prepare_input_data("https://www.litentry.com/", "/bool", "{}"); + + // when + let result = http_post_bool(data, client).unwrap(); + + // then + assert_eq!(success_precompile_output(ethabi::Token::Bool(true)), result) + } + + #[test] + pub fn test_post_i64() { + // given + let client = MockedHttpClient::default(); + let data = prepare_input_data("https://www.litentry.com/", "/i64", "{}"); + + // when + let result = http_post_i64(data, client).unwrap(); + + // then + assert_eq!( + success_precompile_output(ethabi::Token::Uint(U256::try_from(10).unwrap())), + result + ) + } + + #[test] + pub fn test_post_string() { + // given + let client = MockedHttpClient::default(); + let data = prepare_input_data("https://www.litentry.com/", "/string", "{}"); + + // when + let result = http_post_string(data, client).unwrap(); + + // then + assert_eq!(success_precompile_output(ethabi::Token::String("string".to_string())), result) + } + + #[test] + pub fn returns_failure_for_invalid_url() { + // given + let client = MockedHttpClient::default(); + let data = prepare_input_data("invalid_url", "/string", "{}"); + + // when + let result = http_post_string(data, client).unwrap(); + + // then + assert_eq!(failure_precompile_output(ethabi::Token::String(Default::default())), result) + } + + #[test] + pub fn returns_failure_for_invalid_json_pointer() { + // given + let client = MockedHttpClient::default(); + let data = prepare_input_data("https://www.litentry.com/", "invalid_pointer", "{}"); + + // when + let result = http_post_string(data, client).unwrap(); + + // then + assert_eq!(failure_precompile_output(ethabi::Token::String(Default::default())), result) + } + + #[test] + pub fn returns_failure_for_malformed_json() { + // given + let client = MockedHttpClient::malformed_json(); + let data = prepare_input_data("https://www.litentry.com/", "string", "{}"); + + // when + let result = http_post_string(data, client).unwrap(); + + // then + assert_eq!(failure_precompile_output(ethabi::Token::String(Default::default())), result) + } + + #[test] + pub fn returns_failure_for_value_of_type_other_than_expected() { + // given + let client = MockedHttpClient::default(); + let data = prepare_input_data("https://www.litentry.com/", "/not_bool", "{}"); + + // when + let result = http_post_bool(data, client).unwrap(); + + // then + assert_eq!(failure_precompile_output(ethabi::Token::Bool(false)), result) + } + + #[test] + pub fn returns_failure_for_invalid_input_data() { + // given + let client = MockedHttpClient::default(); + let data = [0u8, 11]; + + // when + let result = http_post_bool(data.to_vec(), client).unwrap(); + + // then + assert!(matches!(result.exit_status, ExitSucceed::Returned)); + assert_eq!(failure_precompile_output(ethabi::Token::Bool(false)), result) + } + + #[test] + pub fn returns_error_for_http_error() { + // given + let client = MockedHttpClient::http_error(); + let data = prepare_input_data("https://www.litentry.com/", "string", "{}"); + + // when + let result = http_post_string(data, client).unwrap(); + + // then + assert!(matches!(result.exit_status, ExitSucceed::Returned)); + assert_eq!(failure_precompile_output(ethabi::Token::String(Default::default())), result) + } + + fn prepare_input_data(url: &str, pointer: &str, payload: &str) -> Vec { + ethabi::encode(&[ + ethabi::Token::String(url.to_string()), + ethabi::Token::String(pointer.to_string()), + ethabi::Token::String(payload.to_string()), + ethabi::Token::Array(vec![]), + ]) + } +} + +#[cfg(test)] +pub mod integration_test { + use crate::{execute_smart_contract, prepare_function_call_input}; + use ethabi::{encode, ethereum_types::U256, Token}; + use lc_mock_server::run; + + // tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/PostI64.sol + const POST_I64_FUNCTION_HASH_0: &str = "2381daad"; // callPostI64(string,string,string) + const POST_I64_FUNCTION_HASH_1: &str = "18f0d608"; // callPostI64TwiceAndReturnSecondResult(string,string,string,string,string,string) + const POST_I64_BYTE_CODE: &str = "608060405234801561001057600080fd5b5061051a806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c806318f0d6081461003b5780632381daad1461006c575b600080fd5b61004e61004936600461025a565b61007f565b60408051921515835260079190910b60208301520160405180910390f35b61004e61007a36600461034f565b6100ed565b6040805160008082526020820190925281908190816100c0565b60408051808201909152606080825260208201528152602001906001900390816100995790505b5090506100cf8989898461014a565b50506100dd8686868461014a565b9250925050965096945050505050565b60408051600080825260208201909252819081908161012e565b60408051808201909152606080825260208201528152602001906001900390816101075790505b50905061013d8686868461014a565b9250925050935093915050565b6000806000806000888888886040516020016101699493929190610424565b60408051601f198184030181528282528051909350919081836020860160006103eb600019f161019857600080fd5b8051602082015160409283019092529b909a5098505050505050505050565b634e487b7160e01b600052604160045260246000fd5b600082601f8301126101de57600080fd5b813567ffffffffffffffff808211156101f9576101f96101b7565b604051601f8301601f19908116603f01168101908282118183101715610221576102216101b7565b8160405283815286602085880101111561023a57600080fd5b836020870160208301376000602085830101528094505050505092915050565b60008060008060008060c0878903121561027357600080fd5b863567ffffffffffffffff8082111561028b57600080fd5b6102978a838b016101cd565b975060208901359150808211156102ad57600080fd5b6102b98a838b016101cd565b965060408901359150808211156102cf57600080fd5b6102db8a838b016101cd565b955060608901359150808211156102f157600080fd5b6102fd8a838b016101cd565b9450608089013591508082111561031357600080fd5b61031f8a838b016101cd565b935060a089013591508082111561033557600080fd5b5061034289828a016101cd565b9150509295509295509295565b60008060006060848603121561036457600080fd5b833567ffffffffffffffff8082111561037c57600080fd5b610388878388016101cd565b9450602086013591508082111561039e57600080fd5b6103aa878388016101cd565b935060408601359150808211156103c057600080fd5b506103cd868287016101cd565b9150509250925092565b6000815180845260005b818110156103fd576020818501810151868301820152016103e1565b8181111561040f576000602083870101525b50601f01601f19169290920160200192915050565b60808152600061043760808301876103d7565b60208382038185015261044a82886103d7565b915060408483038186015261045f83886103d7565b925084830360608601528286518085528385019150838160051b86010184890160005b838110156104d257878303601f19018552815180518785526104a6888601826103d7565b91890151858303868b01529190506104be81836103d7565b968901969450505090860190600101610482565b50909c9b50505050505050505050505056fea264697066735822122049f0442b4788f10091894993479dbd5aa31707e778e37c370888cdb77c24445264736f6c634300080b0033"; + + // tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/PostBool.sol + const POST_BOOL_FUNCTION_HASH_0: &str = "9c428231"; // callPostBool(string,string,string) + const POST_BOOL_FUNCTION_HASH_1: &str = "c668f937"; // callPostBoolTwiceAndReturnSecondResult(string,string,string,string,string,string) + const POST_BOOL_BYTE_CODE: &str = "608060405234801561001057600080fd5b50610517806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80639c4282311461003b578063c668f93714610069575b600080fd5b61004e610049366004610257565b61007c565b60408051921515835290151560208301520160405180910390f35b61004e6100773660046102df565b6100d9565b6040805160008082526020820190925281908190816100bd565b60408051808201909152606080825260208201528152602001906001900390816100965790505b5090506100cc86868684610147565b9250925050935093915050565b60408051600080825260208201909252819081908161011a565b60408051808201909152606080825260208201528152602001906001900390816100f35790505b50905061012989898984610147565b505061013786868684610147565b9250925050965096945050505050565b6000806000806000888888886040516020016101669493929190610421565b60408051601f198184030181528282528051909350919081836020860160006103ec600019f161019557600080fd5b8051602082015160409283019092529b909a5098505050505050505050565b634e487b7160e01b600052604160045260246000fd5b600082601f8301126101db57600080fd5b813567ffffffffffffffff808211156101f6576101f66101b4565b604051601f8301601f19908116603f0116810190828211818310171561021e5761021e6101b4565b8160405283815286602085880101111561023757600080fd5b836020870160208301376000602085830101528094505050505092915050565b60008060006060848603121561026c57600080fd5b833567ffffffffffffffff8082111561028457600080fd5b610290878388016101ca565b945060208601359150808211156102a657600080fd5b6102b2878388016101ca565b935060408601359150808211156102c857600080fd5b506102d5868287016101ca565b9150509250925092565b60008060008060008060c087890312156102f857600080fd5b863567ffffffffffffffff8082111561031057600080fd5b61031c8a838b016101ca565b9750602089013591508082111561033257600080fd5b61033e8a838b016101ca565b9650604089013591508082111561035457600080fd5b6103608a838b016101ca565b9550606089013591508082111561037657600080fd5b6103828a838b016101ca565b9450608089013591508082111561039857600080fd5b6103a48a838b016101ca565b935060a08901359150808211156103ba57600080fd5b506103c789828a016101ca565b9150509295509295509295565b6000815180845260005b818110156103fa576020818501810151868301820152016103de565b8181111561040c576000602083870101525b50601f01601f19169290920160200192915050565b60808152600061043460808301876103d4565b60208382038185015261044782886103d4565b915060408483038186015261045c83886103d4565b925084830360608601528286518085528385019150838160051b86010184890160005b838110156104cf57878303601f19018552815180518785526104a3888601826103d4565b91890151858303868b01529190506104bb81836103d4565b96890196945050509086019060010161047f565b50909c9b50505050505050505050505056fea2646970667358221220e2f5fd57d4e1af1e82babd9ad9c76106e329c8efcff87511ffe94203235eadc664736f6c634300080b0033"; + + // tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/PostString.sol + const POST_STRING_FUNCTION_HASH_0: &str = "a7481684"; // callPostString(string,string,string) + const POST_STRING_FUNCTION_HASH_1: &str = "1ad1cfaf"; // callPostStringTwiceAndReturnSecondResult(string,string,string,string,string,string) + const POST_STRING_BYTE_CODE: &str = "608060405234801561001057600080fd5b5061053c806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80631ad1cfaf1461003b578063a748168414610065575b600080fd5b61004e610049366004610259565b610078565b60405161005c92919061039b565b60405180910390f35b61004e6100733660046103be565b6100e7565b604080516000808252602082019092526060908290816100ba565b60408051808201909152606080825260208201528152602001906001900390816100935790505b5090506100c989898984610145565b50506100d786868684610145565b9250925050965096945050505050565b60408051600080825260208201909252606090829081610129565b60408051808201909152606080825260208201528152602001906001900390816101025790505b50905061013886868684610145565b9250925050935093915050565b60006060600060606000888888886040516020016101669493929190610446565b60408051601f198184030181529082905280519092509061100081836020860160006103ed600019f161019857600080fd5b805161100082016040908152909c91019a5098505050505050505050565b634e487b7160e01b600052604160045260246000fd5b600082601f8301126101dd57600080fd5b813567ffffffffffffffff808211156101f8576101f86101b6565b604051601f8301601f19908116603f01168101908282118183101715610220576102206101b6565b8160405283815286602085880101111561023957600080fd5b836020870160208301376000602085830101528094505050505092915050565b60008060008060008060c0878903121561027257600080fd5b863567ffffffffffffffff8082111561028a57600080fd5b6102968a838b016101cc565b975060208901359150808211156102ac57600080fd5b6102b88a838b016101cc565b965060408901359150808211156102ce57600080fd5b6102da8a838b016101cc565b955060608901359150808211156102f057600080fd5b6102fc8a838b016101cc565b9450608089013591508082111561031257600080fd5b61031e8a838b016101cc565b935060a089013591508082111561033457600080fd5b5061034189828a016101cc565b9150509295509295509295565b6000815180845260005b8181101561037457602081850181015186830182015201610358565b81811115610386576000602083870101525b50601f01601f19169290920160200192915050565b82151581526040602082015260006103b6604083018461034e565b949350505050565b6000806000606084860312156103d357600080fd5b833567ffffffffffffffff808211156103eb57600080fd5b6103f7878388016101cc565b9450602086013591508082111561040d57600080fd5b610419878388016101cc565b9350604086013591508082111561042f57600080fd5b5061043c868287016101cc565b9150509250925092565b608081526000610459608083018761034e565b60208382038185015261046c828861034e565b9150604084830381860152610481838861034e565b925084830360608601528286518085528385019150838160051b86010184890160005b838110156104f457878303601f19018552815180518785526104c88886018261034e565b91890151858303868b01529190506104e0818361034e565b9689019694505050908601906001016104a4565b50909c9b50505050505050505050505056fea2646970667358221220d9f558cc5e728c0489649cd34bf73d7e31d7c2e6bdc209e25925d9e3326e36db64736f6c634300080b0033"; + + #[test] + pub fn test_post_i64() { + run(19534).unwrap(); + + // given + let byte_code = hex::decode(POST_I64_BYTE_CODE).unwrap(); + let input_data = prepare_function_call_input(POST_I64_FUNCTION_HASH_0, + encode( + &[ + Token::String("http://localhost:19534/v1/run/system-labels".to_string()), + Token::String("/runningCost".to_string()), + Token::String(r#"{"name": "Account total transactions under {amount}", "address": "test", "params": {"chain": "ChainName"}, "includeMetadata": false }"#.to_string()) + ])).unwrap(); + let (_, return_data) = execute_smart_contract(byte_code, input_data); + let types = vec![ethabi::ParamType::Bool, ethabi::ParamType::Int(2)]; + + // when + let decoded = ethabi::decode(&types, &return_data).unwrap(); + + // then + assert_eq!(true, decoded[0].clone().into_bool().unwrap()); + assert_eq!(U256::from(1), decoded[1].clone().into_int().unwrap()); + } + + #[test] + pub fn test_post_i64_with_failure() { + // given + let byte_code = hex::decode(POST_I64_BYTE_CODE).unwrap(); + let input_data = prepare_function_call_input(POST_I64_FUNCTION_HASH_0, + encode( + &[ + Token::String("http://localhost:1/v1/run/system-labels".to_string()), + Token::String("/runningCost".to_string()), + Token::String(r#"{"name": "Account total transactions under {amount}", "address": "test", "params": {"chain": "ChainName"}, "includeMetadata": false }"#.to_string()) + ])).unwrap(); + let (_, return_data) = execute_smart_contract(byte_code, input_data); + let types = vec![ethabi::ParamType::Bool, ethabi::ParamType::Int(2)]; + + // when + let decoded = ethabi::decode(&types, &return_data).unwrap(); + + // then + assert_eq!(false, decoded[0].clone().into_bool().unwrap()); + assert_eq!(U256::from(0), decoded[1].clone().into_int().unwrap()); + } + + #[test] + pub fn test_post_i64_returns_second_result_in_case_of_first_request_failure() { + run(19535).unwrap(); + + // given + let byte_code = hex::decode(POST_I64_BYTE_CODE).unwrap(); + let input_data = prepare_function_call_input(POST_I64_FUNCTION_HASH_1, + encode( + &[ + // this one uses different port so service is unavailable + Token::String("http://localhost:1/v1/run/system-labels".to_string()), + Token::String("/runningCost".to_string()), + Token::String(r#"{"name": "Account total transactions under {amount}", "address": "test", "params": {"chain": "ChainName"}, "includeMetadata": false }"#.to_string()), + Token::String("http://localhost:19535/v1/run/system-labels".to_string()), + Token::String("/runningCost".to_string()), + Token::String(r#"{"name": "Account total transactions under {amount}", "address": "test", "params": {"chain": "ChainName"}, "includeMetadata": false }"#.to_string()) + ] + ) + ).unwrap(); + let (_, return_data) = execute_smart_contract(byte_code, input_data); + let types = vec![ethabi::ParamType::Bool, ethabi::ParamType::Int(2)]; + + // when + let decoded = ethabi::decode(&types, &return_data).unwrap(); + + // then + assert_eq!(true, decoded[0].clone().into_bool().unwrap()); + assert_eq!(U256::from(1), decoded[1].clone().into_int().unwrap()); + } + + #[test] + pub fn test_post_bool() { + run(19536).unwrap(); + + // given + let byte_code = hex::decode(POST_BOOL_BYTE_CODE).unwrap(); + let input_data = prepare_function_call_input(POST_BOOL_FUNCTION_HASH_0, + encode( + &[ + Token::String("http://localhost:19536/v1/run/system-labels".to_string()), + Token::String("/result".to_string()), + Token::String(r#"{"name": "Account total transactions under {amount}", "address": "test", "params": {"chain": "ChainName"}, "includeMetadata": false }"#.to_string()) + ])).unwrap(); + let (_, return_data) = execute_smart_contract(byte_code, input_data); + let types = vec![ethabi::ParamType::Bool, ethabi::ParamType::Bool]; + + // when + let decoded = ethabi::decode(&types, &return_data).unwrap(); + + // then + assert_eq!(true, decoded[0].clone().into_bool().unwrap()); + assert_eq!(true, decoded[1].clone().into_bool().unwrap()); + } + + #[test] + pub fn test_post_bool_with_failure() { + // given + let byte_code = hex::decode(POST_BOOL_BYTE_CODE).unwrap(); + let input_data = prepare_function_call_input(POST_BOOL_FUNCTION_HASH_0, + encode( + &[ + Token::String("http://localhost:1/v1/run/system-labels".to_string()), + Token::String("/result".to_string()), + Token::String(r#"{"name": "Account total transactions under {amount}", "address": "test", "params": {"chain": "ChainName"}, "includeMetadata": false }"#.to_string()) + ])).unwrap(); + let (_, return_data) = execute_smart_contract(byte_code, input_data); + let types = vec![ethabi::ParamType::Bool, ethabi::ParamType::Bool]; + + // when + let decoded = ethabi::decode(&types, &return_data).unwrap(); + + // then + assert_eq!(false, decoded[0].clone().into_bool().unwrap()); + assert_eq!(false, decoded[1].clone().into_bool().unwrap()); + } + + #[test] + pub fn test_post_bool_returns_second_result_in_case_of_first_request_failure() { + run(19537).unwrap(); + + // given + let byte_code = hex::decode(POST_BOOL_BYTE_CODE).unwrap(); + let input_data = prepare_function_call_input(POST_BOOL_FUNCTION_HASH_1, + encode( + &[ + // this one uses different port so service is unavailable + Token::String("http://localhost:1/v1/run/system-labels".to_string()), + Token::String("/result".to_string()), + Token::String(r#"{"name": "Account total transactions under {amount}", "address": "test", "params": {"chain": "ChainName"}, "includeMetadata": false }"#.to_string()), + Token::String("http://localhost:19537/v1/run/system-labels".to_string()), + Token::String("/result".to_string()), + Token::String(r#"{"name": "Account total transactions under {amount}", "address": "test", "params": {"chain": "ChainName"}, "includeMetadata": false }"#.to_string()) + ] + ) + ).unwrap(); + let (_, return_data) = execute_smart_contract(byte_code, input_data); + let types = vec![ethabi::ParamType::Bool, ethabi::ParamType::Bool]; + + // when + let decoded = ethabi::decode(&types, &return_data).unwrap(); + + // then + assert_eq!(true, decoded[0].clone().into_bool().unwrap()); + assert_eq!(true, decoded[1].clone().into_bool().unwrap()); + } + + #[test] + pub fn test_post_string() { + run(19538).unwrap(); + + // given + let byte_code = hex::decode(POST_STRING_BYTE_CODE).unwrap(); + let input_data = prepare_function_call_input(POST_STRING_FUNCTION_HASH_0, + encode( + &[ + Token::String("http://localhost:19538/v1/run/system-labels".to_string()), + Token::String("/display/0/text".to_string()), + Token::String(r#"{"name": "Account total transactions under {amount}", "address": "test", "params": {"chain": "ChainName"}, "includeMetadata": false }"#.to_string()) + ])).unwrap(); + let (_, return_data) = execute_smart_contract(byte_code, input_data); + let types = vec![ethabi::ParamType::Bool, ethabi::ParamType::String]; + + // when + let decoded = ethabi::decode(&types, &return_data).unwrap(); + + // then + assert_eq!(true, decoded[0].clone().into_bool().unwrap()); + assert_eq!( + "Total transactions under 1 (Transactions: 41)", + decoded[1].clone().into_string().unwrap() + ); + } + + #[test] + pub fn test_post_string_with_failure() { + // given + let byte_code = hex::decode(POST_STRING_BYTE_CODE).unwrap(); + let input_data = prepare_function_call_input(POST_STRING_FUNCTION_HASH_0, + encode( + &[ + Token::String("http://localhost:1/v1/run/system-labels".to_string()), + Token::String("/display/0/text".to_string()), + Token::String(r#"{"name": "Account total transactions under {amount}", "address": "test", "params": {"chain": "ChainName"}, "includeMetadata": false }"#.to_string()) + ])).unwrap(); + let (_, return_data) = execute_smart_contract(byte_code, input_data); + let types = vec![ethabi::ParamType::Bool, ethabi::ParamType::String]; + + // when + let decoded = ethabi::decode(&types, &return_data).unwrap(); + + // then + assert_eq!(false, decoded[0].clone().into_bool().unwrap()); + assert_eq!("", decoded[1].clone().into_string().unwrap()); + } + + #[test] + pub fn test_post_string_returns_second_result_in_case_of_first_request_failure() { + run(19539).unwrap(); + + // given + let byte_code = hex::decode(POST_STRING_BYTE_CODE).unwrap(); + let input_data = prepare_function_call_input(POST_STRING_FUNCTION_HASH_1, + encode( + &[ + // this one uses different port so service is unavailable + Token::String("http://localhost:1/v1/run/system-labels".to_string()), + Token::String("/display/0/text".to_string()), + Token::String(r#"{"name": "Account total transactions under {amount}", "address": "test", "params": {"chain": "ChainName"}, "includeMetadata": false }"#.to_string()), + Token::String("http://localhost:19539/v1/run/system-labels".to_string()), + Token::String("/display/0/text".to_string()), + Token::String(r#"{"name": "Account total transactions under {amount}", "address": "test", "params": {"chain": "ChainName"}, "includeMetadata": false }"#.to_string()) + ] + ) + ).unwrap(); + let (_, return_data) = execute_smart_contract(byte_code, input_data); + let types = vec![ethabi::ParamType::Bool, ethabi::ParamType::String]; + + // when + let decoded = ethabi::decode(&types, &return_data).unwrap(); + + // then + assert_eq!(true, decoded[0].clone().into_bool().unwrap()); + assert_eq!( + "Total transactions under 1 (Transactions: 41)", + decoded[1].clone().into_string().unwrap() + ); + } +} diff --git a/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/macros.rs b/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/macros.rs index 7ff95bf6a7..738144cfd2 100644 --- a/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/macros.rs +++ b/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/macros.rs @@ -124,3 +124,118 @@ macro_rules! http_get_precompile_fn { } }; } + +#[macro_export] +macro_rules! http_post_precompile_fn { + ($name:ident, $token:ident, $parse_fn_name:ident) => { + pub fn $name( + input: Vec, + client: T, + ) -> $crate::precompiles::PrecompileResult { + let decoded = match ethabi::decode( + &[ + ethabi::ParamType::String, + ethabi::ParamType::String, + ethabi::ParamType::String, + ethabi::ParamType::Array( + ethabi::ParamType::Tuple(vec![ + ethabi::ParamType::String, + ethabi::ParamType::String, + ]) + .into(), + ), + ], + &input, + ) { + Ok(d) => d, + Err(e) => { + log::debug!("Could not decode bytes {:?}, reason: {:?}", input, e); + return Ok(failure_precompile_output(ethabi::Token::$token(Default::default()))) + }, + }; + // safe to unwrap + let url = decoded.get(0).unwrap().clone().into_string().unwrap(); + let url = match itc_rest_client::rest_client::Url::parse(&url) { + Ok(v) => v, + Err(e) => { + log::debug!("Could not parse url {:?}, reason: {:?}", url, e); + return Ok(failure_precompile_output(ethabi::Token::$token(Default::default()))) + }, + }; + + // safe to unwrap + let pointer = decoded.get(1).unwrap().clone().into_string().unwrap(); + + let payload = decoded.get(2).unwrap().clone().into_string().unwrap(); + + let http_headers: Vec<(String, String)> = decoded + .get(3) + .unwrap() + .clone() + .into_array() + .unwrap() + .iter() + .map(|v| { + let name = v + .clone() + .into_tuple() + .unwrap() + .get(0) + .unwrap() + .clone() + .into_string() + .unwrap(); + let value = v + .clone() + .into_tuple() + .unwrap() + .get(1) + .unwrap() + .clone() + .into_string() + .unwrap(); + + (name, value) + }) + .collect(); + let resp = match client.send_request_raw( + url, + itc_rest_client::rest_client::Method::POST, + Some(payload), + http_headers, + ) { + Ok(resp) => resp, + Err(e) => { + log::debug!("Error while performing http call: {:?}", e); + return Ok(failure_precompile_output(ethabi::Token::$token(Default::default()))) + }, + }; + let value: serde_json::Value = match serde_json::from_slice(&resp.1) { + Ok(v) => v, + Err(e) => { + log::debug!("Could not parse json {:?}, reason: {:?}", resp.1, e); + return Ok(failure_precompile_output(ethabi::Token::$token(Default::default()))) + }, + }; + let result = match value.pointer(&pointer) { + Some(v) => v, + None => { + log::debug!("No value under given pointer: :{:?}", pointer); + return Ok(failure_precompile_output(ethabi::Token::$token(Default::default()))) + }, + }; + + let encoded = match result.$parse_fn_name() { + Some(v) => ethabi::Token::$token(v.into()), + None => { + log::debug!( + "There is no value or it might be of different type, pointer: ${:?}", + pointer + ); + return Ok(failure_precompile_output(ethabi::Token::$token(Default::default()))) + }, + }; + Ok(success_precompile_output(encoded)) + } + }; +} diff --git a/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/mod.rs b/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/mod.rs index 34c36c7d53..1d436419f6 100644 --- a/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/mod.rs +++ b/tee-worker/litentry/core/evm-dynamic-assertions/src/precompiles/mod.rs @@ -23,6 +23,7 @@ use crate::sgx_reexport_prelude::*; use crate::precompiles::{ hex_to_number::hex_to_number, http_get::{http_get_bool, http_get_i64, http_get_string}, + http_post::{http_post_bool, http_post_i64, http_post_string}, identity_to_string::identity_to_string, parse_decimal::parse_decimal, parse_int::parse_int, @@ -37,6 +38,7 @@ use std::result::Result as StdResult; mod hex_to_number; mod http_get; +mod http_post; mod identity_to_string; mod macros; mod parse_decimal; @@ -66,6 +68,9 @@ impl PrecompileSet for Precompiles { a if a == hash(1000) => Some(http_get_i64(handle.input().to_vec(), client)), a if a == hash(1001) => Some(http_get_bool(handle.input().to_vec(), client)), a if a == hash(1002) => Some(http_get_string(handle.input().to_vec(), client)), + a if a == hash(1003) => Some(http_post_i64(handle.input().to_vec(), client)), + a if a == hash(1004) => Some(http_post_bool(handle.input().to_vec(), client)), + a if a == hash(1005) => Some(http_post_string(handle.input().to_vec(), client)), a if a == hash(1051) => Some(to_hex(handle.input().to_vec())), a if a == hash(1052) => Some(identity_to_string(handle.input().to_vec())), a if a == hash(1053) => Some(hex_to_number(handle.input().to_vec())), @@ -83,6 +88,12 @@ impl PrecompileSet for Precompiles { IsPrecompileResult::Answer { is_precompile: true, extra_cost: 0 }, a if a == hash(1002) => IsPrecompileResult::Answer { is_precompile: true, extra_cost: 0 }, + a if a == hash(1003) => + IsPrecompileResult::Answer { is_precompile: true, extra_cost: 0 }, + a if a == hash(1004) => + IsPrecompileResult::Answer { is_precompile: true, extra_cost: 0 }, + a if a == hash(1005) => + IsPrecompileResult::Answer { is_precompile: true, extra_cost: 0 }, a if a == hash(1051) => IsPrecompileResult::Answer { is_precompile: true, extra_cost: 0 }, a if a == hash(1052) => From ba2c26eade30ac3c8457d4c6588827d5b6215e70 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 11 Jun 2024 08:10:08 +0200 Subject: [PATCH 09/10] Bump strum_macros from 0.26.3 to 0.26.4 (#2796) Bumps [strum_macros](https://github.com/Peternator7/strum) from 0.26.3 to 0.26.4. - [Release notes](https://github.com/Peternator7/strum/releases) - [Changelog](https://github.com/Peternator7/strum/blob/master/CHANGELOG.md) - [Commits](https://github.com/Peternator7/strum/commits) --- updated-dependencies: - dependency-name: strum_macros dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index be5ad9b073..9b6d7035e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1209,7 +1209,7 @@ dependencies = [ "sp-runtime", "sp-std", "strum 0.26.2", - "strum_macros 0.26.3", + "strum_macros 0.26.4", ] [[package]] @@ -13531,9 +13531,9 @@ dependencies = [ [[package]] name = "strum_macros" -version = "0.26.3" +version = "0.26.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7993a8e3a9e88a00351486baae9522c91b123a088f76469e5bd5cc17198ea87" +checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" dependencies = [ "heck 0.5.0", "proc-macro2", From 6b470c61e2a158fb6bca9ce8ef1422b60b970d89 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 11 Jun 2024 08:10:33 +0200 Subject: [PATCH 10/10] Bump proc-macro2 from 1.0.84 to 1.0.85 (#2798) Bumps [proc-macro2](https://github.com/dtolnay/proc-macro2) from 1.0.84 to 1.0.85. - [Release notes](https://github.com/dtolnay/proc-macro2/releases) - [Commits](https://github.com/dtolnay/proc-macro2/compare/1.0.84...1.0.85) --- updated-dependencies: - dependency-name: proc-macro2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9b6d7035e0..2d391493e5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9924,9 +9924,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.84" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec96c6a92621310b51366f1e28d05ef11489516e93be030060e5fc12024a49d6" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" dependencies = [ "unicode-ident", ]