-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f36e4c7
commit 458571b
Showing
5 changed files
with
548 additions
and
0 deletions.
There are no files selected for viewing
153 changes: 153 additions & 0 deletions
153
tee-worker/litentry/core/assertion-build/src/dynamic/contracts/libraries/Json.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
// 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 <https://www.gnu.org/licenses/>. | ||
|
||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
pragma solidity ^0.8.8; | ||
|
||
library Json { | ||
function getString(string memory json, string memory pointer) | ||
internal | ||
returns (bool, string memory) | ||
{ | ||
bool success; | ||
string memory value; | ||
bytes memory encoded_params = abi.encode(json, pointer); | ||
|
||
uint256 encoded_params_len = encoded_params.length; | ||
|
||
assembly { | ||
let memPtr := mload(0x40) | ||
if iszero( | ||
call( | ||
not(0), | ||
0x044C, | ||
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 getI64(string memory json, string memory pointer) | ||
internal | ||
returns (bool, int64) | ||
{ | ||
bool success; | ||
int64 value; | ||
|
||
bytes memory encoded_params = abi.encode(json, pointer); | ||
uint256 encoded_params_len = encoded_params.length; | ||
|
||
assembly { | ||
let memPtr := mload(0x40) | ||
if iszero( | ||
call( | ||
not(0), | ||
0x044D, | ||
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 json, string memory pointer) | ||
internal | ||
returns (bool, bool) | ||
{ | ||
bool success; | ||
bool value; | ||
|
||
bytes memory encoded_params = abi.encode(json, pointer); | ||
uint256 encoded_params_len = encoded_params.length; | ||
|
||
assembly { | ||
let memPtr := mload(0x40) | ||
if iszero( | ||
call( | ||
not(0), | ||
0x044E, | ||
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 getArrayLen(string memory json, string memory pointer) | ||
internal | ||
returns (bool, int64) | ||
{ | ||
bool success; | ||
int64 value; | ||
|
||
bytes memory encoded_params = abi.encode(json, pointer); | ||
uint256 encoded_params_len = encoded_params.length; | ||
|
||
assembly { | ||
let memPtr := mload(0x40) | ||
if iszero( | ||
call( | ||
not(0), | ||
0x044F, | ||
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); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
tee-worker/litentry/core/assertion-build/src/dynamic/contracts/tests/JsonTest.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <https://www.gnu.org/licenses/>. | ||
|
||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
pragma solidity ^0.8.8; | ||
|
||
import "../libraries/Json.sol"; | ||
|
||
contract JsonTest { | ||
function callGetString(string memory json, string memory pointer) | ||
public | ||
returns (bool, string memory) | ||
{ | ||
return Json.getString(json, pointer); | ||
} | ||
|
||
function callGetI64(string memory json, string memory pointer) | ||
public | ||
returns (bool, int64) | ||
{ | ||
return Json.getI64(json, pointer); | ||
} | ||
|
||
function callGetBool(string memory json, string memory pointer) | ||
public | ||
returns (bool, bool) | ||
{ | ||
return Json.getBool(json, pointer); | ||
} | ||
|
||
function callGetArrayLen(string memory json, string memory pointer) | ||
public | ||
returns (bool, int64) | ||
{ | ||
return Json.getArrayLen(json, pointer); | ||
} | ||
} |
Oops, something went wrong.