|
| 1 | +# Uniswap-V2 YUL TEST |
| 2 | + |
| 3 | +## Compile Uniswap Solidity Contracts into YUL files using solc |
| 4 | + |
| 5 | +For the convenience of testing, the `mint` interface was added to the original uniswap-v2-erc20 interface. |
| 6 | +We could use solc to compile solidity into YUL IR. |
| 7 | + |
| 8 | +``` |
| 9 | +solc --ir UniswapV2ERC20.sol > UniswapV2ERC20.yul |
| 10 | +``` |
| 11 | + |
| 12 | +However, the compiled ir has deployment code. This test does not contain runtime test, so you need to remove the deployment code manually. |
| 13 | +It could be done by extract `object "UniswapV2ERC20_431_deployed"` into a single YUL file. |
| 14 | + |
| 15 | +A preprocessed `UniswapV2ERC20.yul` is included in the folder, you could use the file directly. |
| 16 | + |
| 17 | +## Compile YUL IR into WASM through SOLL toolchain |
| 18 | + |
| 19 | +Prepare SOLL toolchain, and we could compile `UniswapV2ERC20.yul` into `UniswapV2ERC20.wasm`. You can use the Makefile in this folder. |
| 20 | + |
| 21 | +``` |
| 22 | +make |
| 23 | +``` |
| 24 | + |
| 25 | +## Compile libsoll_runtime_test |
| 26 | + |
| 27 | +Required files: |
| 28 | + |
| 29 | ++ `libssvm-evmc.so` a evmc wrapper for ssvm |
| 30 | ++ `libsoll_runtime_test.so` a middle layer between python and `ssvm-evmc` |
| 31 | ++ `evmc.py` a python ctype wrapper for `libsoll_runtime_test.so` |
| 32 | + |
| 33 | +Please clone and build [ssvm-evmc](https://github.com/second-state/ssvm-evmc). |
| 34 | +``` |
| 35 | +$ git clone [email protected]:second-state/ssvm-evmc.git |
| 36 | +$ cd ssvm-evmc |
| 37 | +$ git checkout master |
| 38 | +``` |
| 39 | + |
| 40 | +Build `libsoll_runtime_test.so` and `libssvm-evmc.so `. |
| 41 | +``` |
| 42 | +$ cd <path/to/ssvm-evmc> |
| 43 | +$ mkdir -p build && cd build |
| 44 | +``` |
| 45 | + |
| 46 | +Copy the libraries to this folder. |
| 47 | +``` |
| 48 | +$ cd <path/to/erc20-rs-ssvm-test> |
| 49 | +$ cp <path/to/ssvm-evmc>/build/tools/soll-runtime-test/libsoll_runtime_test.so . |
| 50 | +$ cp <path/to/ssvm-evmc>/build/tools/tools/ssvm-evmc/libssvm-evmc.so . |
| 51 | +``` |
| 52 | + |
| 53 | + |
| 54 | +## Testing UniswapV2ERC20.wasm |
| 55 | + |
| 56 | +After compiling `UniswapV2ERC20.wasm` and soll-runtime-test. Make sure that the result files are copied into this directory: |
| 57 | + |
| 58 | ++ `UniswapV2ERC20.wasm` |
| 59 | ++ `libsoll_runtime_test.so` |
| 60 | ++ `libssvm-evmc.so ` |
| 61 | + |
| 62 | +Then, execute `python uniswap-test.py`. |
| 63 | + |
| 64 | +``` |
| 65 | +name |
| 66 | +status: EVMC_SUCCESS |
| 67 | +return: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\nUniswap V2\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' |
| 68 | +===================================== |
| 69 | +symbol |
| 70 | +status: EVMC_SUCCESS |
| 71 | +return: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x06UNI-V2\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' |
| 72 | +===================================== |
| 73 | +decimals |
| 74 | +status: EVMC_SUCCESS |
| 75 | +return: 18 |
| 76 | +===================================== |
| 77 | +total_supply |
| 78 | +status: EVMC_SUCCESS |
| 79 | +return: 0 |
| 80 | +===================================== |
| 81 | +mint_0xDEADBEEF_3 |
| 82 | +status: EVMC_SUCCESS |
| 83 | +return: 1 |
| 84 | +===================================== |
| 85 | +total_supply |
| 86 | +status: EVMC_SUCCESS |
| 87 | +return: 3 |
| 88 | +===================================== |
| 89 | +balance_of_0xDEADBEEF |
| 90 | +status: EVMC_SUCCESS |
| 91 | +return: 3 |
| 92 | +===================================== |
| 93 | +balance_of_0xFACEB00C |
| 94 | +status: EVMC_SUCCESS |
| 95 | +return: 0 |
| 96 | +===================================== |
| 97 | +transfer_0xDEADBEEF_1_to_0xFACEB00C |
| 98 | +status: EVMC_SUCCESS |
| 99 | +return: 1 |
| 100 | +===================================== |
| 101 | +balance_of_0xDEADBEEF |
| 102 | +status: EVMC_SUCCESS |
| 103 | +return: 2 |
| 104 | +===================================== |
| 105 | +balance_of_0xFACEB00C |
| 106 | +status: EVMC_SUCCESS |
| 107 | +return: 1 |
| 108 | +===================================== |
| 109 | +total_supply |
| 110 | +status: EVMC_SUCCESS |
| 111 | +return: 3 |
| 112 | +===================================== |
| 113 | +transfer_0xDEADBEEF_5_to_0xFACEB00C |
| 114 | +status: EVMC_REVERT |
| 115 | +return: 1 |
| 116 | +===================================== |
| 117 | +``` |
0 commit comments