diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9282e82..1d8fce6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,10 @@ name: test -on: workflow_dispatch +on: + push: + branches: + - main + pull_request: env: FOUNDRY_PROFILE: ci diff --git a/src/CairoLib.sol b/src/CairoLib.sol index fafa543..af8f883 100644 --- a/src/CairoLib.sol +++ b/src/CairoLib.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity >=0.7.0 <0.9.0; +pragma solidity >=0.8.0 <0.9.0; library CairoLib { /// @dev The Cairo precompile contract's address. @@ -11,10 +11,10 @@ library CairoLib { /// @param contractAddress The address of the Cairo contract. /// @param functionSelector The function selector of the Cairo contract function to be called. /// @param data The input data for the Cairo contract function. - /// @return returnData The return data from the Cairo contract function. + /// @return The return data from the Cairo contract function. function callCairo(uint256 contractAddress, uint256 functionSelector, uint256[] memory data) internal - returns (bytes memory returnData) + returns (bytes memory) { bytes memory callData = abi.encodeWithSignature("call_contract(uint256,uint256,uint256[])", contractAddress, functionSelector, data); @@ -22,15 +22,15 @@ library CairoLib { (bool success, bytes memory result) = CAIRO_PRECOMPILE_ADDRESS.call(callData); require(success, string(abi.encodePacked("CairoLib: call_contract failed with: ", result))); - returnData = result; + return result; } /// @notice Performs a low-level call to a Cairo contract deployed on the Starknet appchain. /// @dev Used with intent to modify the state of the Cairo contract. /// @param contractAddress The address of the Cairo contract. /// @param functionSelector The function selector of the Cairo contract function to be called. - /// @return returnData The return data from the Cairo contract function. - function callCairo(uint256 contractAddress, uint256 functionSelector) internal returns (bytes memory returnData) { + /// @return The return data from the Cairo contract function. + function callCairo(uint256 contractAddress, uint256 functionSelector) internal returns (bytes memory) { uint256[] memory data = new uint256[](0); return callCairo(contractAddress, functionSelector, data); } @@ -38,11 +38,10 @@ library CairoLib { /// @notice Performs a low-level call to a Cairo contract deployed on the Starknet appchain. /// @dev Used with intent to modify the state of the Cairo contract. /// @param functionName The name of the Cairo contract function to be called. - /// - /// @return returnData The return data from the Cairo contract function. + /// @return The return data from the Cairo contract function. function callCairo(uint256 contractAddress, string memory functionName, uint256[] memory data) internal - returns (bytes memory returnData) + returns (bytes memory) { uint256 functionSelector = uint256(keccak256(bytes(functionName))) % 2 ** 250; return callCairo(contractAddress, functionSelector, data); @@ -51,11 +50,8 @@ library CairoLib { /// @notice Performs a low-level call to a Cairo contract deployed on the Starknet appchain. /// @dev Used with intent to modify the state of the Cairo contract. /// @param functionName The name of the Cairo contract function to be called. - /// @return returnData The return data from the Cairo contract function. - function callCairo(uint256 contractAddress, string memory functionName) - internal - returns (bytes memory returnData) - { + /// @return The return data from the Cairo contract function. + function callCairo(uint256 contractAddress, string memory functionName) internal returns (bytes memory) { uint256[] memory data = new uint256[](0); uint256 functionSelector = uint256(keccak256(bytes(functionName))) % 2 ** 250; return callCairo(contractAddress, functionSelector, data); @@ -68,10 +64,10 @@ library CairoLib { /// @param contractAddress The address of the Cairo contract. /// @param functionSelector The function selector of the Cairo contract function to be called. /// @param data The input data for the Cairo contract function. - /// @return returnData The return data from the Cairo contract function. + /// @return The return data from the Cairo contract function. function delegatecallCairo(uint256 contractAddress, uint256 functionSelector, uint256[] memory data) internal - returns (bytes memory returnData) + returns (bytes memory) { bytes memory callData = abi.encodeWithSignature("call_contract(uint256,uint256,uint256[])", contractAddress, functionSelector, data); @@ -79,7 +75,7 @@ library CairoLib { (bool success, bytes memory result) = CAIRO_PRECOMPILE_ADDRESS.delegatecall(callData); require(success, string(abi.encodePacked("CairoLib: call_contract failed with: ", result))); - returnData = result; + return result; } /// @notice Performs a low-level delegatecall to a Cairo contract deployed on the Starknet appchain. @@ -88,11 +84,8 @@ library CairoLib { /// callee contract is performed using the `msg.sender` of the calling contract. /// @param contractAddress The address of the Cairo contract. /// @param functionSelector The function selector of the Cairo contract function to be called. - /// @return returnData The return data from the Cairo contract function. - function delegatecallCairo(uint256 contractAddress, uint256 functionSelector) - internal - returns (bytes memory returnData) - { + /// @return The return data from the Cairo contract function. + function delegatecallCairo(uint256 contractAddress, uint256 functionSelector) internal returns (bytes memory) { uint256[] memory data = new uint256[](0); return delegatecallCairo(contractAddress, functionSelector, data); } @@ -104,10 +97,10 @@ library CairoLib { /// @param contractAddress The address of the Cairo contract. /// @param functionName The name of the Cairo contract function to be called. /// @param data The input data for the Cairo contract function. - /// @return returnData The return data from the Cairo contract function. + /// @return The return data from the Cairo contract function. function delegatecallCairo(uint256 contractAddress, string memory functionName, uint256[] memory data) internal - returns (bytes memory returnData) + returns (bytes memory) { uint256 functionSelector = uint256(keccak256(bytes(functionName))) % 2 ** 250; return delegatecallCairo(contractAddress, functionSelector, data); @@ -119,11 +112,8 @@ library CairoLib { /// callee contract is performed using the `msg.sender` of the calling contract. /// @param contractAddress The address of the Cairo contract. /// @param functionName The name of the Cairo contract function to be called. - /// @return returnData The return data from the Cairo contract function. - function delegatecallCairo(uint256 contractAddress, string memory functionName) - internal - returns (bytes memory returnData) - { + /// @return The return data from the Cairo contract function. + function delegatecallCairo(uint256 contractAddress, string memory functionName) internal returns (bytes memory) { uint256[] memory data = new uint256[](0); uint256 functionSelector = uint256(keccak256(bytes(functionName))) % 2 ** 250; return delegatecallCairo(contractAddress, functionSelector, data); @@ -134,11 +124,11 @@ library CairoLib { /// @param contractAddress The address of the Cairo contract. /// @param functionSelector The function selector of the Cairo contract function to be called. /// @param data The input data for the Cairo contract function. - /// @return returnData The return data from the Cairo contract function. + /// @return The return data from the Cairo contract function. function staticcallCairo(uint256 contractAddress, uint256 functionSelector, uint256[] memory data) internal view - returns (bytes memory returnData) + returns (bytes memory) { bytes memory callData = abi.encodeWithSignature("call_contract(uint256,uint256,uint256[])", contractAddress, functionSelector, data); @@ -146,19 +136,15 @@ library CairoLib { (bool success, bytes memory result) = CAIRO_PRECOMPILE_ADDRESS.staticcall(callData); require(success, string(abi.encodePacked("CairoLib: call_contract failed with: ", result))); - returnData = result; + return result; } /// @notice Performs a low-level call to a Cairo contract deployed on the Starknet appchain. /// @dev Used with intent to read the state of the Cairo contract. /// @param contractAddress The address of the Cairo contract. /// @param functionSelector The function selector of the Cairo contract function to be called. - /// @return returnData The return data from the Cairo contract function. - function staticcallCairo(uint256 contractAddress, uint256 functionSelector) - internal - view - returns (bytes memory returnData) - { + /// @return The return data from the Cairo contract function. + function staticcallCairo(uint256 contractAddress, uint256 functionSelector) internal view returns (bytes memory) { uint256[] memory data = new uint256[](0); return staticcallCairo(contractAddress, functionSelector, data); } @@ -168,11 +154,11 @@ library CairoLib { /// @param contractAddress The address of the Cairo contract. /// @param functionName The name of the Cairo contract function to be called. /// @param data The input data for the Cairo contract function. - /// @return returnData The return data from the Cairo contract function. + /// @return The return data from the Cairo contract function. function staticcallCairo(uint256 contractAddress, string memory functionName, uint256[] memory data) internal view - returns (bytes memory returnData) + returns (bytes memory) { uint256 functionSelector = uint256(keccak256(bytes(functionName))) % 2 ** 250; return staticcallCairo(contractAddress, functionSelector, data); @@ -182,11 +168,11 @@ library CairoLib { /// @dev Used with intent to read the state of the Cairo contract. /// @param contractAddress The address of the Cairo contract. /// @param functionName The name of the Cairo contract function to be called. - /// @return returnData The return data from the Cairo contract function. + /// @return The return data from the Cairo contract function. function staticcallCairo(uint256 contractAddress, string memory functionName) internal view - returns (bytes memory returnData) + returns (bytes memory) { uint256[] memory data = new uint256[](0); uint256 functionSelector = uint256(keccak256(bytes(functionName))) % 2 ** 250; @@ -205,12 +191,13 @@ library CairoLib { /// @dev A ByteArray is represented as: /** * pub struct ByteArray { - * data: Array, - * pending_word: felt252, - * pending_word_len: usize, - * } - * where `data` is an array of 31-byte packed words, and `pending_word` word of size `pending_word_len`. - * + * full_words_len: felt252, + * full_words: [], + * pending_word: felt252, + * pending_word_len: usize, + * } + * where `full_words` is an array of 31-byte packed words, and `pending_word` word of size `pending_word_len`. + * Note that those full words are 32 bytes long, but only 31 bytes are used. */ /// @param data The Cairo representation of the ByteArray serialized to bytes. function byteArrayToString(bytes memory data) internal pure returns (string memory) {