forked from NethermindEth/warp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request NethermindEth#160 from NethermindEth/murcake/optim…
…ize-array-load Murcake/optimize array load
- Loading branch information
Showing
46 changed files
with
477 additions
and
298 deletions.
There are no files selected for viewing
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
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
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
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,10 @@ | ||
pragma solidity >=0.8.6; | ||
|
||
contract WARP { | ||
function callMe() public payable returns (bytes4) { | ||
assembly { | ||
calldatacopy(0x0, 0, 4) | ||
return(0x0, 4) | ||
} | ||
} | ||
} |
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,41 @@ | ||
import os | ||
import tempfile | ||
|
||
import pytest | ||
from cli.encoding import get_evm_calldata | ||
from starkware.starknet.compiler.compile import compile_starknet_files | ||
from starkware.starknet.testing.state import StarknetState | ||
from yul.main import transpile_from_solidity | ||
from yul.starknet_utils import deploy_contract, invoke_method | ||
from yul.utils import cairoize_bytes | ||
|
||
from warp.logging.generateMarkdown import steps_in_function | ||
|
||
warp_root = os.path.abspath(os.path.join(__file__, "../../..")) | ||
test_dir = __file__ | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_calldatacopy(): | ||
sol_file = test_dir[:-8] + ".sol" | ||
program_info = transpile_from_solidity(sol_file, "WARP") | ||
tmp = tempfile.NamedTemporaryFile(mode="w", suffix=".cairo", delete=False) | ||
tmp.write(program_info["cairo_code"]) | ||
tmp.close() | ||
cairo_path = f"{warp_root}/warp/cairo-src" | ||
contract_definition = compile_starknet_files( | ||
[tmp.name], debug_info=True, cairo_path=[cairo_path] | ||
) | ||
|
||
starknet = await StarknetState.empty() | ||
contract_address = await deploy_contract( | ||
starknet, program_info, contract_definition | ||
) | ||
|
||
evm_calldata = get_evm_calldata(program_info["sol_abi"], "callMe", []) | ||
[first_four_bytes], _ = cairoize_bytes(evm_calldata[:4]) | ||
res = await invoke_method(starknet, program_info, contract_address, "callMe") | ||
steps_in_function(sol_file, "callMe", res, "calldatacopy_test") | ||
assert res.retdata == [4, 1, first_four_bytes] | ||
|
||
os.unlink(tmp.name) |
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,26 @@ | ||
%builtins output range_check bitwise | ||
|
||
from evm.array import array_create_from_memory | ||
from evm.memory import mload, mstore | ||
from starkware.cairo.common.cairo_builtins import BitwiseBuiltin | ||
from starkware.cairo.common.default_dict import default_dict_finalize, default_dict_new | ||
from starkware.cairo.common.serialize import serialize_word | ||
from starkware.cairo.common.uint256 import Uint256 | ||
|
||
func main{output_ptr : felt*, range_check_ptr, bitwise_ptr : BitwiseBuiltin*}(): | ||
alloc_locals | ||
let (memory_dict) = default_dict_new(0) | ||
let dict_start = memory_dict | ||
with memory_dict: | ||
# we don't do assertions here, since if one fails we can't observe others | ||
mstore(0, Uint256(5000, 0xabcd * 256 ** 14 + 0x123456)) | ||
mstore(32, Uint256(0xdeadbeef, 0xcafebabe)) | ||
let (array) = array_create_from_memory(0, 64) | ||
serialize_word(array[0]) | ||
serialize_word(array[1]) | ||
serialize_word(array[2]) | ||
serialize_word(array[3]) | ||
end | ||
default_dict_finalize(dict_start, memory_dict, 0) | ||
return () | ||
end |
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,6 @@ | ||
Program output: | ||
228362408135220253930399759055430235222 | ||
5000 | ||
3405691582 | ||
3735928559 | ||
|
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,29 @@ | ||
%builtins output range_check bitwise | ||
|
||
from evm.array import array_create_from_memory | ||
from evm.memory import mload, mstore | ||
from starkware.cairo.common.cairo_builtins import BitwiseBuiltin | ||
from starkware.cairo.common.default_dict import default_dict_finalize, default_dict_new | ||
from starkware.cairo.common.serialize import serialize_word | ||
from starkware.cairo.common.uint256 import Uint256 | ||
|
||
func main{output_ptr : felt*, range_check_ptr, bitwise_ptr : BitwiseBuiltin*}(): | ||
alloc_locals | ||
let (memory_dict) = default_dict_new(0) | ||
let dict_start = memory_dict | ||
with memory_dict: | ||
# we don't do assertions here, since if one fails we can't observe others | ||
mstore(4, Uint256(5000, 0xabcd * 256 ** 14 + 0x123456)) | ||
mstore(36, Uint256(0xdeadbeef, 0xcafebabe)) | ||
let (array) = array_create_from_memory(4, 64) | ||
serialize_word(array[0]) | ||
serialize_word(array[1]) | ||
serialize_word(array[2]) | ||
serialize_word(array[3]) | ||
let (array) = array_create_from_memory(36, 32) | ||
serialize_word(array[0]) | ||
serialize_word(array[1]) | ||
end | ||
default_dict_finalize(dict_start, memory_dict, 0) | ||
return () | ||
end |
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,8 @@ | ||
Program output: | ||
228362408135220253930399759055430235222 | ||
5000 | ||
3405691582 | ||
3735928559 | ||
3405691582 | ||
3735928559 | ||
|
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
Oops, something went wrong.