Spaces:
Sleeping
Sleeping
File size: 276,566 Bytes
cf983b8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 | SpecHash,SpecIndex,Type,Name,StartLine,EndLine,MethodsInRule,RuleContent,RelatedFunctions,FunctionBodies,FilePath,Project,ContractCode,StateVarAssignment,RuleContentNL,Funcitonality
1adad19c8ea189e760a3480b59dc3d24,142 | 143,rule,integrityOfExecuteEmergencyAction,235,246,areAllReservesBacked | executeEmergencyAction,"// rule integrityOfExecuteEmergencyAction(bool rand) {
// require _disableBorrowingCalled() == false;
// aggregator.initFlags(rand);
// bool allReservesBacked = areAllReservesBacked();
// executeEmergencyAction();
// bool disableBorrowingCalled = _disableBorrowingCalled();
// assert !allReservesBacked => disableBorrowingCalled;
// assert allReservesBacked => !disableBorrowingCalled;
// }
","areAllReservesBacked (Lines 87-97), | executeEmergencyAction (Lines 70-92), "," function areAllReservesBacked() external view returns (bool) {
if (_assets.length == 0) {
return true;
}
(bool areReservesBacked, ) = _proofOfReserveAggregator.areAllReservesBacked(
_assets
);
return areReservesBacked;
}
| function executeEmergencyAction() external override {
(
bool areReservesBacked,
bool[] memory unbackedAssetsFlags
) = _proofOfReserveAggregator.areAllReservesBacked(_assets);
if (!areReservesBacked) {
_disableBorrowing();
uint256 assetsLength = _assets.length;
for (uint256 i = 0; i < assetsLength; ++i) {
if (unbackedAssetsFlags[i]) {
// freeze reserve
_configurator.freezeReserve(_assets[i]);
emit AssetIsNotBacked(_assets[i]);
}
}
emit EmergencyActionExecuted();
}
}
",./aave_proof_of_reserve/specs/executorV2.spec,aave_proof_of_reserve,,Yes,,"Functionality: The provided code checks if all assets in a portfolio are backed by reserves through a proof of reserve aggregator. If any asset is unbacked, it disables borrowing, freezes the reserves of those specific unbacked assets, and emits events to indicate an emergency action and the assets not backed by reserves."
1a45f8a5d1331c57ccb23e4ab81cf513,144 | 145,rule,integrityOfExecuteEmergencyAction,244,255,areAllReservesBacked | executeEmergencyAction,"// rule integrityOfExecuteEmergencyAction(bool rand) {
// aggregator.initFlags(rand);
// require configurator.freezeWasCalled() == false;
// bool allReservesBacked = areAllReservesBacked();
// executeEmergencyAction();
// bool freezeReserveWasCalled = configurator.freezeWasCalled();
// assert !allReservesBacked => freezeReserveWasCalled;
// assert allReservesBacked => !freezeReserveWasCalled;
// }
","areAllReservesBacked (Lines 87-97), | executeEmergencyAction (Lines 70-92), "," function areAllReservesBacked() external view returns (bool) {
if (_assets.length == 0) {
return true;
}
(bool areReservesBacked, ) = _proofOfReserveAggregator.areAllReservesBacked(
_assets
);
return areReservesBacked;
}
| function executeEmergencyAction() external override {
(
bool areReservesBacked,
bool[] memory unbackedAssetsFlags
) = _proofOfReserveAggregator.areAllReservesBacked(_assets);
if (!areReservesBacked) {
_disableBorrowing();
uint256 assetsLength = _assets.length;
for (uint256 i = 0; i < assetsLength; ++i) {
if (unbackedAssetsFlags[i]) {
// freeze reserve
_configurator.freezeReserve(_assets[i]);
emit AssetIsNotBacked(_assets[i]);
}
}
emit EmergencyActionExecuted();
}
}
",./aave_proof_of_reserve/specs/executorV3.spec,aave_proof_of_reserve,,Yes,,"Functionality: Verify if all reserves are backed by assets, returning a boolean value. In case of unbacked reserves, disable borrowing, freeze unbacked asset reserves, and emit relevant events to indicate assets that are not backed and that an emergency action has been executed."
1f13d0617b40090d6b6dc2a0541c72d8,148 | 149,rule,PoRFeedChange,35,54,enableProofOfReserveFeed | enableProofOfReserveFeedWithBridgeWrapper,"rule PoRFeedChange(address asset, address PoRFeed, address wrapper){
address feedBefore = getProofOfReserveFeedForAsset(asset);
address bridgeWrapperBefore = getBridgeWrapperForAsset(asset);
method f; env e;
call_f_with_params(f, e, asset, PoRFeed, wrapper);
address feedAfter = getProofOfReserveFeedForAsset(asset);
address bridgeWrapperAfter = getBridgeWrapperForAsset(asset);
assert f.selector == enableProofOfReserveFeed(address, address).selector => (feedAfter != 0 && feedAfter == PoRFeed);
assert f.selector == enableProofOfReserveFeedWithBridgeWrapper(address, address, address).selector =>
(feedAfter != 0 && feedAfter == PoRFeed && bridgeWrapperAfter != 0 && bridgeWrapperAfter == wrapper);
assert f.selector == disableProofOfReserveFeed(address).selector => feedAfter == 0 && bridgeWrapperAfter == 0;
assert (f.selector != enableProofOfReserveFeed(address, address).selector &&
f.selector != disableProofOfReserveFeed(address).selector &&
f.selector != enableProofOfReserveFeedWithBridgeWrapper(address, address, address).selector) =>
feedBefore == feedAfter && bridgeWrapperBefore == bridgeWrapperAfter;
}
","enableProofOfReserveFeed (Lines 42-57), | enableProofOfReserveFeedWithBridgeWrapper (Lines 60-79), "," function enableProofOfReserveFeed(address asset, address proofOfReserveFeed)
external
onlyOwner
{
require(asset != address(0), 'INVALID_ASSET');
require(proofOfReserveFeed != address(0), 'INVALID_PROOF_OF_RESERVE_FEED');
require(_proofOfReserveList[asset] == address(0), 'FEED_ALREADY_ENABLED');
_proofOfReserveList[asset] = proofOfReserveFeed;
emit ProofOfReserveFeedStateChanged(
asset,
proofOfReserveFeed,
address(0),
true
);
}
| function enableProofOfReserveFeedWithBridgeWrapper(
address asset,
address proofOfReserveFeed,
address bridgeWrapper
) external onlyOwner {
require(asset != address(0), 'INVALID_ASSET');
require(proofOfReserveFeed != address(0), 'INVALID_PROOF_OF_RESERVE_FEED');
require(bridgeWrapper != address(0), 'INVALID_BRIDGE_WRAPPER');
require(_proofOfReserveList[asset] == address(0), 'FEED_ALREADY_ENABLED');
_proofOfReserveList[asset] = proofOfReserveFeed;
_bridgeWrapperList[asset] = bridgeWrapper;
emit ProofOfReserveFeedStateChanged(
asset,
proofOfReserveFeed,
bridgeWrapper,
true
);
}
",./aave_proof_of_reserve/specs/aggregator.spec,aave_proof_of_reserve,,Yes,,"Functionality: Enable or update the proof of reserve feed for a specified asset, optionally setting a bridge wrapper. Ensure the asset and feed addresses are valid and not already configured. Emit events to log changes in the state of proof of reserve feeds."
6f0a788c11d1de327d863a034e8efbe5,611 | 612,rule,additiveBurn,141,156,balanceOf | burn,"rule additiveBurn(address user1, address user2, uint256 x, uint256 y) {
env e;
uint256 index = gRNVB();
require (user1 != user2 && balanceOf(user1) == balanceOf(user2));
require user1 != currentContract && user2 != currentContract;
burn(e, user1, x, index);
burn(e, user1, y, index);
uint256 balanceScenario1 = balanceOf(user1);
burn(e, user2, x+y, index);
uint256 balanceScenario2 = balanceOf(user2);
assert bounded_error_eq(balanceScenario1, balanceScenario2, 3), ""burn is not additive"";
// assert balanceScenario1 == balanceScenario2, ""burn is not additive"";
}
","balanceOf (Lines 101-112), | burn (Lines 178-245), "," function balanceOf(address account) public view virtual override returns (uint256) {
uint256 accountBalance = super.balanceOf(account);
uint256 stableRate = _userState[account].additionalData;
if (accountBalance == 0) {
return 0;
}
uint256 cumulatedInterest = MathUtils.calculateCompoundedInterest(
stableRate,
_timestamps[account]
);
return accountBalance.rayMul(cumulatedInterest);
}
| function burn(
address from,
uint256 amount
) external virtual override onlyPool returns (uint256, uint256) {
(, uint256 currentBalance, uint256 balanceIncrease) = _calculateBalanceIncrease(from);
uint256 previousSupply = totalSupply();
uint256 nextAvgStableRate = 0;
uint256 nextSupply = 0;
uint256 userStableRate = _userState[from].additionalData;
// Since the total supply and each single user debt accrue separately,
// there might be accumulation errors so that the last borrower repaying
// might actually try to repay more than the available debt supply.
// In this case we simply set the total supply and the avg stable rate to 0
if (previousSupply <= amount) {
_avgStableRate = 0;
_totalSupply = 0;
} else {
nextSupply = _totalSupply = previousSupply - amount;
uint256 firstTerm = uint256(_avgStableRate).rayMul(previousSupply.wadToRay());
uint256 secondTerm = userStableRate.rayMul(amount.wadToRay());
// For the same reason described above, when the last user is repaying it might
// happen that user rate * user balance > avg rate * total supply. In that case,
// we simply set the avg rate to 0
if (secondTerm >= firstTerm) {
nextAvgStableRate = _totalSupply = _avgStableRate = 0;
} else {
nextAvgStableRate = _avgStableRate = (
(firstTerm - secondTerm).rayDiv(nextSupply.wadToRay())
).toUint128();
}
}
if (amount == currentBalance) {
_userState[from].additionalData = 0;
_timestamps[from] = 0;
} else {
//solium-disable-next-line
_timestamps[from] = uint40(block.timestamp);
}
//solium-disable-next-line
_totalSupplyTimestamp = uint40(block.timestamp);
if (balanceIncrease > amount) {
uint256 amountToMint = balanceIncrease - amount;
_mint(from, amountToMint, previousSupply);
emit Transfer(address(0), from, amountToMint);
emit Mint(
from,
from,
amountToMint,
currentBalance,
balanceIncrease,
userStableRate,
nextAvgStableRate,
nextSupply
);
} else {
uint256 amountToBurn = amount - balanceIncrease;
_burn(from, amountToBurn, previousSupply);
emit Transfer(from, address(0), amountToBurn);
emit Burn(from, amountToBurn, currentBalance, balanceIncrease, nextAvgStableRate, nextSupply);
}
return (nextSupply, nextAvgStableRate);
}
",./aave_v3/specs/VariableDebtToken.spec,aave_v3,,Yes,,"Functionality: Adjust a user's balance and the total supply of a financial instrument by calculating interest accrued based on a stable rate, and either mint or burn tokens to reflect changes resulting from a transaction, while also updating average stable rates and timestamps accordingly."
5ef46523db01c063e88661dc1f6ac3eb,412,rule,additiveTransfer,178,201,balanceOf,"rule additiveTransfer(address from1, address from2, address to1, address to2, uint256 x, uint256 y)
{
env e1;
env e2;
uint256 indexRay = gRNI();
require (from1 != from2 && to1 != to2 && from1 != to2 && from2 != to1 &&
(from1 == to1 <=> from2 == to2) &&
balanceOf(from1) == balanceOf(from2) && balanceOf(to1) == balanceOf(to2));
require e1.msg.sender == from1;
require e2.msg.sender == from2;
transfer(e1, to1, x);
transfer(e1, to1, y);
uint256 balanceFromScenario1 = balanceOf(from1);
uint256 balanceToScenario1 = balanceOf(to1);
transfer(e2, to2, x+y);
uint256 balanceFromScenario2 = balanceOf(from2);
uint256 balanceToScenario2 = balanceOf(to2);
assert bounded_error_eq(balanceFromScenario1, balanceFromScenario2, 3) &&
bounded_error_eq(balanceToScenario1, balanceToScenario2, 3), ""transfer is not additive"";
}
","balanceOf (Lines 101-112), "," function balanceOf(address account) public view virtual override returns (uint256) {
uint256 accountBalance = super.balanceOf(account);
uint256 stableRate = _userState[account].additionalData;
if (accountBalance == 0) {
return 0;
}
uint256 cumulatedInterest = MathUtils.calculateCompoundedInterest(
stableRate,
_timestamps[account]
);
return accountBalance.rayMul(cumulatedInterest);
}
",./aave_v3/specs/AToken.spec,aave_v3,,Yes,,"Functionality: Calculate and return the adjusted balance of a given account by applying the compounded interest rate to the account's existing balance, incorporating a stable rate and time factor, with the calculation ceasing and returning zero if the account balance is initially zero."
a17ca2e8fe7297047b2c0484f1988b46,532,rule,getReserveNormalizedVariableDebtCheck,197,209,supply,"rule getReserveNormalizedVariableDebtCheck()
{
env e1;
calldataarg args;
calldataarg args2;
address asset; uint256 amount; address onBehalfOf; uint16 referralCode;
require asset != _aToken;
uint256 oldIndex = getReserveNormalizedVariableDebt(e1, args);
uint256 totalDebtBefore = getCurrScaledVariableDebt(asset);
supply(e1, asset, amount, onBehalfOf, referralCode);
uint256 newIndex = getReserveNormalizedVariableDebt(e1, args);
assert totalDebtBefore != 0 => newIndex >= oldIndex;
}
","supply (Lines 143-160), "," function supply(
address asset,
uint256 amount,
address onBehalfOf,
uint16 referralCode
) public virtual override {
SupplyLogic.executeSupply(
_reserves,
_reservesList,
_usersConfig[onBehalfOf],
DataTypes.ExecuteSupplyParams({
asset: asset,
amount: amount,
onBehalfOf: onBehalfOf,
referralCode: referralCode
})
);
}
",./aave_v3/specs/pool.spec,aave_v3,,Yes,,"Functionality: Execute a supply operation on behalf of a specified user by calling the SupplyLogic's `executeSupply` method with the specified asset, amount, beneficiary address, and referral code using the user's configuration and reserves data."
efa0872e2bd5bc7b8586d20edeed3133,403 | 404,rule,integrityMint,101,119,mint | balanceOf,"rule integrityMint(address a, address b, uint256 x)
{
env e;
uint256 indexRay = gRNI();
uint256 underlyingBalanceBefore = balanceOf(a);
uint256 atokenBlanceBefore = scaledBalanceOf(e, a);
uint256 totalATokenSupplyBefore = scaledTotalSupply(e);
mint(e,b,a,x,indexRay);
uint256 underlyingBalanceAfter = balanceOf(a);
uint256 atokenBlanceAfter = scaledBalanceOf(e, a);
uint256 totalATokenSupplyAfter = scaledTotalSupply(e);
assert atokenBlanceAfter - atokenBlanceBefore == totalATokenSupplyAfter - totalATokenSupplyBefore;
assert totalATokenSupplyAfter > totalATokenSupplyBefore;
assert bounded_error_eq(underlyingBalanceAfter, underlyingBalanceBefore+x, 1);
}
","mint (Lines 124-175), | balanceOf (Lines 101-112), "," function mint(
address user,
address onBehalfOf,
uint256 amount,
uint256 rate
) external virtual override onlyPool returns (bool, uint256, uint256) {
MintLocalVars memory vars;
if (user != onBehalfOf) {
_decreaseBorrowAllowance(onBehalfOf, user, amount);
}
(, uint256 currentBalance, uint256 balanceIncrease) = _calculateBalanceIncrease(onBehalfOf);
vars.previousSupply = totalSupply();
vars.currentAvgStableRate = _avgStableRate;
vars.nextSupply = _totalSupply = vars.previousSupply + amount;
vars.amountInRay = amount.wadToRay();
vars.currentStableRate = _userState[onBehalfOf].additionalData;
vars.nextStableRate = (vars.currentStableRate.rayMul(currentBalance.wadToRay()) +
vars.amountInRay.rayMul(rate)).rayDiv((currentBalance + amount).wadToRay());
_userState[onBehalfOf].additionalData = vars.nextStableRate.toUint128();
//solium-disable-next-line
_totalSupplyTimestamp = _timestamps[onBehalfOf] = uint40(block.timestamp);
// Calculates the updated average stable rate
vars.currentAvgStableRate = _avgStableRate = (
(vars.currentAvgStableRate.rayMul(vars.previousSupply.wadToRay()) +
rate.rayMul(vars.amountInRay)).rayDiv(vars.nextSupply.wadToRay())
).toUint128();
uint256 amountToMint = amount + balanceIncrease;
_mint(onBehalfOf, amountToMint, vars.previousSupply);
emit Transfer(address(0), onBehalfOf, amountToMint);
emit Mint(
user,
onBehalfOf,
amountToMint,
currentBalance,
balanceIncrease,
vars.nextStableRate,
vars.currentAvgStableRate,
vars.nextSupply
);
return (currentBalance == 0, vars.nextSupply, vars.currentAvgStableRate);
}
| function balanceOf(address account) public view virtual override returns (uint256) {
uint256 accountBalance = super.balanceOf(account);
uint256 stableRate = _userState[account].additionalData;
if (accountBalance == 0) {
return 0;
}
uint256 cumulatedInterest = MathUtils.calculateCompoundedInterest(
stableRate,
_timestamps[account]
);
return accountBalance.rayMul(cumulatedInterest);
}
",./aave_v3/specs/AToken.spec,aave_v3,,Yes,,"Functionality: The provided code defines a function for minting new tokens on behalf of a user, adjusting their balance based on an updated average stable rate and compounded interest, and emits events reflecting these changes. It also includes a method to calculate a user's current balance, factoring in accrued interest."
d006d522c332ba3ba477c7e5c892b16a,568,rule,setLiquidationProtocolFeeIntegrity,151,154,setLiquidationProtocolFee,"rule setLiquidationProtocolFeeIntegrity(uint256 liquidationProtocolFee) {
setLiquidationProtocolFee(liquidationProtocolFee);
assert getLiquidationProtocolFee() == liquidationProtocolFee;
}
","setLiquidationProtocolFee (Lines 311-321), "," function setLiquidationProtocolFee(
address asset,
uint256 newFee
) external override onlyRiskOrPoolAdmins {
require(newFee <= PercentageMath.PERCENTAGE_FACTOR, Errors.INVALID_LIQUIDATION_PROTOCOL_FEE);
DataTypes.ReserveConfigurationMap memory currentConfig = _pool.getConfiguration(asset);
uint256 oldFee = currentConfig.getLiquidationProtocolFee();
currentConfig.setLiquidationProtocolFee(newFee);
_pool.setConfiguration(asset, currentConfig);
emit LiquidationProtocolFeeChanged(asset, oldFee, newFee);
}
",./aave_v3/specs/ReserveConfiguration.spec,aave_v3,,Yes,,"Functionality: Update the liquidation protocol fee for a specified asset to a new value, ensuring it does not exceed a predefined maximum percentage. The function validates the new fee, updates the configuration in the pool, and emits an event documenting the change."
de9b73e2d0acb6c986c9cda6f3cedfea,490 | 491,rule,setBorrowing,20,24,setBorrowing | isBorrowing,"rule setBorrowing(uint256 reserveIndex, bool borrowing)
{
setBorrowing(reserveIndex, borrowing);
assert isBorrowing(reserveIndex) == borrowing, ""unexpected result"";
}
","setBorrowing (Lines 27-41), | isBorrowing (Lines 87-95), "," function setBorrowing(
DataTypes.UserConfigurationMap storage self,
uint256 reserveIndex,
bool borrowing
) internal {
unchecked {
require(reserveIndex < ReserveConfiguration.MAX_RESERVES_COUNT, Errors.INVALID_RESERVE_INDEX);
uint256 bit = 1 << (reserveIndex << 1);
if (borrowing) {
self.data |= bit;
} else {
self.data &= ~bit;
}
}
}
| function isBorrowing(
DataTypes.UserConfigurationMap memory self,
uint256 reserveIndex
) internal pure returns (bool) {
unchecked {
require(reserveIndex < ReserveConfiguration.MAX_RESERVES_COUNT, Errors.INVALID_RESERVE_INDEX);
return (self.data >> (reserveIndex << 1)) & 1 != 0;
}
}
",./aave_v3/specs/UserConfiguration.spec,aave_v3,,Yes,,"Functionality: Enable or disable a user's borrowing status for a specific reserve index within a decentralized finance protocol. It verifies the reserve index's validity, modifies the user's configuration map to reflect the borrowing status, and checks if a user is currently borrowing from a specific reserve."
8aa368715d4def33d5d14e9a16af7032,577 | 578,rule,integrityBurn,138,147,balanceOf | burn,"rule integrityBurn(address a, uint256 x) {
env e;
require getIncentivesController(e) == 0;
uint256 index;
uint256 balancebefore = balanceOf(e, a);
burn(e,a,x);
uint256 balanceAfter = balanceOf(e, a);
assert balanceAfter == balancebefore - x;
}
","balanceOf (Lines 101-112), | burn (Lines 178-245), "," function balanceOf(address account) public view virtual override returns (uint256) {
uint256 accountBalance = super.balanceOf(account);
uint256 stableRate = _userState[account].additionalData;
if (accountBalance == 0) {
return 0;
}
uint256 cumulatedInterest = MathUtils.calculateCompoundedInterest(
stableRate,
_timestamps[account]
);
return accountBalance.rayMul(cumulatedInterest);
}
| function burn(
address from,
uint256 amount
) external virtual override onlyPool returns (uint256, uint256) {
(, uint256 currentBalance, uint256 balanceIncrease) = _calculateBalanceIncrease(from);
uint256 previousSupply = totalSupply();
uint256 nextAvgStableRate = 0;
uint256 nextSupply = 0;
uint256 userStableRate = _userState[from].additionalData;
// Since the total supply and each single user debt accrue separately,
// there might be accumulation errors so that the last borrower repaying
// might actually try to repay more than the available debt supply.
// In this case we simply set the total supply and the avg stable rate to 0
if (previousSupply <= amount) {
_avgStableRate = 0;
_totalSupply = 0;
} else {
nextSupply = _totalSupply = previousSupply - amount;
uint256 firstTerm = uint256(_avgStableRate).rayMul(previousSupply.wadToRay());
uint256 secondTerm = userStableRate.rayMul(amount.wadToRay());
// For the same reason described above, when the last user is repaying it might
// happen that user rate * user balance > avg rate * total supply. In that case,
// we simply set the avg rate to 0
if (secondTerm >= firstTerm) {
nextAvgStableRate = _totalSupply = _avgStableRate = 0;
} else {
nextAvgStableRate = _avgStableRate = (
(firstTerm - secondTerm).rayDiv(nextSupply.wadToRay())
).toUint128();
}
}
if (amount == currentBalance) {
_userState[from].additionalData = 0;
_timestamps[from] = 0;
} else {
//solium-disable-next-line
_timestamps[from] = uint40(block.timestamp);
}
//solium-disable-next-line
_totalSupplyTimestamp = uint40(block.timestamp);
if (balanceIncrease > amount) {
uint256 amountToMint = balanceIncrease - amount;
_mint(from, amountToMint, previousSupply);
emit Transfer(address(0), from, amountToMint);
emit Mint(
from,
from,
amountToMint,
currentBalance,
balanceIncrease,
userStableRate,
nextAvgStableRate,
nextSupply
);
} else {
uint256 amountToBurn = amount - balanceIncrease;
_burn(from, amountToBurn, previousSupply);
emit Transfer(from, address(0), amountToBurn);
emit Burn(from, amountToBurn, currentBalance, balanceIncrease, nextAvgStableRate, nextSupply);
}
return (nextSupply, nextAvgStableRate);
}
",./aave_v3/specs/StableDebtToken.spec,aave_v3,,Yes,,"Functionality: Adjust user and total supply balances on a stablecoin contract, using time-dependent interest calculations for accurate accounting. Account for potential accumulation errors by adjusting the average stable rate as necessary, and handle burns or mints based on the comparison of user balance increases to requested burn amounts."
cb81952394ea33aa5b1e095725df8d51,584 | 585,rule,additiveBurn,187,198,balanceOf | burn,"rule additiveBurn(address a, uint256 x, uint256 y) {
env e;
storage initialStorage = lastStorage;
burn(e, a, x);
burn(e, a, y);
uint256 balanceScenario1 = balanceOf(e, a);
uint256 t = x + y;
burn(e, a, t) at initialStorage;
uint256 balanceScenario2 = balanceOf(e, a);
assert balanceScenario1 == balanceScenario2, ""burn is not additive"";
}
","balanceOf (Lines 101-112), | burn (Lines 178-245), "," function balanceOf(address account) public view virtual override returns (uint256) {
uint256 accountBalance = super.balanceOf(account);
uint256 stableRate = _userState[account].additionalData;
if (accountBalance == 0) {
return 0;
}
uint256 cumulatedInterest = MathUtils.calculateCompoundedInterest(
stableRate,
_timestamps[account]
);
return accountBalance.rayMul(cumulatedInterest);
}
| function burn(
address from,
uint256 amount
) external virtual override onlyPool returns (uint256, uint256) {
(, uint256 currentBalance, uint256 balanceIncrease) = _calculateBalanceIncrease(from);
uint256 previousSupply = totalSupply();
uint256 nextAvgStableRate = 0;
uint256 nextSupply = 0;
uint256 userStableRate = _userState[from].additionalData;
// Since the total supply and each single user debt accrue separately,
// there might be accumulation errors so that the last borrower repaying
// might actually try to repay more than the available debt supply.
// In this case we simply set the total supply and the avg stable rate to 0
if (previousSupply <= amount) {
_avgStableRate = 0;
_totalSupply = 0;
} else {
nextSupply = _totalSupply = previousSupply - amount;
uint256 firstTerm = uint256(_avgStableRate).rayMul(previousSupply.wadToRay());
uint256 secondTerm = userStableRate.rayMul(amount.wadToRay());
// For the same reason described above, when the last user is repaying it might
// happen that user rate * user balance > avg rate * total supply. In that case,
// we simply set the avg rate to 0
if (secondTerm >= firstTerm) {
nextAvgStableRate = _totalSupply = _avgStableRate = 0;
} else {
nextAvgStableRate = _avgStableRate = (
(firstTerm - secondTerm).rayDiv(nextSupply.wadToRay())
).toUint128();
}
}
if (amount == currentBalance) {
_userState[from].additionalData = 0;
_timestamps[from] = 0;
} else {
//solium-disable-next-line
_timestamps[from] = uint40(block.timestamp);
}
//solium-disable-next-line
_totalSupplyTimestamp = uint40(block.timestamp);
if (balanceIncrease > amount) {
uint256 amountToMint = balanceIncrease - amount;
_mint(from, amountToMint, previousSupply);
emit Transfer(address(0), from, amountToMint);
emit Mint(
from,
from,
amountToMint,
currentBalance,
balanceIncrease,
userStableRate,
nextAvgStableRate,
nextSupply
);
} else {
uint256 amountToBurn = amount - balanceIncrease;
_burn(from, amountToBurn, previousSupply);
emit Transfer(from, address(0), amountToBurn);
emit Burn(from, amountToBurn, currentBalance, balanceIncrease, nextAvgStableRate, nextSupply);
}
return (nextSupply, nextAvgStableRate);
}
",./aave_v3/specs/StableDebtToken.spec,aave_v3,,Yes,,"Functionality: Adjust a user's balance and update the average stable rate and total supply in a decentralized finance protocol, handling balance increase due to interest, and minting or burning tokens accordingly while ensuring the last borrower repaying doesn't repay more than the available debt supply."
de9b73e2d0acb6c986c9cda6f3cedfea,490 | 491,rule,setBorrowing,20,24,setBorrowing | isBorrowing,"rule setBorrowing(uint256 reserveIndex, bool borrowing)
{
setBorrowing(reserveIndex, borrowing);
assert isBorrowing(reserveIndex) == borrowing, ""unexpected result"";
}
","setBorrowing (Lines 27-41), | isBorrowing (Lines 87-95), "," function setBorrowing(
DataTypes.UserConfigurationMap storage self,
uint256 reserveIndex,
bool borrowing
) internal {
unchecked {
require(reserveIndex < ReserveConfiguration.MAX_RESERVES_COUNT, Errors.INVALID_RESERVE_INDEX);
uint256 bit = 1 << (reserveIndex << 1);
if (borrowing) {
self.data |= bit;
} else {
self.data &= ~bit;
}
}
}
| function isBorrowing(
DataTypes.UserConfigurationMap memory self,
uint256 reserveIndex
) internal pure returns (bool) {
unchecked {
require(reserveIndex < ReserveConfiguration.MAX_RESERVES_COUNT, Errors.INVALID_RESERVE_INDEX);
return (self.data >> (reserveIndex << 1)) & 1 != 0;
}
}
",./aave_v3/specs/UserConfiguration.spec,aave_v3,,Yes,,"Functionality: Manage and check user borrowing status for specific reserves in a financial protocol. ""setBorrowing"" updates a user's borrowing status for a given reserve index, and ""isBorrowing"" checks if a user is currently borrowing from a specified reserve."
568f1c053d910601ac7880d98abeb0b3,510,rule,integrityOfisUsingAsCollateralOne,85,89,isUsingAsCollateral,"// rule integrityOfisUsingAsCollateralOne(uint256 reserveIndex, uint256 reserveIndexOther){
// bool reserveCollateral = isUsingAsCollateral(reserveIndex);
// bool reserveCollateralOther = isUsingAsCollateral(reserveIndexOther);
// assert reserveCollateral && isUsingAsCollateralOne() => !reserveCollateralOther || reserveIndexOther == reserveIndex;
// }
","isUsingAsCollateral (Lines 103-111), "," function isUsingAsCollateral(
DataTypes.UserConfigurationMap memory self,
uint256 reserveIndex
) internal pure returns (bool) {
unchecked {
require(reserveIndex < ReserveConfiguration.MAX_RESERVES_COUNT, Errors.INVALID_RESERVE_INDEX);
return (self.data >> ((reserveIndex << 1) + 1)) & 1 != 0;
}
}
",./aave_v3/specs/UserConfiguration.spec,aave_v3,,Yes,,Functionality: Check if a specific reserve is being used as collateral by a user within a decentralized finance platform. This is done by shifting the user's configuration data to extract and evaluate a flag indicating collateral usage at the specified reserve index.
128f7992885aeaf61914ff90925752e5,765,rule,cantGoFromNoAuthorizationToCompletedInOneStepUnlessRoleIsLegacy,290,294,authorizeSignerWithSignature,"rule cantGoFromNoAuthorizationToCompletedInOneStepUnlessRoleIsLegacy(method f) filtered { f ->
!f.isView
// the authorizeSignerWithSignature allows the signer to provide a signature to the account, so we exclude this option
&& f.selector != authorizeSignerWithSignature(address,bytes32,uint8,bytes32,bytes32).selector
} {
","authorizeSignerWithSignature (Lines 407-417), "," function authorizeSignerWithSignature(address signer, bytes32 role, uint8 v, bytes32 r, bytes32 s)
public
{
authorizeAddressWithRole(signer, role, v, r, s);
signerAuthorizations[msg.sender][role][signer] = SignerAuthorization({
started: true,
completed: true
});
emit SignerAuthorized(msg.sender, signer, role);
}
",./celo_governance/specs/accounts.spec,celo_governance,,Yes,,"Functionality: Use `authorizeSignerWithSignature` to authorize a signer for a specific role using EIP-712 signature, by internally calling `authorizeAddressWithRole` with the signer's details and marking the authorization process as both started and completed in the contract's state, then emit a `SignerAuthorized` event."
ea4ba5e30a4c062b8d537ef09b36af6b,766,rule,cantMakeASignerForNonLegacyRoleWithoutApprovalOfSigner,309,313,authorizeSignerWithSignature,"rule cantMakeASignerForNonLegacyRoleWithoutApprovalOfSigner(method f) filtered { f ->
!f.isView
// the authorizeSignerWithSignature allows the signer to provide a signature to the account, so we exclude this option
&& f.selector != authorizeSignerWithSignature(address,bytes32,uint8,bytes32,bytes32).selector
} {
","authorizeSignerWithSignature (Lines 407-417), "," function authorizeSignerWithSignature(address signer, bytes32 role, uint8 v, bytes32 r, bytes32 s)
public
{
authorizeAddressWithRole(signer, role, v, r, s);
signerAuthorizations[msg.sender][role][signer] = SignerAuthorization({
started: true,
completed: true
});
emit SignerAuthorized(msg.sender, signer, role);
}
",./celo_governance/specs/accounts.spec,celo_governance,,Yes,,"Functionality: Authorize a specified signer with a particular role after verifying the sender's signature, and mark the authorization process as both started and completed within the contract's storage. Then, emit an event to record the authorization of the signer for the specified role."
f4502f38f9ab63a1c3e3807bdfab9353,836 | 838 | 840,rule,no_double_vote_referendum_all_but_vote,164,164,getUpvotedProposal | upvote | getUpvoteRecord,"rule no_double_vote_referendum_all_but_vote(method f, address account, uint256 deqIndex) filtered { f -> !f.isView } {
// the invariant is upvoteInv, defined here
}
definition upvoteInv(uint p, uint w) returns bool
= (p != 0 && w > 0) || (p == 0 && w == 0)
;
rule no_double_upvote(uint256 p, address u) {
uint256 _upvotes = getUpvotes(p);
uint256 _usersUpvotedProposal = getUpvotedProposal(u);
env e;
require e.msg.sender == u && u != 0; // note that the sender is the signer here
require accounts.voteSignerToAccount(u) == u;
uint256 lesser;
uint256 greater;
upvote(e, p, lesser, greater);
uint256 upvotes_ = getUpvotes(p);
uint voteRecordP;
uint voteRecordW;
voteRecordP, voteRecordW = getUpvoteRecord(u);
require upvoteInv(voteRecordP, voteRecordW);
assert _usersUpvotedProposal == p => upvotes_ <= _upvotes,
""Upvotes increased from ${_upvotes} to ${upvotes_} even though upvoted by user $u who already upvoted $p"";
}
","getUpvotedProposal (Lines 43-48), | upvote (Lines 530-558), | getUpvoteRecord (Lines 1161-1164), "," function getUpvotedProposal(address account) public view returns (uint256) {
uint256 proposalId;
uint256 weight;
(proposalId, weight) = this.getUpvoteRecord(account);
return proposalId;
}
| function upvote(uint256 proposalId, uint256 lesser, uint256 greater)
external
nonReentrant
returns (bool)
{
dequeueProposalsIfReady();
// If acting on an expired proposal, expire the proposal and take no action.
if (removeIfQueuedAndExpired(proposalId)) {
return false;
}
address account = getAccounts().voteSignerToAccount(msg.sender);
Voter storage voter = voters[account];
removeIfQueuedAndExpired(voter.upvote.proposalId);
// We can upvote a proposal in the queue if we're not already upvoting a proposal in the queue.
uint256 weight = getLockedGold().getAccountTotalLockedGold(account);
require(weight > 0, ""cannot upvote without locking gold"");
require(queue.contains(proposalId), ""cannot upvote a proposal not in the queue"");
require(
voter.upvote.proposalId == 0 || !queue.contains(voter.upvote.proposalId),
""cannot upvote more than one queued proposal""
);
uint256 upvotes = queue.getValue(proposalId).add(weight);
queue.update(proposalId, upvotes, lesser, greater);
voter.upvote = UpvoteRecord(proposalId, weight);
emit ProposalUpvoted(proposalId, account, weight);
return true;
}
| function getUpvoteRecord(address account) external view returns (uint256, uint256) {
UpvoteRecord memory upvoteRecord = voters[account].upvote;
return (upvoteRecord.proposalId, upvoteRecord.weight);
}
",./celo_governance/specs/governance.spec,celo_governance,,Yes,,"Functionality: Manage upvotes for proposals within a governance framework, allowing users to upvote proposals in a queue by locking a certain amount of gold. It prevents upvoting multiple queued proposals simultaneously and ensures only active, non-expired proposals with sufficient locked gold can be upvoted, reflecting each vote's weight accurately."
e438d9fd1e89cf34c68ae2275f73ae7a,822 | 824 | 826,rule,no_referendum_votes_unless_approved,118,118,getUpvotedProposal | upvote | getUpvoteRecord,"rule no_referendum_votes_unless_approved(method f, uint256 p) filtered { f -> !f.isView } {
// the invariant is upvoteInv, defined here
}
definition upvoteInv(uint p, uint w) returns bool
= (p != 0 && w > 0) || (p == 0 && w == 0)
;
rule no_double_upvote(uint256 p, address u) {
uint256 _upvotes = getUpvotes(p);
uint256 _usersUpvotedProposal = getUpvotedProposal(u);
env e;
require e.msg.sender == u && u != 0; // note that the sender is the signer here
require accounts.voteSignerToAccount(u) == u;
uint256 lesser;
uint256 greater;
upvote(e, p, lesser, greater);
uint256 upvotes_ = getUpvotes(p);
uint voteRecordP;
uint voteRecordW;
voteRecordP, voteRecordW = getUpvoteRecord(u);
require upvoteInv(voteRecordP, voteRecordW);
assert _usersUpvotedProposal == p => upvotes_ <= _upvotes,
""Upvotes increased from ${_upvotes} to ${upvotes_} even though upvoted by user $u who already upvoted $p"";
}
","getUpvotedProposal (Lines 43-48), | upvote (Lines 530-558), | getUpvoteRecord (Lines 1161-1164), "," function getUpvotedProposal(address account) public view returns (uint256) {
uint256 proposalId;
uint256 weight;
(proposalId, weight) = this.getUpvoteRecord(account);
return proposalId;
}
| function upvote(uint256 proposalId, uint256 lesser, uint256 greater)
external
nonReentrant
returns (bool)
{
dequeueProposalsIfReady();
// If acting on an expired proposal, expire the proposal and take no action.
if (removeIfQueuedAndExpired(proposalId)) {
return false;
}
address account = getAccounts().voteSignerToAccount(msg.sender);
Voter storage voter = voters[account];
removeIfQueuedAndExpired(voter.upvote.proposalId);
// We can upvote a proposal in the queue if we're not already upvoting a proposal in the queue.
uint256 weight = getLockedGold().getAccountTotalLockedGold(account);
require(weight > 0, ""cannot upvote without locking gold"");
require(queue.contains(proposalId), ""cannot upvote a proposal not in the queue"");
require(
voter.upvote.proposalId == 0 || !queue.contains(voter.upvote.proposalId),
""cannot upvote more than one queued proposal""
);
uint256 upvotes = queue.getValue(proposalId).add(weight);
queue.update(proposalId, upvotes, lesser, greater);
voter.upvote = UpvoteRecord(proposalId, weight);
emit ProposalUpvoted(proposalId, account, weight);
return true;
}
| function getUpvoteRecord(address account) external view returns (uint256, uint256) {
UpvoteRecord memory upvoteRecord = voters[account].upvote;
return (upvoteRecord.proposalId, upvoteRecord.weight);
}
",./celo_governance/specs/governance.spec,celo_governance,,Yes,,"Functionality: Enable users to upvote governance proposals using their locked gold as voting power. It validates proposal eligibility, prevents users from supporting multiple active proposals, and updates the upvoted proposal's total upvotes accordingly while maintaining a record of each voter's current upvote."
2b7cc4ca0087210de350b81670679aae,899,rule,no_weight_changing_when_voting,44,61,isVoting,"rule no_weight_changing_when_voting(method f, address account) {
env _e;
uint256 _accountWeight = sinvoke _weight(_e,account);
bool isAccountVoting = sinvoke isVoting(_e,account);
env eF;
calldataarg arg;
invoke f(eF,arg);
env e_;
uint256 accountWeight_ = sinvoke _weight(e_,account);
assert(
isAccountVoting => _accountWeight == accountWeight_,
""Method changed weight of account if voting""
);
}","isVoting (Lines 986-995), "," function isVoting(address account) external view returns (bool) {
Voter storage voter = voters[account];
uint256 upvotedProposal = voter.upvote.proposalId;
bool isVotingQueue = upvotedProposal != 0 &&
isQueued(upvotedProposal) &&
!isQueuedProposalExpired(upvotedProposal);
Proposals.Proposal storage proposal = proposals[voter.mostRecentReferendumProposal];
bool isVotingReferendum = (getProposalDequeuedStage(proposal) == Proposals.Stage.Referendum);
return isVotingQueue || isVotingReferendum;
}
",./celo_governance/specs/locked_gold_linked.spec,celo_governance,,Yes,,"Functionality: Determine if an account is currently voting by checking if they've upvoted a proposal that is queued (but not expired) or if their most recent referendum proposal is in the referendum stage, and return true if either condition is met."
29e34d2da68f8eb527ac2d29a4ac129f,812 | 814 | 816,rule,no_double_upvote,80,97,getUpvotedProposal | upvote | getUpvoteRecord,"rule no_double_upvote(uint256 p, address u) {
uint256 _upvotes = getUpvotes(p);
uint256 _usersUpvotedProposal = getUpvotedProposal(u);
env e;
require e.msg.sender == u && u != 0; // note that the sender is the signer here
// the invariant is upvoteInv, defined here
}
definition upvoteInv(uint p, uint w) returns bool
= (p != 0 && w > 0) || (p == 0 && w == 0)
;
require accounts.voteSignerToAccount(u) == u;
uint256 lesser;
uint256 greater;
upvote(e, p, lesser, greater);
uint256 upvotes_ = getUpvotes(p);
uint voteRecordP;
uint voteRecordW;
voteRecordP, voteRecordW = getUpvoteRecord(u);
require upvoteInv(voteRecordP, voteRecordW);
assert _usersUpvotedProposal == p => upvotes_ <= _upvotes,
""Upvotes increased from ${_upvotes} to ${upvotes_} even though upvoted by user $u who already upvoted $p"";
}
","getUpvotedProposal (Lines 43-48), | upvote (Lines 530-558), | getUpvoteRecord (Lines 1161-1164), "," function getUpvotedProposal(address account) public view returns (uint256) {
uint256 proposalId;
uint256 weight;
(proposalId, weight) = this.getUpvoteRecord(account);
return proposalId;
}
| function upvote(uint256 proposalId, uint256 lesser, uint256 greater)
external
nonReentrant
returns (bool)
{
dequeueProposalsIfReady();
// If acting on an expired proposal, expire the proposal and take no action.
if (removeIfQueuedAndExpired(proposalId)) {
return false;
}
address account = getAccounts().voteSignerToAccount(msg.sender);
Voter storage voter = voters[account];
removeIfQueuedAndExpired(voter.upvote.proposalId);
// We can upvote a proposal in the queue if we're not already upvoting a proposal in the queue.
uint256 weight = getLockedGold().getAccountTotalLockedGold(account);
require(weight > 0, ""cannot upvote without locking gold"");
require(queue.contains(proposalId), ""cannot upvote a proposal not in the queue"");
require(
voter.upvote.proposalId == 0 || !queue.contains(voter.upvote.proposalId),
""cannot upvote more than one queued proposal""
);
uint256 upvotes = queue.getValue(proposalId).add(weight);
queue.update(proposalId, upvotes, lesser, greater);
voter.upvote = UpvoteRecord(proposalId, weight);
emit ProposalUpvoted(proposalId, account, weight);
return true;
}
| function getUpvoteRecord(address account) external view returns (uint256, uint256) {
UpvoteRecord memory upvoteRecord = voters[account].upvote;
return (upvoteRecord.proposalId, upvoteRecord.weight);
}
",./celo_governance/specs/governance.spec,celo_governance,,Yes,,"Functionality: Allow users to upvote proposals for consideration by locking their gold. This process includes validating user vote weight, checking proposal status, ensuring a single queued proposal upvote per user, updating the proposal queue with increased upvotes, and recording the user's upvote with their locked gold weight."
e0e25c2eff6e77e4aa64ef1b150b6797,719 | 720,rule,noWithdrawBeforeUnlocking,128,150,pendingWithdrawalsNotFull | unlock,"rule noWithdrawBeforeUnlocking(address account, uint256 value, method f) {
// We must make sure the length of pending withdrawals is not MAX_UINT, since then the `push` will make the length 0.
// (this should have been checked by the solidity compiler)
require(sinvoke pendingWithdrawalsNotFull(account), ""Pending withdrawals are full"");
// Unlock a value and add it to pending withdrawals
env _e;
require(_e.msg.sender == account);
sinvoke unlock(_e,value);
// Try to run any function - adversary's goal is to succeed in unlocking before time
env eF;
require(eF.block.timestamp > _e.block.timestamp);
calldataarg arg;
sinvoke f(eF,arg);
// We check if adversary succeeded
uint256 totalPendingWithdrawals_ = sinvoke getTotalPendingWithdrawals(account);
assert(
eF.block.timestamp < _e.block.timestamp + sinvoke getunlockingPeriod() =>
sinvoke getAccountNonvotingLockedGold(account) + totalPendingWithdrawals_ >= value,
""If we are before the unlock period passed, we cannot transfer the value outside the locked balance or pending balance""
);
}
","pendingWithdrawalsNotFull (Lines 47-49), | unlock (Lines 62-64), "," function pendingWithdrawalsNotFull(address account) public view returns (bool) {
return balances[account].pendingWithdrawals.length.add(2) >= 2; // we can add 2 more additional elements
}
| function unlock(uint256 value) external {
accountTotalLockedGold[msg.sender] = accountTotalLockedGold[msg.sender].sub(value);
}
",./celo_governance/specs/lockedGold.spec,celo_governance,,Yes,,"Functionality: Check if an account can add at least two more pending withdrawals, returning `true` if the sum of the current number of pending withdrawals and 2 is at least 2. Subtract a specified `value` from the sender's total locked gold balance in the contract."
30c9824cebc813125783c38049e611c2,757,rule,address_can_authorize_two_addresses,125,149,authorizeSignerWithSignature,"rule address_can_authorize_two_addresses(address x, address d1, address d2, bytes32 role1, bytes32 role2)
{
require x != 0 && d1 != 0 && d2 != 0 && x != d1 && x != d2 && d1 != d2 && isAccount(x);
env e;
require e.msg.sender == x;
storage init = lastStorage;
// first, authorizing d2 as a validation signer should succeed
uint8 v2;
bytes32 r2;
bytes32 s2;
authorizeSignerWithSignature(e, d2, role2, v2, r2, s2);
// Authorize d1 as a Vote signer (alternative execution path - start from the state where validator authorization started)
uint8 v1;
bytes32 r1;
bytes32 s1;
authorizeSignerWithSignature(e, d1, role1, v1, r1, s1) at init;
// Even after authorizing d1, the authorization of d2 as a Validation signer should succeed
// AuthorizedBy(d1) and AuthorizedBy(d2) should still be x
assert _getAuthorizedBy(d1) == x && _getAuthorizedBy(d2) == x, ""Authorizedby should both be x"";
}
","authorizeSignerWithSignature (Lines 407-417), "," function authorizeSignerWithSignature(address signer, bytes32 role, uint8 v, bytes32 r, bytes32 s)
public
{
authorizeAddressWithRole(signer, role, v, r, s);
signerAuthorizations[msg.sender][role][signer] = SignerAuthorization({
started: true,
completed: true
});
emit SignerAuthorized(msg.sender, signer, role);
}
",./celo_governance/specs/accounts.spec,celo_governance,,Yes,,"Functionality: Authorize a signer with a specific role using their signature. This is achieved by first authorizing the address with the desired role using the signature components (v, r, s), and then marking the authorization as started and completed for the signer in the contract's state."
ea4ba5e30a4c062b8d537ef09b36af6b,766,rule,cantMakeASignerForNonLegacyRoleWithoutApprovalOfSigner,309,313,authorizeSignerWithSignature,"rule cantMakeASignerForNonLegacyRoleWithoutApprovalOfSigner(method f) filtered { f ->
!f.isView
// the authorizeSignerWithSignature allows the signer to provide a signature to the account, so we exclude this option
&& f.selector != authorizeSignerWithSignature(address,bytes32,uint8,bytes32,bytes32).selector
} {
","authorizeSignerWithSignature (Lines 407-417), "," function authorizeSignerWithSignature(address signer, bytes32 role, uint8 v, bytes32 r, bytes32 s)
public
{
authorizeAddressWithRole(signer, role, v, r, s);
signerAuthorizations[msg.sender][role][signer] = SignerAuthorization({
started: true,
completed: true
});
emit SignerAuthorized(msg.sender, signer, role);
}
",./celo_governance/specs/accounts.spec,celo_governance,,Yes,,"Functionality: Authorize a signer with a specific role by utilizing a digital signature (comprised of `v`, `r`, and `s` components) via the `authorizeAddressWithRole` function. It then marks the authorization as both started and completed within a mapping, and emits a `SignerAuthorized` event."
9228f7b8b1622d2108c894af4bd773de,870 | 872 | 874,rule,constitution_change,325,328,getUpvotedProposal | upvote | getUpvoteRecord,"rule constitution_change(method f) filtered { f ->
!f.isView
// the invariant is upvoteInv, defined here
}
definition upvoteInv(uint p, uint w) returns bool
= (p != 0 && w > 0) || (p == 0 && w == 0)
;
rule no_double_upvote(uint256 p, address u) {
uint256 _upvotes = getUpvotes(p);
uint256 _usersUpvotedProposal = getUpvotedProposal(u);
env e;
require e.msg.sender == u && u != 0; // note that the sender is the signer here
require accounts.voteSignerToAccount(u) == u;
uint256 lesser;
uint256 greater;
upvote(e, p, lesser, greater);
uint256 upvotes_ = getUpvotes(p);
uint voteRecordP;
uint voteRecordW;
voteRecordP, voteRecordW = getUpvoteRecord(u);
require upvoteInv(voteRecordP, voteRecordW);
assert _usersUpvotedProposal == p => upvotes_ <= _upvotes,
""Upvotes increased from ${_upvotes} to ${upvotes_} even though upvoted by user $u who already upvoted $p"";
}
&& f.selector != setConstitution(address,bytes4,uint256).selector
} {
","getUpvotedProposal (Lines 43-48), | upvote (Lines 530-558), | getUpvoteRecord (Lines 1161-1164), "," function getUpvotedProposal(address account) public view returns (uint256) {
uint256 proposalId;
uint256 weight;
(proposalId, weight) = this.getUpvoteRecord(account);
return proposalId;
}
| function upvote(uint256 proposalId, uint256 lesser, uint256 greater)
external
nonReentrant
returns (bool)
{
dequeueProposalsIfReady();
// If acting on an expired proposal, expire the proposal and take no action.
if (removeIfQueuedAndExpired(proposalId)) {
return false;
}
address account = getAccounts().voteSignerToAccount(msg.sender);
Voter storage voter = voters[account];
removeIfQueuedAndExpired(voter.upvote.proposalId);
// We can upvote a proposal in the queue if we're not already upvoting a proposal in the queue.
uint256 weight = getLockedGold().getAccountTotalLockedGold(account);
require(weight > 0, ""cannot upvote without locking gold"");
require(queue.contains(proposalId), ""cannot upvote a proposal not in the queue"");
require(
voter.upvote.proposalId == 0 || !queue.contains(voter.upvote.proposalId),
""cannot upvote more than one queued proposal""
);
uint256 upvotes = queue.getValue(proposalId).add(weight);
queue.update(proposalId, upvotes, lesser, greater);
voter.upvote = UpvoteRecord(proposalId, weight);
emit ProposalUpvoted(proposalId, account, weight);
return true;
}
| function getUpvoteRecord(address account) external view returns (uint256, uint256) {
UpvoteRecord memory upvoteRecord = voters[account].upvote;
return (upvoteRecord.proposalId, upvoteRecord.weight);
}
",./celo_governance/specs/governance.spec,celo_governance,,Yes,,"Functionality: Allow users to upvote governance proposals by locking gold, ensuring they can only upvote a proposal not already queued or expired. Users retrieve their current upvoted proposal's ID and weight, ensuring they cannot upvote more than one proposal in the queue simultaneously."
102ab15f7889b3b711c724608fba9f17,945,rule,executeDelegatesOnlyToAllowedAddresses,59,67,summaryInstance.checkDelegated,"rule executeDelegatesOnlyToAllowedAddresses(method f) {
require summaryInstance.lenDelegated() == 0;
arbitrary(f);
uint pushed = summaryInstance.lenDelegated();
assert pushed <= 3, ""not expected to call execute more than 3 times"";
assert summaryInstance.checkDelegated(getProxyActions()), ""not all delegated are allowed"";
}
","checkDelegated (Lines 80-88), "," function checkDelegated(address allowed) external returns (bool) {
for (uint i = 0 ; i < delegated.length; i++) {
if (delegated[i] != allowed) {
return false;
}
}
return true;
}
",./furucombo/specs/hmaker.spec,furucombo,,Yes,,"Functionality: Check if a specified address (allowed) is the only address in a predefined list (delegated). It iterates through the list and returns false at the first instance of a different address, otherwise, it returns true, indicating all addresses in the list match the specified address."
fa776b5c4182a8ae091f55e1af54298c,947 | 948,rule,changesHandler,22,28,register | unregister,"rule changesHandler(method f, address handler) {
bytes32 _regState;
bytes32 regState_;
handlerTransition(handler, _regState, regState_, f);
assert (f.selector != register(address,bytes32).selector && f.selector != unregister(address).selector)
=> _regState == regState_, ""method unexpectedly changes handler info"";
}
","register (Lines 28-32), | unregister (Lines 38-43), "," function register(address registration, bytes32 info) external onlyOwner {
require(registration != address(0), ""zero address"");
require(adapters[registration] == bytes32(0), ""registered"");
adapters[registration] = info;
}
| function unregister(address registration) external onlyOwner {
require(registration != address(0), ""zero address"");
require(adapters[registration] != bytes32(0), ""no registration"");
require(adapters[registration] != DEPRECATED, ""unregistered"");
adapters[registration] = DEPRECATED;
}
",./furucombo/specs/registry.spec,furucombo,,Yes,,"Functionality: Register an address with specific information if it hasn't been registered yet and is not zero. Unregister a previously registered address by marking it as deprecated, ensuring the address is neither zero, unregistered, nor already marked as deprecated."
7957cf7a0c367b6d664077d0b8c77797,935,rule,transferredTokensMeanThatStackIsUpdated,476,491,summaryInstance.getEthAddress,"rule transferredTokensMeanThatStackIsUpdated(method f) {
require summaryInstance.getEthAddress(currentContract) != someToken; // not an eth transfer
require someToken != 0; // not an eth transfer
require someToken.allowance(currentContract, summaryInstance) == 0; // to make sure we're starting clean as implied by approvedTokensAreTemporary
rule approvedTokensAreTemporary(method f, address someAllowed) {
require someAllowed == summaryInstance; // narrowing down
uint256 allowanceBefore = someToken.allowance(currentContract, someAllowed);
arbitrary(f);
uint256 allowanceAfter = someToken.allowance(currentContract, someAllowed);
assert allowanceBefore == 0 => allowanceAfter == 0, ""Allowances must be nullified"";
}
uint256 balanceBefore = someToken.balanceOf(currentContract);
uint256 stackLengthBefore = getStackLength();
require stackLengthBefore < MAX_UINT256() - STACK_INCREASE_BOUND(); // see stackLengthIncreaseIsBounded
rule stackLengthIncreaseIsBounded(method f) {
uint256 stackLengthAfter = getStackLength();
assert stackLengthAfter <= stackLengthBefore + STACK_INCREASE_BOUND(), ""Found a way to increase stack length by more than 1 million"";
uint256 balanceAfter = someToken.balanceOf(currentContract);
assert (balanceAfter > balanceBefore) => stackLengthAfter > stackLengthBefore,
""must push an entry to postprocess stack if transferring funds into proxy which are not eth"";
","getEthAddress (Lines 30-39), "," function getEthAddress(address handler) external returns (address) {
// either the handler defines a ETH_ADDRESS function or it does not. If it does not then just return address(0)
address eth = address(0);
try WithEthAddress(handler).ETH_ADDRESS() returns (address x) {
eth = x;
} catch {
eth = address(0);
}
return eth;
}
",./furucombo/specs/proxy.spec,furucombo,,Yes,,"Functionality: Attempt to retrieve an Ethereum (ETH) address from a specified contract (`handler`). If the `handler` contract implements a function `ETH_ADDRESS` that returns an address, return this address. Otherwise, return the zero address (address(0)) to indicate failure or non-existence of such a function."
3c7675cafe2f8abdcb3651dc5a393e8a,943,rule,is,568,577,registry.isValidCaller,"// the rule is usually expected to fail, because handler functions do not check who calls them (it's usually the sender via the proxy delegatecall).
rule onlyValidCaller(method f) {
env e;
bool isGoodCaller = registry.isValidCaller(e.msg.sender);
calldataarg arg;
f@withrevert(e, arg);
bool succeeded = !lastReverted;
assert !isGoodCaller => !succeeded, ""function can be called even if the sender is not an allowed caller"";
}
","isValidCaller (Lines 133-137), "," function isValidCaller(
address caller
) external view override returns (bool) {
return callers[caller] != 0 && callers[caller] != DEPRECATED;
}
",./furucombo/specs/proxy.spec,furucombo,,Yes,,"Functionality: Check whether the provided address (caller) is authorized by verifying if its associated value in the `callers` mapping is neither zero nor marked as deprecated (indicated by the `DEPRECATED` constant), and return a boolean indication of its validity."
02c2786803dc8418e6fad9709e745c2f,931,rule,nonExecutableWithInitializedSender,461,473,registry.isValidCaller,"rule nonExecutableWithInitializedSender(method f) {
require !isHandler();
// the rule is usually expected to fail, because handler functions are payable.
rule holdNoEth(method f) {
require ethBalance(currentContract) == 0;
arbitrary(f);
assert ethBalance(currentContract) == 0;
}
require !f.isView; // only non-view functions, that may modify the state, are interesting.
require getSender() != 0; // sender is initialized
env e;
bool isGoodCaller = registry.isValidCaller(e, e.msg.sender);
calldataarg arg;
f@withrevert(e, arg);
assert (f.isFallback && !isGoodCaller) => lastReverted; // only valid callers should execute in fallback successfully (would violate since certora prover cannot distinguish between receive and fallback for now)
assert (f.selector == execs(address[],bytes32[],bytes[]).selector && e.msg.sender != currentContract) => lastReverted; // `execs` is allowed to be called by proxy itself after initialized
assert (!f.isFallback && f.selector != execs(address[],bytes32[],bytes[]).selector) => lastReverted; // all non-view functions other than above ones should revert if sender is already initialized
","isValidCaller (Lines 133-137), "," function isValidCaller(
address caller
) external view override returns (bool) {
return callers[caller] != 0 && callers[caller] != DEPRECATED;
}
",./furucombo/specs/proxy.spec,furucombo,,Yes,,"Functionality: Check if a caller address is valid by verifying that its corresponding value in the 'callers' mapping is neither zero nor marked as 'DEPRECATED'. Return true if the caller is valid, otherwise, return false. This ensures only authorized or non-deprecated callers can proceed."
466147d681a7443c369915dd2914ed64,915,rule,noOverwrite,370,381,postProcess,"rule noOverwrite(method f, uint slot) {
require getStackLength() < MAX_UINT256() - STACK_INCREASE_BOUND(); // see stackLengthIncreaseIsBounded
rule stackLengthIncreaseIsBounded(method f) {
uint256 stackLengthBefore = getStackLength();
arbitrary(f);
uint256 stackLengthAfter = getStackLength();
assert stackLengthAfter <= stackLengthBefore + STACK_INCREASE_BOUND(), ""Found a way to increase stack length by more than 1 million"";
}
uint oldValue = getSlot(slot);
uint newValue = getSlot(slot);
// slot 0 is stack length, postProcess() may nullify it and it's fine, and execs() can increase it
// the rule is usually expected to fail, because handler functions are payable.
rule holdNoEth(method f) {
require ethBalance(currentContract) == 0;
assert ethBalance(currentContract) == 0;
assert oldValue != 0 => (newValue == oldValue
|| slot == getStackLengthSlot()), ""Slot $slot changd during this execution"";
","postProcess (Lines 334-344), "," function postProcess() external payable override {
bytes4 sig = stack.getSig();
// selector of openLockETHAndDraw(uint256,address,address,bytes32,uint256)
// and openLockGemAndDraw(address,address,bytes32,uint256,uint256)
if (sig == 0x5481e4a4 || sig == 0x73af24e7) {
_transferCdp(uint256(stack.get()));
uint256 amount = IERC20(DAI_TOKEN).balanceOf(address(this));
if (amount > 0)
IERC20(DAI_TOKEN).safeTransfer(_getSender(), amount);
} else revert(""Invalid post process"");
}
",./furucombo/specs/proxy.spec,furucombo,,Yes,,"Functionality: Check if the invoked function matches specific signatures related to financial operations. If so, transfer a collateralized debt position (CDP) and, if any DAI tokens are available, safely transfer these tokens to the transaction initiator's address. Otherwise, revert the transaction for invalid operations."
0567294d237aab42e4368f373490459b,954,rule,unregisterHandlerIsPermanent2,72,78,unregister,"rule unregisterHandlerIsPermanent2(method f, address handler) {
rule unregisterHandlerIsPermanent(method f, address handler) {
env e;
unregister(e, handler);
callArbitrary(f);
assert handlers(handler) == deprecated(), ""unexpected handler info after unregister"";
}
require handlers(handler) == deprecated();
","unregister (Lines 38-43), "," function unregister(address registration) external onlyOwner {
require(registration != address(0), ""zero address"");
require(adapters[registration] != bytes32(0), ""no registration"");
require(adapters[registration] != DEPRECATED, ""unregistered"");
adapters[registration] = DEPRECATED;
}
",./furucombo/specs/registry.spec,furucombo,,Yes,,"Functionality: Mark a specific registration as deprecated if it exists and is not already marked as such, ensuring that the registration address is not the zero address and has been previously registered. Only the contract owner is allowed to perform this action."
33c932d0e1757f2a8595ccd730e08402,950,rule,changesCaller,38,44,unregisterCaller,"rule changesCaller(method f, address caller) {
bytes32 _regState;
bytes32 regState_;
callerTransition(caller, _regState, regState_, f);
assert (f.selector != registerCaller(address,bytes32).selector && f.selector != unregisterCaller(address).selector)
=> _regState == regState_, ""method unexpectedly changes caller info"";
}
","unregisterCaller (Lines 94-100), "," function unregisterCaller(address registration) external onlyOwner {
require(registration != address(0), ""zero address"");
require(callers[registration] != bytes32(0), ""no registration"");
require(callers[registration] != DEPRECATED, ""unregistered"");
callers[registration] = DEPRECATED;
emit CallerUnregistered(registration);
}
",./furucombo/specs/registry.spec,furucombo,,Yes,,"Functionality: Invalidate a previously registered caller's address, ensuring it's neither a zero address nor already unregistered. This action, only executable by the contract owner, marks the caller's address as deprecated within the contract's state and emits an event indicating the caller's unregistration."
32d202a5d42940d3ddd3ea1a426af50b,905,rule,executeDelegatesOnlyToAllowedAddresses,59,67,summaryInstance.checkDelegated,"rule executeDelegatesOnlyToAllowedAddresses(method f) {
require summaryInstance.lenDelegated() == 0;
arbitrary(f);
uint pushed = summaryInstance.lenDelegated();
assert pushed <= 3, ""not expected to call execute more than 3 times"";
assert summaryInstance.checkDelegated(FCOMPOUND_ACTIONS()), ""not all delegated are allowed"";
}
","checkDelegated (Lines 80-88), "," function checkDelegated(address allowed) external returns (bool) {
for (uint i = 0 ; i < delegated.length; i++) {
if (delegated[i] != allowed) {
return false;
}
}
return true;
}
",./furucombo/specs/hscompound.spec,furucombo,,Yes,,"Functionality: The given code checks if the address provided as 'allowed' is the only address recorded in the 'delegated' array. It returns true only if the 'allowed' address matches all entries in the 'delegated' array, otherwise, it returns false."
fe8c987fb27105b67dce90aa69e6d968,953,rule,unregisterCallerIsPermanent,63,70,unregisterCaller,"rule unregisterCallerIsPermanent(method f, address caller) {
env e;
unregisterCaller(e, caller);
callArbitrary(f);
assert callers(caller) == deprecated(), ""unexpected caller info after unregister"";
}
","unregisterCaller (Lines 94-100), "," function unregisterCaller(address registration) external onlyOwner {
require(registration != address(0), ""zero address"");
require(callers[registration] != bytes32(0), ""no registration"");
require(callers[registration] != DEPRECATED, ""unregistered"");
callers[registration] = DEPRECATED;
emit CallerUnregistered(registration);
}
",./furucombo/specs/registry.spec,furucombo,,Yes,,"Functionality: Mark a caller as unregistered in a smart contract, ensuring it's not the zero address, already registered, and not previously unregistered. It then sets the caller's status to 'DEPRECATED' and emits a 'CallerUnregistered' event with the caller's address."
ec94157365af0a8d8ad4ed57ec684886,1485 | 1486,rule,unexpectedBalanceChange,87,93,safeTransferFrom | safeBatchTransferFrom,"rule unexpectedBalanceChange(method f, env e)
filtered { f -> f.selector != safeTransferFrom(address, address, uint256, uint256, bytes).selector
&& f.selector != safeBatchTransferFrom(address, address, uint256[], uint256[], bytes).selector
&& f.selector != mint(address, uint256, uint256, bytes).selector
&& f.selector != mintBatch(address, uint256[], uint256[], bytes).selector
&& f.selector != burn(address, uint256, uint256).selector
&& f.selector != burnBatch(address, uint256[], uint256[]).selector } {
","safeTransferFrom (Lines 117-129), | safeBatchTransferFrom (Lines 134-146), "," function safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
) public virtual override {
require(
from == _msgSender() || isApprovedForAll(from, _msgSender()),
""ERC1155: caller is not token owner nor approved""
);
_safeTransferFrom(from, to, id, amount, data);
}
| function safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) public virtual override {
require(
from == _msgSender() || isApprovedForAll(from, _msgSender()),
""ERC1155: caller is not token owner nor approved""
);
_safeBatchTransferFrom(from, to, ids, amounts, data);
}
",./openzepplin/specs/ERC1155.spec,openzepplin,,Yes,,"Functionality: Enable the secure transfer of single or multiple token types from one address to another, contingent on the initiator being the token holder or an approved delegate, through checks ensuring authorization before leveraging internal functions that actually facilitate the transfer process."
f756903d59f2aed80775848b57232223,1533 | 1534 | 1535,rule,singleTokenSafeTransferFromSafeBatchTransferFromEquivalence,779,806,balanceOf | safeTransferFrom | safeBatchTransferFrom,"rule singleTokenSafeTransferFromSafeBatchTransferFromEquivalence {
storage beforeTransfer = lastStorage;
env e;
address holder; address recipient;
uint256 token; uint256 transferAmount; bytes data;
uint256[] tokens; uint256[] transferAmounts;
mathint holderStartingBalance = balanceOf(holder, token);
mathint recipientStartingBalance = balanceOf(recipient, token);
require tokens.length == 1; require transferAmounts.length == 1;
require tokens[0] == token; require transferAmounts[0] == transferAmount;
// transferring via safeTransferFrom
safeTransferFrom(e, holder, recipient, token, transferAmount, data) at beforeTransfer;
mathint holderSafeTransferFromBalanceChange = holderStartingBalance - balanceOf(holder, token);
mathint recipientSafeTransferFromBalanceChange = balanceOf(recipient, token) - recipientStartingBalance;
// transferring via safeBatchTransferFrom
safeBatchTransferFrom(e, holder, recipient, tokens, transferAmounts, data) at beforeTransfer;
mathint holderSafeBatchTransferFromBalanceChange = holderStartingBalance - balanceOf(holder, token);
mathint recipientSafeBatchTransferFromBalanceChange = balanceOf(recipient, token) - recipientStartingBalance;
assert holderSafeTransferFromBalanceChange == holderSafeBatchTransferFromBalanceChange
&& recipientSafeTransferFromBalanceChange == recipientSafeBatchTransferFromBalanceChange,
""Transferring a single token via safeTransferFrom or safeBatchTransferFrom must be equivalent"";
}
","balanceOf (Lines 70-73), | safeTransferFrom (Lines 117-129), | safeBatchTransferFrom (Lines 134-146), "," function balanceOf(address account, uint256 id) public view virtual override returns (uint256) {
require(account != address(0), ""ERC1155: address zero is not a valid owner"");
return _balances[id][account];
}
| function safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
) public virtual override {
require(
from == _msgSender() || isApprovedForAll(from, _msgSender()),
""ERC1155: caller is not token owner nor approved""
);
_safeTransferFrom(from, to, id, amount, data);
}
| function safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) public virtual override {
require(
from == _msgSender() || isApprovedForAll(from, _msgSender()),
""ERC1155: caller is not token owner nor approved""
);
_safeBatchTransferFrom(from, to, ids, amounts, data);
}
",./openzepplin/specs/ERC1155.spec,openzepplin,,Yes,,"Functionality: Validate token ownership or approval before executing token transfers in the ERC1155 standard. Specifically, it checks for valid non-zero addresses, owner or approved caller status, then performs either a single or batch transfer of tokens, including accompanying data."
d37c0dd25e371ea38fa91d5158d92698,1520,rule,cantMintBatchOtherBalances,574,595,balanceOf,"rule cantMintBatchOtherBalances(env e){
address to;
uint256 id1; uint256 id2; uint256 id3;
uint256[] ids; uint256[] amounts;
address other;
bytes data;
uint256 otherBalanceBefore1 = balanceOf(other, id1);
uint256 otherBalanceBefore2 = balanceOf(other, id2);
uint256 otherBalanceBefore3 = balanceOf(other, id3);
mintBatch(e, to, ids, amounts, data);
uint256 otherBalanceAfter1 = balanceOf(other, id1);
uint256 otherBalanceAfter2 = balanceOf(other, id2);
uint256 otherBalanceAfter3 = balanceOf(other, id3);
assert other != to => (otherBalanceBefore1 == otherBalanceAfter1
&& otherBalanceBefore2 == otherBalanceAfter2
&& otherBalanceBefore3 == otherBalanceAfter3)
, ""I like to see your money disappearing"";
}
","balanceOf (Lines 70-73), "," function balanceOf(address account, uint256 id) public view virtual override returns (uint256) {
require(account != address(0), ""ERC1155: address zero is not a valid owner"");
return _balances[id][account];
}
",./openzepplin/specs/ERC1155.spec,openzepplin,,Yes,,"Functionality: Verify the validity of an account address, ensuring it is not a zero address, to prevent operations involving invalid ownership. Subsequently, retrieve and return the balance of a specific token, identified by `id`, owned by the specified `account`."
ec94157365af0a8d8ad4ed57ec684886,1485 | 1486,rule,unexpectedBalanceChange,87,93,safeTransferFrom | safeBatchTransferFrom,"rule unexpectedBalanceChange(method f, env e)
filtered { f -> f.selector != safeTransferFrom(address, address, uint256, uint256, bytes).selector
&& f.selector != safeBatchTransferFrom(address, address, uint256[], uint256[], bytes).selector
&& f.selector != mint(address, uint256, uint256, bytes).selector
&& f.selector != mintBatch(address, uint256[], uint256[], bytes).selector
&& f.selector != burn(address, uint256, uint256).selector
&& f.selector != burnBatch(address, uint256[], uint256[]).selector } {
","safeTransferFrom (Lines 117-129), | safeBatchTransferFrom (Lines 134-146), "," function safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
) public virtual override {
require(
from == _msgSender() || isApprovedForAll(from, _msgSender()),
""ERC1155: caller is not token owner nor approved""
);
_safeTransferFrom(from, to, id, amount, data);
}
| function safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) public virtual override {
require(
from == _msgSender() || isApprovedForAll(from, _msgSender()),
""ERC1155: caller is not token owner nor approved""
);
_safeBatchTransferFrom(from, to, ids, amounts, data);
}
",./openzepplin/specs/ERC1155.spec,openzepplin,,Yes,,"Functionality: The code defines two functions for transferring ERC1155 tokens. The `safeTransferFrom` function allows for the transfer of a single token type, while the `safeBatchTransferFrom` function enables the transfer of multiple token types in one transaction, enforcing ownership or approval verification before proceeding."
e5c1003fa926635a164cb5ca90a76138,1647 | 1651,rule,delegate_no_frontrunning,236,271,balanceOf | _delegate,"rule delegate_no_frontrunning(method f) {
env e; calldataarg args;
address delegator; address delegatee; address third; address other;
// converted from an invariant to a rule to slightly change the logic
// if the fromBlock is the same as before, then the number of checkpoints stays the same
// however if the fromBlock is new than the number of checkpoints increases
// passes, fails rule sanity because tautology check seems to be bugged
// passes + rule sanity
invariant fromBlock_greaterThanEq_pos(address account, uint32 pos)
ckptFromBlock(account, pos) >= pos
filtered { f -> !f.isView }
rule unique_checkpoints_rule(method f) {
address account;
uint32 num_ckpts_ = numCheckpoints(account);
uint32 fromBlock_ = num_ckpts_ == 0 ? 0 : ckptFromBlock(account, num_ckpts_ - 1);
f(e, args);
uint32 _num_ckpts = numCheckpoints(account);
uint32 _fromBlock = _num_ckpts == 0 ? 0 : ckptFromBlock(account, _num_ckpts - 1);
assert fromBlock_ == _fromBlock => num_ckpts_ == _num_ckpts || _num_ckpts == 1, ""same fromBlock, new checkpoint"";
}
require numCheckpoints(delegatee) < 1000000;
require numCheckpoints(third) < 1000000;
uint256 delegator_bal = balanceOf(e, delegator);
uint256 delegatee_votes_ = getVotes(delegatee);
uint256 third_votes_ = getVotes(third);
uint256 other_votes_ = getVotes(other);
require delegates(delegator) == third;
require third != delegatee;
require other != third;
require other != delegatee;
require delegatee != 0x0;
_delegate(e, delegator, delegatee);
uint256 _delegatee_votes = getVotes(delegatee);
uint256 _third_votes = getVotes(third);
uint256 _other_votes = getVotes(other);
// previous delegatee loses all of their votes
// delegatee gains that many votes
// third loses any votes delegated to them
assert _delegatee_votes == delegatee_votes_ + delegator_bal, ""delegatee did not receive votes"";
assert third != 0 => _third_votes == third_votes_ - delegator_bal, ""votes not removed from third"";
assert other_votes_ == _other_votes, ""delegate not contained"";
","balanceOf (Lines 70-73), | _delegate (Lines 127-133), "," function balanceOf(address account, uint256 id) public view virtual override returns (uint256) {
require(account != address(0), ""ERC1155: address zero is not a valid owner"");
return _balances[id][account];
}
| function _delegate(address account, address delegatee) internal virtual {
address oldDelegate = delegates(account);
_delegation[account] = delegatee;
emit DelegateChanged(account, oldDelegate, delegatee);
_moveDelegateVotes(oldDelegate, delegatee, _getVotingUnits(account));
}
",./openzepplin/specs/ERC20Votes.spec,openzepplin,,Yes,,"Functionality: Check the balance of a specific token (identified by `id`) for a given account in an ERC1155 contract while ensuring the account isn't a zero address. Additionally, manage the delegation of voting power from one account to another, updating their delegation status and redistributing voting units accordingly."
41259f74d90666460170f6c3f7cde3b8,1497 | 1498,rule,transferBalanceIncreaseEffect,281,295,balanceOf | safeTransferFrom,"rule transferBalanceIncreaseEffect(env e){
address from; address to; address other;
uint256 id; uint256 amount;
bytes data;
require from != other;
uint256 otherBalanceBefore = balanceOf(other, id);
safeTransferFrom(e, from, to, id, amount, data);
uint256 otherBalanceAfter = balanceOf(other, id);
assert other != to => otherBalanceBefore == otherBalanceAfter, ""Don't touch my money!"";
}
","balanceOf (Lines 70-73), | safeTransferFrom (Lines 117-129), "," function balanceOf(address account, uint256 id) public view virtual override returns (uint256) {
require(account != address(0), ""ERC1155: address zero is not a valid owner"");
return _balances[id][account];
}
| function safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
) public virtual override {
require(
from == _msgSender() || isApprovedForAll(from, _msgSender()),
""ERC1155: caller is not token owner nor approved""
);
_safeTransferFrom(from, to, id, amount, data);
}
",./openzepplin/specs/ERC1155.spec,openzepplin,,Yes,,"Functionality: Check an account's balance for a specific token ID and safely transfer a specified amount of a token from one account to another, ensuring the sender is authorized through ownership or approval, and validating address integrity to prevent transfers to the zero address."
7a0e8380f35b696c56504691cf006d5a,1494,rule,cannotTransferMoreBatch,238,257,balanceOf,"rule cannotTransferMoreBatch(env e){
address from; address to; uint256[] ids; uint256[] amounts; bytes data;
uint256 idToCheck1; uint256 amountToCheck1;
uint256 idToCheck2; uint256 amountToCheck2;
uint256 idToCheck3; uint256 amountToCheck3;
uint256 balanceBefore1 = balanceOf(from, idToCheck1);
uint256 balanceBefore2 = balanceOf(from, idToCheck2);
uint256 balanceBefore3 = balanceOf(from, idToCheck3);
require ids.length == 3;
require amounts.length == 3;
require ids[0] == idToCheck1; require amounts[0] == amountToCheck1;
require ids[1] == idToCheck2; require amounts[1] == amountToCheck2;
require ids[2] == idToCheck3; require amounts[2] == amountToCheck3;
safeBatchTransferFrom@withrevert(e, from, to, ids, amounts, data);
assert (amountToCheck1 > balanceBefore1 || amountToCheck2 > balanceBefore2 || amountToCheck3 > balanceBefore3) => lastReverted, ""Achtung! Scammer!"";
}
","balanceOf (Lines 70-73), "," function balanceOf(address account, uint256 id) public view virtual override returns (uint256) {
require(account != address(0), ""ERC1155: address zero is not a valid owner"");
return _balances[id][account];
}
",./openzepplin/specs/ERC1155.spec,openzepplin,,Yes,,"Functionality: Verify that the specified account address is not a zero address to ensure it's a valid owner, then retrieve and return the balance of a specific token (identified by `id`) that is held by the given account from the internal `_balances` mapping."
a9ad2fb52b9f699a195da63275d122d9,1688,rule,scheduleCheck,169,179,schedule,"rule scheduleCheck(method f, env e){
bytes32 id;
address target; uint256 value; bytes data ;bytes32 predecessor; bytes32 salt; uint256 delay;
hashIdCorrelation(id, target, value, data, predecessor, salt);
schedule(e, target, value, data, predecessor, salt, delay);
assert getTimestamp(id) == to_uint256(e.block.timestamp + delay), ""Time doesn't obey to mortal souls"";
}
","schedule (Lines 214-225), "," function schedule(
address target,
uint256 value,
bytes calldata data,
bytes32 predecessor,
bytes32 salt,
uint256 delay
) public virtual onlyRole(PROPOSER_ROLE) {
bytes32 id = hashOperation(target, value, data, predecessor, salt);
_schedule(id, delay);
emit CallScheduled(id, 0, target, value, data, predecessor, delay);
}
",./openzepplin/specs/TimelockController.spec,openzepplin,,Yes,,"Functionality: Schedule a deferred transaction with a specific delay, targeting a certain address with data and value, only if the caller has the required proposer role. It calculates a unique operation ID based on the target, value, data, predecessor, and salt, then schedules the operation and emits a corresponding event."
5482195dc811971ad08ec18f89a78ecd,1599 | 1603,rule,sanity,181,198,balanceOf | _delegate,"// passes + rule sanity
rule delegatee_receives_votes() {
env e;
address delegator; address delegatee;
// converted from an invariant to a rule to slightly change the logic
// if the fromBlock is the same as before, then the number of checkpoints stays the same
// however if the fromBlock is new than the number of checkpoints increases
// passes, fails rule sanity because tautology check seems to be bugged
// passes but fails rule sanity from hash on delegate by sig
invariant timestamp_constrains_fromBlock(address account, uint32 index, env e)
ckptFromBlock(account, index) < e.block.number
filtered { f -> !f.isView }
rule unique_checkpoints_rule(method f) {
env e; calldataarg args;
address account;
uint32 num_ckpts_ = numCheckpoints(account);
uint32 fromBlock_ = num_ckpts_ == 0 ? 0 : ckptFromBlock(account, num_ckpts_ - 1);
f(e, args);
uint32 _num_ckpts = numCheckpoints(account);
uint32 _fromBlock = _num_ckpts == 0 ? 0 : ckptFromBlock(account, _num_ckpts - 1);
assert fromBlock_ == _fromBlock => num_ckpts_ == _num_ckpts || _num_ckpts == 1, ""same fromBlock, new checkpoint"";
// this assert fails consistently
// assert !doubleFromBlock(account) => ckpts_ != _ckpts, ""new fromBlock but total checkpoints not being increased"";
}
require numCheckpoints(delegatee) < 1000000;
require delegates(delegator) != delegatee;
require delegatee != 0x0;
uint256 delegator_bal = balanceOf(e, delegator);
uint256 votes_= getVotes(delegatee);
_delegate(e, delegator, delegatee);
uint256 _votes = getVotes(delegatee);
assert _votes == votes_ + delegator_bal, ""delegatee did not receive votes"";
","balanceOf (Lines 70-73), | _delegate (Lines 127-133), "," function balanceOf(address account, uint256 id) public view virtual override returns (uint256) {
require(account != address(0), ""ERC1155: address zero is not a valid owner"");
return _balances[id][account];
}
| function _delegate(address account, address delegatee) internal virtual {
address oldDelegate = delegates(account);
_delegation[account] = delegatee;
emit DelegateChanged(account, oldDelegate, delegatee);
_moveDelegateVotes(oldDelegate, delegatee, _getVotingUnits(account));
}
",./openzepplin/specs/ERC721Votes.spec,openzepplin,,Yes,,"Functionality: Retrieve the balance of a specific token ID for a given account, ensuring the account address is not zero, and internally assign a delegate to an account, recording the delegation change and adjusting the vote counts of the old and new delegates based on the delegator's voting power."
3b46de187a09f7f67a6debd54638f799,1474,rule,burnBatchOnEmptyArraysChangesNothing,142,160,balanceOf,"rule burnBatchOnEmptyArraysChangesNothing {
uint256 token; address nonHolderA; address nonHolderB;
uint256 startingBalance = balanceOf(nonHolderA, token);
bool startingPermission = isApprovedForAll(nonHolderA, nonHolderB);
env e; address holder; uint256[] noTokens; uint256[] noBurnAmounts;
require noTokens.length == 0; require noBurnAmounts.length == 0;
burnBatch(e, holder, noTokens, noBurnAmounts);
uint256 endingBalance = balanceOf(nonHolderA, token);
bool endingPermission = isApprovedForAll(nonHolderA, nonHolderB);
assert startingBalance == endingBalance,
""burnBatch must not change token balances if passed empty arrays"";
assert startingPermission == endingPermission,
""burnBatch must not change account permissions if passed empty arrays"";
}
","balanceOf (Lines 70-73), "," function balanceOf(address account, uint256 id) public view virtual override returns (uint256) {
require(account != address(0), ""ERC1155: address zero is not a valid owner"");
return _balances[id][account];
}
",./openzepplin/specs/ERC1155Burnable.spec,openzepplin,,Yes,,"Functionality: Retrieve the balance of a specific token (identified by `id`) owned by a given account. Ensure the account address is not the zero address, indicating it must be a valid owner, before returning the account's token balance from the internal balances mapping."
650a8ad637770c08c9dff6bd1ba25058,1930 | 1931 | 1932,rule,validBalanceTotalShort,190,215,mintOtokenA | redeemA | settleVault,"rule validBalanceTotalShort(address owner, uint256 vaultId, uint256 index, address secondAddress, address oToken, method f, uint256 amount)
description ""$f breaks the validity of stored balance of short asset""
{
links();
env e;
calldataarg arg;
require oToken == shortOtoken;
require !isVaultExpired(e, owner, vaultId);
require getVaultShortOtoken(owner, vaultId, index) == oToken;
uint256 shortVaultBefore = getVaultShortAmount(owner, vaultId, index);
uint256 supplyBefore = shortOtoken.totalSupply();
// only test the cases before expiry
if (f.selector == settleVault(address,uint256,address).selector) || (f.selector == redeemA(address,uint256).selector) {
assert true;
} else if (f.selector == mintOtokenA(address,uint256,address,uint256,uint256).selector) {
// ignore the case where you can mint otokens directly to the margin pool
require (secondAddress != pool);
sinvoke mintOtokenA(e, owner, vaultId, secondAddress, index, amount);
} else {
callFunctionWithParameters(f, owner, vaultId, index);
}
uint256 shortVaultAfter = getVaultShortAmount(owner, vaultId, index);
uint256 supplyAfter = shortOtoken.totalSupply();
assert shortVaultBefore != shortVaultAfter => (supplyAfter - supplyBefore == shortVaultAfter - shortVaultBefore);
assert supplyAfter != supplyBefore => ( supplyAfter - supplyBefore == shortVaultAfter - shortVaultBefore);
}
","mintOtokenA (Lines 268-285), | redeemA (Lines 344-347), | settleVault (Lines 360-367), "," function mintOtokenA(
address owner,
uint256 vaultId,
address to,
uint256 index,
uint256 amount
) external {
require(smallVault(owner, vaultId, 1));
Actions.MintArgs memory args = Actions.MintArgs({
owner: owner,
vaultId: vaultId,
to: to,
otoken: anOtokenA,
index: index,
amount: amount
});
_mintOtoken(args);
}
| function redeemA(address receiver, uint256 amount) external {
Actions.RedeemArgs memory args = Actions.RedeemArgs({receiver: receiver, otoken: anOtokenA, amount: amount});
_redeem(args);
}
| function settleVault(
address owner,
uint256 vaultId,
address to
) external {
Actions.SettleVaultArgs memory args = Actions.SettleVaultArgs({owner: owner, vaultId: vaultId, to: to});
_settleVault(args);
}
",./opyn_gamma_protocol/specs/ValidBalances.spec,opyn_gamma_protocol,,Yes,,"Functionality: The provided code implements three operations related to managing tokens and vaults within a finance-oriented smart contract: minting a specific type of oToken (`anOtokenA`) into a designated account, redeeming said oToken for an underlying asset, and settling a vault by transferring its contents or obligations to another account."
bde417a50b4ad4f79fb7d8b4809fca07,1801 | 1802 | 1803 | 1808,rule,integrityOfAddShort,188,196,addShort | addLong | addCollateral | totalShortAmount,"rule integrityOfAddShort(address shortOtoken, uint256 x, uint256 index)
{
requireInvariant validVault();
invariant validVault() longAmountLength() == longOtokensLength() &&
shortAmountLength() == shortOtokensLength() &&
collateralAmountLength() == collateralAssetsLength()
invariant validEntityIndex(uint256 index)
(getLongAmount(index) > 0 <=> getLongOtoken(index) != 0) &&
(getShortAmount(index) > 0 <=> getShortOtoken(index) != 0) &&
(getCollateralAmount(index) > 0 <=> getCollateralAsset(index) != 0)
preserved addLong(address asset, uint256 amt, uint256 _index)
{
requireInvariant validEntityIndex(_index);
requireInvariant validEntityIndex(index);
require asset != ADDRESSZERO();
}
preserved addShort(address asset, uint256 amt, uint256 _index)
preserved addCollateral(address asset, uint256 amt, uint256 _index)
}
require shortOtoken != ADDRESSZERO();
uint256 shortAmountBefore = totalShortAmount();
sinvoke addShort(shortOtoken, x, index);
assert totalShortAmount() == shortAmountBefore + x &&
getShortOtoken(index) == shortOtoken, ""integrity break of addShort"";
","addShort (Lines 57-78), | addLong (Lines 112-133), | addCollateral (Lines 167-188), | totalShortAmount (Lines 91-97), "," function addShort(
Vault storage _vault,
address _shortOtoken,
uint256 _amount,
uint256 _index
) external {
require(_amount > 0, ""V1"");
// valid indexes in any array are between 0 and array.length - 1.
// if adding an amount to an preexisting short oToken, check that _index is in the range of 0->length-1
if ((_index == _vault.shortOtokens.length) && (_index == _vault.shortAmounts.length)) {
_vault.shortOtokens.push(_shortOtoken);
_vault.shortAmounts.push(_amount);
} else {
require((_index < _vault.shortOtokens.length) && (_index < _vault.shortAmounts.length), ""V2"");
address existingShort = _vault.shortOtokens[_index];
require((existingShort == _shortOtoken) || (existingShort == address(0)), ""V3"");
_vault.shortAmounts[_index] = _vault.shortAmounts[_index].add(_amount);
_vault.shortOtokens[_index] = _shortOtoken;
}
}
| function addLong(
Vault storage _vault,
address _longOtoken,
uint256 _amount,
uint256 _index
) external {
require(_amount > 0, ""V4"");
// valid indexes in any array are between 0 and array.length - 1.
// if adding an amount to an preexisting short oToken, check that _index is in the range of 0->length-1
if ((_index == _vault.longOtokens.length) && (_index == _vault.longAmounts.length)) {
_vault.longOtokens.push(_longOtoken);
_vault.longAmounts.push(_amount);
} else {
require((_index < _vault.longOtokens.length) && (_index < _vault.longAmounts.length), ""V5"");
address existingLong = _vault.longOtokens[_index];
require((existingLong == _longOtoken) || (existingLong == address(0)), ""V6"");
_vault.longAmounts[_index] = _vault.longAmounts[_index].add(_amount);
_vault.longOtokens[_index] = _longOtoken;
}
}
| function addCollateral(
Vault storage _vault,
address _collateralAsset,
uint256 _amount,
uint256 _index
) external {
require(_amount > 0, ""V7"");
// valid indexes in any array are between 0 and array.length - 1.
// if adding an amount to an preexisting short oToken, check that _index is in the range of 0->length-1
if ((_index == _vault.collateralAssets.length) && (_index == _vault.collateralAmounts.length)) {
_vault.collateralAssets.push(_collateralAsset);
_vault.collateralAmounts.push(_amount);
} else {
require((_index < _vault.collateralAssets.length) && (_index < _vault.collateralAmounts.length), ""V8"");
address existingCollateral = _vault.collateralAssets[_index];
require((existingCollateral == _collateralAsset) || (existingCollateral == address(0)), ""V9"");
_vault.collateralAmounts[_index] = _vault.collateralAmounts[_index].add(_amount);
_vault.collateralAssets[_index] = _collateralAsset;
}
}
| function totalShortAmount() external returns (uint256) {
uint256 total = 0;
for (uint256 i = 0; i < vault.shortAmounts.length; i++) {
total = total.add(vault.shortAmounts[i]);
}
return total;
}
",./opyn_gamma_protocol/specs/MarginVault.spec,opyn_gamma_protocol,,Yes,,"Functionality: Add assets (long, short, or collateral) to a vault at a specified index, ensuring valid amounts and indices are provided, then potentially update existing entries or append new ones. Also, calculate the total amount of short positions in the vault."
3ad2a8378261e379ed62392d65de0601,1817 | 1818 | 1819 | 1824,rule,additiveAddShort,201,220,addShort | addLong | addCollateral | totalShortAmount,"rule additiveAddShort(address shortOtoken, uint256 x, uint256 y, uint256 index)
{
requireInvariant validVault();
invariant validVault() longAmountLength() == longOtokensLength() &&
shortAmountLength() == shortOtokensLength() &&
collateralAmountLength() == collateralAssetsLength()
invariant validEntityIndex(uint256 index)
(getLongAmount(index) > 0 <=> getLongOtoken(index) != 0) &&
(getShortAmount(index) > 0 <=> getShortOtoken(index) != 0) &&
(getCollateralAmount(index) > 0 <=> getCollateralAsset(index) != 0)
preserved addLong(address asset, uint256 amt, uint256 _index)
{
requireInvariant validEntityIndex(_index);
requireInvariant validEntityIndex(index);
require asset != ADDRESSZERO();
}
preserved addShort(address asset, uint256 amt, uint256 _index)
preserved addCollateral(address asset, uint256 amt, uint256 _index)
}
require shortOtoken != ADDRESSZERO();
require index < MAXINT(); // no violation when limiting index
require x > 0 && y > 0 ;
uint256 t = x + y ;
require( t >= x && t >= y); //no overflow
storage initialStorage = lastStorage;
invoke addShort(shortOtoken, x, index);
bool call1 = !lastReverted;
invoke addShort(shortOtoken, y, index);
bool call2 = !lastReverted;
uint256 shortAmountScenario1 = totalShortAmount();
invoke addShort(shortOtoken, t, index) at initialStorage;
bool call3 = !lastReverted;
uint256 shortAmountScenario2 = totalShortAmount();
assert (call1 && call2) <=> call3, ""addShort is not additive, one scenario reverts"" ;
assert call3 => shortAmountScenario1 == shortAmountScenario2, ""addShort is not additive"" ;
","addShort (Lines 57-78), | addLong (Lines 112-133), | addCollateral (Lines 167-188), | totalShortAmount (Lines 91-97), "," function addShort(
Vault storage _vault,
address _shortOtoken,
uint256 _amount,
uint256 _index
) external {
require(_amount > 0, ""V1"");
// valid indexes in any array are between 0 and array.length - 1.
// if adding an amount to an preexisting short oToken, check that _index is in the range of 0->length-1
if ((_index == _vault.shortOtokens.length) && (_index == _vault.shortAmounts.length)) {
_vault.shortOtokens.push(_shortOtoken);
_vault.shortAmounts.push(_amount);
} else {
require((_index < _vault.shortOtokens.length) && (_index < _vault.shortAmounts.length), ""V2"");
address existingShort = _vault.shortOtokens[_index];
require((existingShort == _shortOtoken) || (existingShort == address(0)), ""V3"");
_vault.shortAmounts[_index] = _vault.shortAmounts[_index].add(_amount);
_vault.shortOtokens[_index] = _shortOtoken;
}
}
| function addLong(
Vault storage _vault,
address _longOtoken,
uint256 _amount,
uint256 _index
) external {
require(_amount > 0, ""V4"");
// valid indexes in any array are between 0 and array.length - 1.
// if adding an amount to an preexisting short oToken, check that _index is in the range of 0->length-1
if ((_index == _vault.longOtokens.length) && (_index == _vault.longAmounts.length)) {
_vault.longOtokens.push(_longOtoken);
_vault.longAmounts.push(_amount);
} else {
require((_index < _vault.longOtokens.length) && (_index < _vault.longAmounts.length), ""V5"");
address existingLong = _vault.longOtokens[_index];
require((existingLong == _longOtoken) || (existingLong == address(0)), ""V6"");
_vault.longAmounts[_index] = _vault.longAmounts[_index].add(_amount);
_vault.longOtokens[_index] = _longOtoken;
}
}
| function addCollateral(
Vault storage _vault,
address _collateralAsset,
uint256 _amount,
uint256 _index
) external {
require(_amount > 0, ""V7"");
// valid indexes in any array are between 0 and array.length - 1.
// if adding an amount to an preexisting short oToken, check that _index is in the range of 0->length-1
if ((_index == _vault.collateralAssets.length) && (_index == _vault.collateralAmounts.length)) {
_vault.collateralAssets.push(_collateralAsset);
_vault.collateralAmounts.push(_amount);
} else {
require((_index < _vault.collateralAssets.length) && (_index < _vault.collateralAmounts.length), ""V8"");
address existingCollateral = _vault.collateralAssets[_index];
require((existingCollateral == _collateralAsset) || (existingCollateral == address(0)), ""V9"");
_vault.collateralAmounts[_index] = _vault.collateralAmounts[_index].add(_amount);
_vault.collateralAssets[_index] = _collateralAsset;
}
}
| function totalShortAmount() external returns (uint256) {
uint256 total = 0;
for (uint256 i = 0; i < vault.shortAmounts.length; i++) {
total = total.add(vault.shortAmounts[i]);
}
return total;
}
",./opyn_gamma_protocol/specs/MarginVault.spec,opyn_gamma_protocol,,Yes,,"Functionality: Manage the composition of a financial vault by adding short, long positions, and collateral. It ensures positions and collateral are validly indexed and amounts are non-zero before updating or adding them. Additionally, it calculates the total amount of short positions within the vault."
bac57955ecb800bfe75fc177616b4b39,1967 | 1968,rule,settleVault,52,72,settleVault | getProceed,"rule settleVault (address owner, uint256 vaultId, uint256 index, address oToken, address to, address collateral) {
env e;
require oToken == shortOtoken;
require collateral == collateralToken;
require getVaultShortOtoken(owner, vaultId, 0) == oToken;
require getVaultCollateralAsset(owner, vaultId, 0) == collateral;
require to != pool;
uint256 supplyBefore = shortOtoken.totalSupply();
uint256 amountRemoved = getProceed(owner, vaultId);
uint256 poolBalanceBefore = collateralToken.balanceOf(pool);
sinvoke settleVault(e, owner, vaultId, to);
uint256 supplyAfter = shortOtoken.totalSupply();
uint256 poolBalanceAfter = collateralToken.balanceOf(pool);
assert supplyAfter == supplyBefore;
assert poolBalanceAfter != poolBalanceBefore => (poolBalanceBefore - poolBalanceAfter == amountRemoved);
}
","settleVault (Lines 360-367), | getProceed (Lines 467-475), "," function settleVault(
address owner,
uint256 vaultId,
address to
) external {
Actions.SettleVaultArgs memory args = Actions.SettleVaultArgs({owner: owner, vaultId: vaultId, to: to});
_settleVault(args);
}
| function getProceed(address _owner, uint256 _vaultId) external view returns (uint256) {
(MarginVault.Vault memory vault, uint256 typeVault, ) = getVaultWithDetails(_owner, _vaultId);
(uint256 netValue, bool isExcess) = calculator.getExcessCollateral(vault, typeVault);
if (!isExcess) return 0;
return netValue;
}
",./opyn_gamma_protocol/specs/controller.spec,opyn_gamma_protocol,,Yes,,"Functionality: Enable the settlement of a user's vault by specifying the vault owner, the vault's ID, and the destination address for the settlement process. Additionally, calculate and return the net value of excess collateral in a vault, if any, for a given vault owned by a user."
f10873924b8c60246813e7ff872ad5fd,1722 | 1723 | 1724,rule,where,71,89,addShort | addLong | addCollateral,"This is a parametic rule where f is any of the external/public functions of the contract
*/
rule changeToOneEntity(uint256 shortIndex, uint256 longIndex, uint256 collateralIndex, method f ) {
requireInvariant validVault();
invariant validVault() longAmountLength() == longOtokensLength() &&
shortAmountLength() == shortOtokensLength() &&
collateralAmountLength() == collateralAssetsLength()
invariant validEntityIndex(uint256 index)
(getLongAmount(index) > 0 <=> getLongOtoken(index) != 0) &&
(getShortAmount(index) > 0 <=> getShortOtoken(index) != 0) &&
(getCollateralAmount(index) > 0 <=> getCollateralAsset(index) != 0)
{
preserved addLong(address asset, uint256 amt, uint256 _index)
{
requireInvariant validEntityIndex(_index);
requireInvariant validEntityIndex(index);
require asset != ADDRESSZERO();
}
preserved addShort(address asset, uint256 amt, uint256 _index)
preserved addCollateral(address asset, uint256 amt, uint256 _index)
}
uint256 longAmountBefore = getLongAmount(longIndex);
uint256 shortAmountBefore = getShortAmount(shortIndex);
uint256 collateralAmountBefore = getCollateralAmount(collateralIndex);
calldataarg args;
env e;
sinvoke f(e,args);
uint256 longAmountAfter = getLongAmount(longIndex);
uint256 shortAmountAfter = getShortAmount(shortIndex);
uint256 collateralAmountAfter = getCollateralAmount(collateralIndex);
assert (longAmountBefore != longAmountAfter => (shortAmountBefore == shortAmountAfter && collateralAmountBefore == collateralAmountAfter)) &&
(shortAmountBefore != shortAmountAfter => (longAmountBefore == longAmountAfter && collateralAmountBefore == collateralAmountAfter)) &&
(collateralAmountBefore != collateralAmountAfter => (longAmountBefore == longAmountAfter && shortAmountBefore == shortAmountAfter));
","addShort (Lines 57-78), | addLong (Lines 112-133), | addCollateral (Lines 167-188), "," function addShort(
Vault storage _vault,
address _shortOtoken,
uint256 _amount,
uint256 _index
) external {
require(_amount > 0, ""V1"");
// valid indexes in any array are between 0 and array.length - 1.
// if adding an amount to an preexisting short oToken, check that _index is in the range of 0->length-1
if ((_index == _vault.shortOtokens.length) && (_index == _vault.shortAmounts.length)) {
_vault.shortOtokens.push(_shortOtoken);
_vault.shortAmounts.push(_amount);
} else {
require((_index < _vault.shortOtokens.length) && (_index < _vault.shortAmounts.length), ""V2"");
address existingShort = _vault.shortOtokens[_index];
require((existingShort == _shortOtoken) || (existingShort == address(0)), ""V3"");
_vault.shortAmounts[_index] = _vault.shortAmounts[_index].add(_amount);
_vault.shortOtokens[_index] = _shortOtoken;
}
}
| function addLong(
Vault storage _vault,
address _longOtoken,
uint256 _amount,
uint256 _index
) external {
require(_amount > 0, ""V4"");
// valid indexes in any array are between 0 and array.length - 1.
// if adding an amount to an preexisting short oToken, check that _index is in the range of 0->length-1
if ((_index == _vault.longOtokens.length) && (_index == _vault.longAmounts.length)) {
_vault.longOtokens.push(_longOtoken);
_vault.longAmounts.push(_amount);
} else {
require((_index < _vault.longOtokens.length) && (_index < _vault.longAmounts.length), ""V5"");
address existingLong = _vault.longOtokens[_index];
require((existingLong == _longOtoken) || (existingLong == address(0)), ""V6"");
_vault.longAmounts[_index] = _vault.longAmounts[_index].add(_amount);
_vault.longOtokens[_index] = _longOtoken;
}
}
| function addCollateral(
Vault storage _vault,
address _collateralAsset,
uint256 _amount,
uint256 _index
) external {
require(_amount > 0, ""V7"");
// valid indexes in any array are between 0 and array.length - 1.
// if adding an amount to an preexisting short oToken, check that _index is in the range of 0->length-1
if ((_index == _vault.collateralAssets.length) && (_index == _vault.collateralAmounts.length)) {
_vault.collateralAssets.push(_collateralAsset);
_vault.collateralAmounts.push(_amount);
} else {
require((_index < _vault.collateralAssets.length) && (_index < _vault.collateralAmounts.length), ""V8"");
address existingCollateral = _vault.collateralAssets[_index];
require((existingCollateral == _collateralAsset) || (existingCollateral == address(0)), ""V9"");
_vault.collateralAmounts[_index] = _vault.collateralAmounts[_index].add(_amount);
_vault.collateralAssets[_index] = _collateralAsset;
}
}
",./opyn_gamma_protocol/specs/MarginVault.spec,opyn_gamma_protocol,,Yes,,"Functionality: The code defines three functions to add short positions, long positions, and collateral to a structured data type called a vault. Each function validates input, checks if it's adding to an existing position or introducing a new one, and then updates the vault with the specified amount and asset type."
f0f9f49ffb6aedfa59f3920098039328,1833 | 1834 | 1835 | 1836 | 1841,rule,inverseAddRemoveShort,225,232,addShort | removeShort | addLong | addCollateral | totalShortAmount,"rule inverseAddRemoveShort(address shortOtoken, uint256 x, uint256 index)
{
requireInvariant validVault();
invariant validVault() longAmountLength() == longOtokensLength() &&
shortAmountLength() == shortOtokensLength() &&
collateralAmountLength() == collateralAssetsLength()
invariant validEntityIndex(uint256 index)
(getLongAmount(index) > 0 <=> getLongOtoken(index) != 0) &&
(getShortAmount(index) > 0 <=> getShortOtoken(index) != 0) &&
(getCollateralAmount(index) > 0 <=> getCollateralAsset(index) != 0)
preserved addLong(address asset, uint256 amt, uint256 _index)
{
requireInvariant validEntityIndex(_index);
requireInvariant validEntityIndex(index);
require asset != ADDRESSZERO();
}
preserved addShort(address asset, uint256 amt, uint256 _index)
preserved addCollateral(address asset, uint256 amt, uint256 _index)
}
uint256 shortAmountBefore = totalShortAmount();
sinvoke addShort(shortOtoken, x, index);
invoke removeShort(shortOtoken, x, index);
assert !lastReverted && totalShortAmount() == shortAmountBefore, ""removeShort is not inverse of addShort"";
","addShort (Lines 57-78), | removeShort (Lines 87-103), | addLong (Lines 112-133), | addCollateral (Lines 167-188), | totalShortAmount (Lines 91-97), "," function addShort(
Vault storage _vault,
address _shortOtoken,
uint256 _amount,
uint256 _index
) external {
require(_amount > 0, ""V1"");
// valid indexes in any array are between 0 and array.length - 1.
// if adding an amount to an preexisting short oToken, check that _index is in the range of 0->length-1
if ((_index == _vault.shortOtokens.length) && (_index == _vault.shortAmounts.length)) {
_vault.shortOtokens.push(_shortOtoken);
_vault.shortAmounts.push(_amount);
} else {
require((_index < _vault.shortOtokens.length) && (_index < _vault.shortAmounts.length), ""V2"");
address existingShort = _vault.shortOtokens[_index];
require((existingShort == _shortOtoken) || (existingShort == address(0)), ""V3"");
_vault.shortAmounts[_index] = _vault.shortAmounts[_index].add(_amount);
_vault.shortOtokens[_index] = _shortOtoken;
}
}
| function removeShort(
Vault storage _vault,
address _shortOtoken,
uint256 _amount,
uint256 _index
) external {
// check that the removed short oToken exists in the vault at the specified index
require(_index < _vault.shortOtokens.length, ""V2"");
require(_vault.shortOtokens[_index] == _shortOtoken, ""V3"");
uint256 newShortAmount = _vault.shortAmounts[_index].sub(_amount);
if (newShortAmount == 0) {
delete _vault.shortOtokens[_index];
}
_vault.shortAmounts[_index] = newShortAmount;
}
| function addLong(
Vault storage _vault,
address _longOtoken,
uint256 _amount,
uint256 _index
) external {
require(_amount > 0, ""V4"");
// valid indexes in any array are between 0 and array.length - 1.
// if adding an amount to an preexisting short oToken, check that _index is in the range of 0->length-1
if ((_index == _vault.longOtokens.length) && (_index == _vault.longAmounts.length)) {
_vault.longOtokens.push(_longOtoken);
_vault.longAmounts.push(_amount);
} else {
require((_index < _vault.longOtokens.length) && (_index < _vault.longAmounts.length), ""V5"");
address existingLong = _vault.longOtokens[_index];
require((existingLong == _longOtoken) || (existingLong == address(0)), ""V6"");
_vault.longAmounts[_index] = _vault.longAmounts[_index].add(_amount);
_vault.longOtokens[_index] = _longOtoken;
}
}
| function addCollateral(
Vault storage _vault,
address _collateralAsset,
uint256 _amount,
uint256 _index
) external {
require(_amount > 0, ""V7"");
// valid indexes in any array are between 0 and array.length - 1.
// if adding an amount to an preexisting short oToken, check that _index is in the range of 0->length-1
if ((_index == _vault.collateralAssets.length) && (_index == _vault.collateralAmounts.length)) {
_vault.collateralAssets.push(_collateralAsset);
_vault.collateralAmounts.push(_amount);
} else {
require((_index < _vault.collateralAssets.length) && (_index < _vault.collateralAmounts.length), ""V8"");
address existingCollateral = _vault.collateralAssets[_index];
require((existingCollateral == _collateralAsset) || (existingCollateral == address(0)), ""V9"");
_vault.collateralAmounts[_index] = _vault.collateralAmounts[_index].add(_amount);
_vault.collateralAssets[_index] = _collateralAsset;
}
}
| function totalShortAmount() external returns (uint256) {
uint256 total = 0;
for (uint256 i = 0; i < vault.shortAmounts.length; i++) {
total = total.add(vault.shortAmounts[i]);
}
return total;
}
",./opyn_gamma_protocol/specs/MarginVault.spec,opyn_gamma_protocol,,Yes,,"Functionality: Manage the composition of a financial Vault by adding or removing short positions, long positions, and collateral assets through specific operations that validate the transaction's index and amount, ensuring adherence to the vault's current state and structure constraints."
ea3d83ed976940e0ddc7cfb8b3596b17,2092 | 2093,rule,callOptionsPreExpiry,449,595,shortOtoken.havocTotalSupply | havocVault,"rule callOptionsPreExpiry(
address owner,
uint256 vaultId,
uint256 index,
address asset,
uint256 _shortAmount,
uint256 _longAmount,
uint256 _collateral,
uint256 _poolAssetBalance,
uint256 _poolShortOtokenBalance,
uint256 _poolLongOtokenBalance,
uint256 _totalSupplyShortOtoken,
uint256 _totalSupplyLongOtoken,
uint256 shortPrice,
uint256 longPrice,
uint256 shortAmount_,
uint256 longAmount_,
uint256 collateral_,
uint256 poolAssetBalance_,
uint256 poolShortOtokenBalance_,
uint256 poolLongOtokenBalance_,
uint256 totalSupplyShortOtoken_,
uint256 totalSupplyLongOtoken_
) {
links();
env e;
require shortOtoken == getVaultShortOtoken(owner, vaultId, index);
require longOtoken == getVaultLongOtoken(owner, vaultId, index);
require collateralToken == getVaultCollateralAsset(owner, vaultId, index);
require asset == collateralToken;
require _shortAmount == getVaultShortAmount(owner, vaultId, index);
require _longAmount == getVaultLongAmount(owner, vaultId, index);
require _collateral == getVaultCollateralAmount(owner, vaultId, index);
require _poolAssetBalance == pool.getStoredBalance(asset);
require _poolShortOtokenBalance == pool.getStoredBalance(shortOtoken);
require _poolLongOtokenBalance == pool.getStoredBalance(longOtoken);
require _totalSupplyShortOtoken == assetTotalSupply(shortOtoken);
require _totalSupplyLongOtoken == assetTotalSupply(longOtoken);
require shortPrice == shortOtoken.strikePrice();
require longPrice == longOtoken.strikePrice();
// assume before expiry
require !isVaultExpired(e, owner, vaultId);
This rule is proven relaying on:
1. a proof with Mathemtic minValue to compute the debt a vault
2. a rule that shows that one vault is changed at a time
3. rules that show valid balances of the system with respect to vault changes
Due to complexity for the SMT solver the rules is split to three cases of a valid vault:
if( longAmount <= shortAmount && longAmount * longPrice <= shortAmount * shortPrice ) //case 1
debt = shortAmount * shortPrice - longAmount * longPrice ;
else if ( longAmount > shortAmount_ && longPrice < shortPrice) //case 2
debt = shortAmount * (shortPrice - longPrice) ;
else //case 3
debt = 0;
*/
rule putOptionsPreExpiryCase1StartingWithAllCases(
// assume before expiry
// assume no bankruptcy
mathint _obligation = (_totalSupplyShortOtoken - _poolShortOtokenBalance ) * shortPrice
+ (_totalSupplyLongOtoken - _poolLongOtokenBalance ) * longPrice;
require _poolAssetBalance >= _obligation ;
// based on Mathematica proof:
mathint _debt = 0;
if( _longAmount <= _shortAmount && ( _longAmount * longPrice <= _shortAmount * shortPrice )) {
_debt = _shortAmount * shortPrice - _longAmount * longPrice ;
} else if ( _longAmount > _shortAmount && longPrice < shortPrice) {
_debt = _shortAmount * (shortPrice - longPrice) ;
}
//assume vault is in a valid state
require _collateral >= _debt ;
//assume valid state based on valid balances rules
require ( _totalSupplyShortOtoken >= _poolShortOtokenBalance + _shortAmount) &&
_totalSupplyLongOtoken >= _poolLongOtokenBalance &&
_poolLongOtokenBalance >= _longAmount &&
_poolAssetBalance >= _collateral ;
//compute excess collateral of other vaults
mathint _obligationWithoutThisVault = (_totalSupplyShortOtoken - _poolShortOtokenBalance - _shortAmount) * shortPrice
+ (_totalSupplyLongOtoken - _poolLongOtokenBalance +_longAmount ) * longPrice ;
// assume excess collateral of other vaults is not cover by this vault's collateral
require ( _poolAssetBalance - _collateral >= _obligationWithoutThisVault );
// simulate many operations in one step
uint256 newShortAmount;
uint256 newLongAmount;
uint256 newcollateralAmount;
uint256 newTotalSupply;
sinvoke havocVault(owner, vaultId, index, newShortAmount, newLongAmount, newcollateralAmount);
sinvoke pool.havocSystemBalance(longOtoken);
sinvoke pool.havocSystemBalance(asset);
sinvoke shortOtoken.havocTotalSupply(newTotalSupply);
require shortAmount_ == getVaultShortAmount(owner, vaultId, index);
require longAmount_ == getVaultLongAmount(owner, vaultId, index);
require collateral_ == getVaultCollateralAmount(owner, vaultId, index);
require poolAssetBalance_ == pool.getStoredBalance(asset);
require poolShortOtokenBalance_ == pool.getStoredBalance(shortOtoken);
require poolLongOtokenBalance_ == pool.getStoredBalance(longOtoken);
require totalSupplyShortOtoken_ == assetTotalSupply(shortOtoken);
require totalSupplyLongOtoken_ == assetTotalSupply(longOtoken);
mathint obligation_ = (totalSupplyShortOtoken_ - poolShortOtokenBalance_ ) * shortPrice
+ (totalSupplyLongOtoken_ - poolLongOtokenBalance_ ) * longPrice ;
//assume isValid vault case 1
require longAmount_ <= shortAmount_ && longAmount_ * longPrice <= shortAmount_ * shortPrice ;
mathint debt_ = shortAmount_ * shortPrice - longAmount_ * longPrice ;
require collateral_ >= debt_ ;
// valid state - need to prove this as in invariant also when the vault is not valid should hold
require (totalSupplyShortOtoken_ >= poolShortOtokenBalance_ + shortAmount_) &&
totalSupplyLongOtoken_ >= poolLongOtokenBalance_ &&
poolLongOtokenBalance_ >= longAmount_ &&
poolAssetBalance_ >= collateral_ ;
// assume changes are coherent based on total required rules
require collateral_ - _collateral == poolAssetBalance_- _poolAssetBalance;
require longAmount_ - _longAmount == poolLongOtokenBalance_ - _poolLongOtokenBalance;
require shortAmount_ - _shortAmount == totalSupplyShortOtoken_ - _totalSupplyShortOtoken;
//verify no bankruptchy
assert poolAssetBalance_ >= obligation_ ;
}
rule putOptionsPreExpiryCase2StartingWithAllCases(
//assume isValid vault case 2
require longAmount_ > shortAmount_ && longPrice < shortPrice ;
mathint _obligation = (_totalSupplyShortOtoken - _poolShortOtokenBalance )
+ (_totalSupplyLongOtoken - _poolLongOtokenBalance ) ;
require (_poolAssetBalance >= _obligation) ;
mathint temp = _shortAmount - _longAmount;
if temp > 0 {
_debt = temp;
/**
* (long strike - short strike) * short amount
* calculate ----------------------------------------------
* long strike
*/
mathint temp2 = (longPrice - shortPrice) * _shortAmount / longPrice;
mathint _debt2;
if temp2 > _debt {
_debt2 = temp2;
} else {
_debt2 = _debt;
require _collateral >= _debt2 ;
////assume valid state based on valid balances rules
_totalSupplyLongOtoken >= _poolLongOtokenBalance &&
_poolAssetBalance >= _collateral;
//compute excess collateral of other vaults.
mathint _obligationWithoutThisVault = (_totalSupplyShortOtoken - _poolShortOtokenBalance - _shortAmount)
+ (_totalSupplyLongOtoken - _poolLongOtokenBalance +_longAmount ) ;
//assume vault is in a vaild state
mathint obligation_ = (totalSupplyShortOtoken_ - poolShortOtokenBalance_ )
+ (totalSupplyLongOtoken_ - poolLongOtokenBalance_ ) ;
mathint debt_ = 0;
mathint temp3 = shortAmount_ - longAmount_;
if temp3 > 0 {
debt_ = temp3;
/**
* (long strike - short strike) * short amount
* calculate ----------------------------------------------
* long strike
*/
mathint temp4 = (longPrice - shortPrice) * shortAmount_ / longPrice;
mathint debt_2;
if temp4 > debt_ {
debt_2 = temp4;
debt_2 = debt_;
require ( collateral_ >= debt_2 );
// valid state
totalSupplyLongOtoken_ >= poolLongOtokenBalance_ &&
poolLongOtokenBalance_ >= longAmount_ &&
poolAssetBalance_ >= collateral_ ;
","havocTotalSupply (Lines 5-7), | havocVault (Lines 24-36), "," function havocTotalSupply(uint256 newVal) public {
_totalSupply = newVal;
}
| function havocVault(
address owner,
uint256 vaultId,
uint256 i,
uint256 newShortAmount,
uint256 newLongAmount,
uint256 newcollateralAmount
) external {
MarginVault.Vault storage vault = cheapGetVault(owner, vaultId);
vault.shortAmounts[i] = newShortAmount;
vault.longAmounts[i] = newLongAmount;
vault.collateralAmounts[i] = newcollateralAmount;
}
",./opyn_gamma_protocol/specs/NoBankruptcy.spec,opyn_gamma_protocol,,Yes,,"Functionality: Update the total supply of a smart contract's token and modify specific properties (short amounts, long amounts, and collateral amounts) of a particular vault identified by its owner and ID within a decentralized finance (DeFi) platform or protocol."
f10873924b8c60246813e7ff872ad5fd,1722 | 1723 | 1724,rule,where,71,89,addShort | addLong | addCollateral,"This is a parametic rule where f is any of the external/public functions of the contract
*/
rule changeToOneEntity(uint256 shortIndex, uint256 longIndex, uint256 collateralIndex, method f ) {
requireInvariant validVault();
invariant validVault() longAmountLength() == longOtokensLength() &&
shortAmountLength() == shortOtokensLength() &&
collateralAmountLength() == collateralAssetsLength()
invariant validEntityIndex(uint256 index)
(getLongAmount(index) > 0 <=> getLongOtoken(index) != 0) &&
(getShortAmount(index) > 0 <=> getShortOtoken(index) != 0) &&
(getCollateralAmount(index) > 0 <=> getCollateralAsset(index) != 0)
{
preserved addLong(address asset, uint256 amt, uint256 _index)
{
requireInvariant validEntityIndex(_index);
requireInvariant validEntityIndex(index);
require asset != ADDRESSZERO();
}
preserved addShort(address asset, uint256 amt, uint256 _index)
preserved addCollateral(address asset, uint256 amt, uint256 _index)
}
uint256 longAmountBefore = getLongAmount(longIndex);
uint256 shortAmountBefore = getShortAmount(shortIndex);
uint256 collateralAmountBefore = getCollateralAmount(collateralIndex);
calldataarg args;
env e;
sinvoke f(e,args);
uint256 longAmountAfter = getLongAmount(longIndex);
uint256 shortAmountAfter = getShortAmount(shortIndex);
uint256 collateralAmountAfter = getCollateralAmount(collateralIndex);
assert (longAmountBefore != longAmountAfter => (shortAmountBefore == shortAmountAfter && collateralAmountBefore == collateralAmountAfter)) &&
(shortAmountBefore != shortAmountAfter => (longAmountBefore == longAmountAfter && collateralAmountBefore == collateralAmountAfter)) &&
(collateralAmountBefore != collateralAmountAfter => (longAmountBefore == longAmountAfter && shortAmountBefore == shortAmountAfter));
","addShort (Lines 57-78), | addLong (Lines 112-133), | addCollateral (Lines 167-188), "," function addShort(
Vault storage _vault,
address _shortOtoken,
uint256 _amount,
uint256 _index
) external {
require(_amount > 0, ""V1"");
// valid indexes in any array are between 0 and array.length - 1.
// if adding an amount to an preexisting short oToken, check that _index is in the range of 0->length-1
if ((_index == _vault.shortOtokens.length) && (_index == _vault.shortAmounts.length)) {
_vault.shortOtokens.push(_shortOtoken);
_vault.shortAmounts.push(_amount);
} else {
require((_index < _vault.shortOtokens.length) && (_index < _vault.shortAmounts.length), ""V2"");
address existingShort = _vault.shortOtokens[_index];
require((existingShort == _shortOtoken) || (existingShort == address(0)), ""V3"");
_vault.shortAmounts[_index] = _vault.shortAmounts[_index].add(_amount);
_vault.shortOtokens[_index] = _shortOtoken;
}
}
| function addLong(
Vault storage _vault,
address _longOtoken,
uint256 _amount,
uint256 _index
) external {
require(_amount > 0, ""V4"");
// valid indexes in any array are between 0 and array.length - 1.
// if adding an amount to an preexisting short oToken, check that _index is in the range of 0->length-1
if ((_index == _vault.longOtokens.length) && (_index == _vault.longAmounts.length)) {
_vault.longOtokens.push(_longOtoken);
_vault.longAmounts.push(_amount);
} else {
require((_index < _vault.longOtokens.length) && (_index < _vault.longAmounts.length), ""V5"");
address existingLong = _vault.longOtokens[_index];
require((existingLong == _longOtoken) || (existingLong == address(0)), ""V6"");
_vault.longAmounts[_index] = _vault.longAmounts[_index].add(_amount);
_vault.longOtokens[_index] = _longOtoken;
}
}
| function addCollateral(
Vault storage _vault,
address _collateralAsset,
uint256 _amount,
uint256 _index
) external {
require(_amount > 0, ""V7"");
// valid indexes in any array are between 0 and array.length - 1.
// if adding an amount to an preexisting short oToken, check that _index is in the range of 0->length-1
if ((_index == _vault.collateralAssets.length) && (_index == _vault.collateralAmounts.length)) {
_vault.collateralAssets.push(_collateralAsset);
_vault.collateralAmounts.push(_amount);
} else {
require((_index < _vault.collateralAssets.length) && (_index < _vault.collateralAmounts.length), ""V8"");
address existingCollateral = _vault.collateralAssets[_index];
require((existingCollateral == _collateralAsset) || (existingCollateral == address(0)), ""V9"");
_vault.collateralAmounts[_index] = _vault.collateralAmounts[_index].add(_amount);
_vault.collateralAssets[_index] = _collateralAsset;
}
}
",./opyn_gamma_protocol/specs/MarginVault.spec,opyn_gamma_protocol,,Yes,,"Functionality: The code extends the functionality of a cryptocurrency vault by allowing the addition of short positions, long positions, and collateral, ensuring validity through checks on amounts, indices, and asset consistency, while leveraging existing positions if applicable."
ab45c728ea5bd7fbe18def86689e2164,2031 | 2032,invariant,also,428,595,shortOtoken.havocTotalSupply | havocVault," // valid state - need to prove this as in invariant also when the vault is not valid should hold
This rule is proven relaying on:
1. a proof with Mathemtic minValue to compute the debt a vault
2. a rule that shows that one vault is changed at a time
3. rules that show valid balances of the system with respect to vault changes
Due to complexity for the SMT solver the rules is split to three cases of a valid vault:
if( longAmount <= shortAmount && longAmount * longPrice <= shortAmount * shortPrice ) //case 1
debt = shortAmount * shortPrice - longAmount * longPrice ;
else if ( longAmount > shortAmount_ && longPrice < shortPrice) //case 2
debt = shortAmount * (shortPrice - longPrice) ;
else //case 3
debt = 0;
*/
rule putOptionsPreExpiryCase1StartingWithAllCases(
address owner,
uint256 vaultId,
uint256 index,
address asset,
uint256 _shortAmount,
uint256 _longAmount,
uint256 _collateral,
uint256 _poolAssetBalance,
uint256 _poolShortOtokenBalance,
uint256 _poolLongOtokenBalance,
uint256 _totalSupplyShortOtoken,
uint256 _totalSupplyLongOtoken,
uint256 shortPrice,
uint256 longPrice,
uint256 shortAmount_,
uint256 longAmount_,
uint256 collateral_,
uint256 poolAssetBalance_,
uint256 poolShortOtokenBalance_,
uint256 poolLongOtokenBalance_,
uint256 totalSupplyShortOtoken_,
uint256 totalSupplyLongOtoken_
) {
links();
env e;
require shortOtoken == getVaultShortOtoken(owner, vaultId, index);
require longOtoken == getVaultLongOtoken(owner, vaultId, index);
require collateralToken == getVaultCollateralAsset(owner, vaultId, index);
require asset == collateralToken;
require _shortAmount == getVaultShortAmount(owner, vaultId, index);
require _longAmount == getVaultLongAmount(owner, vaultId, index);
require _collateral == getVaultCollateralAmount(owner, vaultId, index);
require _poolAssetBalance == pool.getStoredBalance(asset);
require _poolShortOtokenBalance == pool.getStoredBalance(shortOtoken);
require _poolLongOtokenBalance == pool.getStoredBalance(longOtoken);
require _totalSupplyShortOtoken == assetTotalSupply(shortOtoken);
require _totalSupplyLongOtoken == assetTotalSupply(longOtoken);
require shortPrice == shortOtoken.strikePrice();
require longPrice == longOtoken.strikePrice();
// assume before expiry
require !isVaultExpired(e, owner, vaultId);
// assume no bankruptcy
mathint _obligation = (_totalSupplyShortOtoken - _poolShortOtokenBalance ) * shortPrice
+ (_totalSupplyLongOtoken - _poolLongOtokenBalance ) * longPrice;
require _poolAssetBalance >= _obligation ;
// based on Mathematica proof:
mathint _debt = 0;
if( _longAmount <= _shortAmount && ( _longAmount * longPrice <= _shortAmount * shortPrice )) {
_debt = _shortAmount * shortPrice - _longAmount * longPrice ;
} else if ( _longAmount > _shortAmount && longPrice < shortPrice) {
_debt = _shortAmount * (shortPrice - longPrice) ;
}
//assume vault is in a valid state
require _collateral >= _debt ;
//assume valid state based on valid balances rules
require ( _totalSupplyShortOtoken >= _poolShortOtokenBalance + _shortAmount) &&
_totalSupplyLongOtoken >= _poolLongOtokenBalance &&
_poolLongOtokenBalance >= _longAmount &&
_poolAssetBalance >= _collateral ;
//compute excess collateral of other vaults
mathint _obligationWithoutThisVault = (_totalSupplyShortOtoken - _poolShortOtokenBalance - _shortAmount) * shortPrice
+ (_totalSupplyLongOtoken - _poolLongOtokenBalance +_longAmount ) * longPrice ;
// assume excess collateral of other vaults is not cover by this vault's collateral
require ( _poolAssetBalance - _collateral >= _obligationWithoutThisVault );
// simulate many operations in one step
uint256 newShortAmount;
uint256 newLongAmount;
uint256 newcollateralAmount;
uint256 newTotalSupply;
sinvoke havocVault(owner, vaultId, index, newShortAmount, newLongAmount, newcollateralAmount);
sinvoke pool.havocSystemBalance(longOtoken);
sinvoke pool.havocSystemBalance(asset);
sinvoke shortOtoken.havocTotalSupply(newTotalSupply);
require shortAmount_ == getVaultShortAmount(owner, vaultId, index);
require longAmount_ == getVaultLongAmount(owner, vaultId, index);
require collateral_ == getVaultCollateralAmount(owner, vaultId, index);
require poolAssetBalance_ == pool.getStoredBalance(asset);
require poolShortOtokenBalance_ == pool.getStoredBalance(shortOtoken);
require poolLongOtokenBalance_ == pool.getStoredBalance(longOtoken);
require totalSupplyShortOtoken_ == assetTotalSupply(shortOtoken);
require totalSupplyLongOtoken_ == assetTotalSupply(longOtoken);
mathint obligation_ = (totalSupplyShortOtoken_ - poolShortOtokenBalance_ ) * shortPrice
+ (totalSupplyLongOtoken_ - poolLongOtokenBalance_ ) * longPrice ;
//assume isValid vault case 1
require longAmount_ <= shortAmount_ && longAmount_ * longPrice <= shortAmount_ * shortPrice ;
mathint debt_ = shortAmount_ * shortPrice - longAmount_ * longPrice ;
require collateral_ >= debt_ ;
require (totalSupplyShortOtoken_ >= poolShortOtokenBalance_ + shortAmount_) &&
totalSupplyLongOtoken_ >= poolLongOtokenBalance_ &&
poolLongOtokenBalance_ >= longAmount_ &&
poolAssetBalance_ >= collateral_ ;
// assume changes are coherent based on total required rules
require collateral_ - _collateral == poolAssetBalance_- _poolAssetBalance;
require longAmount_ - _longAmount == poolLongOtokenBalance_ - _poolLongOtokenBalance;
require shortAmount_ - _shortAmount == totalSupplyShortOtoken_ - _totalSupplyShortOtoken;
//verify no bankruptchy
assert poolAssetBalance_ >= obligation_ ;
}
/** For put options before expiry (strong bound):
obligation(o) 闁 (o.totalSupply() - storedBalance(o))
The debt computation is also different
rule callOptionsPreExpiry(
// assume before expiry
mathint _obligation = (_totalSupplyShortOtoken - _poolShortOtokenBalance )
+ (_totalSupplyLongOtoken - _poolLongOtokenBalance ) ;
require (_poolAssetBalance >= _obligation) ;
mathint temp = _shortAmount - _longAmount;
if temp > 0 {
_debt = temp;
/**
* (long strike - short strike) * short amount
* calculate ----------------------------------------------
* long strike
*/
mathint temp2 = (longPrice - shortPrice) * _shortAmount / longPrice;
mathint _debt2;
if temp2 > _debt {
_debt2 = temp2;
} else {
_debt2 = _debt;
require _collateral >= _debt2 ;
////assume valid state based on valid balances rules
_totalSupplyLongOtoken >= _poolLongOtokenBalance &&
_poolAssetBalance >= _collateral;
//compute excess collateral of other vaults.
mathint _obligationWithoutThisVault = (_totalSupplyShortOtoken - _poolShortOtokenBalance - _shortAmount)
+ (_totalSupplyLongOtoken - _poolLongOtokenBalance +_longAmount ) ;
//assume vault is in a vaild state
mathint obligation_ = (totalSupplyShortOtoken_ - poolShortOtokenBalance_ )
+ (totalSupplyLongOtoken_ - poolLongOtokenBalance_ ) ;
mathint debt_ = 0;
mathint temp3 = shortAmount_ - longAmount_;
if temp3 > 0 {
debt_ = temp3;
/**
* (long strike - short strike) * short amount
* calculate ----------------------------------------------
* long strike
*/
mathint temp4 = (longPrice - shortPrice) * shortAmount_ / longPrice;
mathint debt_2;
if temp4 > debt_ {
debt_2 = temp4;
debt_2 = debt_;
require ( collateral_ >= debt_2 );
// valid state
totalSupplyLongOtoken_ >= poolLongOtokenBalance_ &&
poolLongOtokenBalance_ >= longAmount_ &&
poolAssetBalance_ >= collateral_ ;
","havocTotalSupply (Lines 5-7), | havocVault (Lines 24-36), "," function havocTotalSupply(uint256 newVal) public {
_totalSupply = newVal;
}
| function havocVault(
address owner,
uint256 vaultId,
uint256 i,
uint256 newShortAmount,
uint256 newLongAmount,
uint256 newcollateralAmount
) external {
MarginVault.Vault storage vault = cheapGetVault(owner, vaultId);
vault.shortAmounts[i] = newShortAmount;
vault.longAmounts[i] = newLongAmount;
vault.collateralAmounts[i] = newcollateralAmount;
}
",./opyn_gamma_protocol/specs/NoBankruptcy.spec,opyn_gamma_protocol,,Yes,,"Functionality: Update the total supply of a currency and modify the amounts within a specific trader's margin vault, adjusting their short positions, long positions, and collateral amounts at a designated index, thereby allowing dynamic management of trading strategies and margin requirements."
85ea85426e0fbbed91f41eef0e3e9ef8,1988 | 1989 | 1990 | 1991,rule,optionWithdrawsRestricted,135,152,withdrawLongB | burnOtokenB | settleVault | getProceed,"rule optionWithdrawsRestricted(address owner, uint256 vaultId, uint256 index, address from, address amount, method f) {
env e;
// The pool cannot really call any of these functions
require (e.msg.sender != pool);
require (!whitelist.isWhitelistedCollateral(longOtoken));
uint256 otokenBalanceBefore = longOtoken.balanceOf(pool);
if (f.selector == burnOtokenB(address,uint256,address,uint256,uint256).selector) {
require(owner != pool);
sinvoke burnOtokenB(e, owner, vaultId, from, index, amount);
} else {
calldataarg arg;
sinvoke f(e, arg);
}
uint256 otokenBalanceAfter = longOtoken.balanceOf(pool);
// or settle vault
assert otokenBalanceAfter < otokenBalanceBefore => (f.selector == withdrawLongB(address, uint256, address, uint256, uint256).selector)
|| (f.selector == settleVault(address,uint256,address).selector);
rule settleVault (address owner, uint256 vaultId, uint256 index, address oToken, address to, address collateral) {
require oToken == shortOtoken;
require collateral == collateralToken;
require getVaultShortOtoken(owner, vaultId, 0) == oToken;
require getVaultCollateralAsset(owner, vaultId, 0) == collateral;
require to != pool;
uint256 supplyBefore = shortOtoken.totalSupply();
uint256 amountRemoved = getProceed(owner, vaultId);
uint256 poolBalanceBefore = collateralToken.balanceOf(pool);
sinvoke settleVault(e, owner, vaultId, to);
uint256 supplyAfter = shortOtoken.totalSupply();
uint256 poolBalanceAfter = collateralToken.balanceOf(pool);
assert supplyAfter == supplyBefore;
assert poolBalanceAfter != poolBalanceBefore => (poolBalanceBefore - poolBalanceAfter == amountRemoved);
}
","withdrawLongB (Lines 212-228), | burnOtokenB (Lines 325-342), | settleVault (Lines 360-367), | getProceed (Lines 467-475), "," function withdrawLongB(
address owner,
uint256 vaultId,
address to,
uint256 index,
uint256 amount
) external {
Actions.WithdrawArgs memory args = Actions.WithdrawArgs({
owner: owner,
vaultId: vaultId,
to: to,
asset: anOtokenB,
index: index,
amount: amount
});
_withdrawLong(args);
}
| function burnOtokenB(
address owner,
uint256 vaultId,
address from,
uint256 index,
uint256 amount
) external {
require(smallVault(owner, vaultId, 1));
Actions.BurnArgs memory args = Actions.BurnArgs({
owner: owner,
vaultId: vaultId,
from: from,
otoken: anOtokenB,
index: index,
amount: amount
});
_burnOtoken(args);
}
| function settleVault(
address owner,
uint256 vaultId,
address to
) external {
Actions.SettleVaultArgs memory args = Actions.SettleVaultArgs({owner: owner, vaultId: vaultId, to: to});
_settleVault(args);
}
| function getProceed(address _owner, uint256 _vaultId) external view returns (uint256) {
(MarginVault.Vault memory vault, uint256 typeVault, ) = getVaultWithDetails(_owner, _vaultId);
(uint256 netValue, bool isExcess) = calculator.getExcessCollateral(vault, typeVault);
if (!isExcess) return 0;
return netValue;
}
",./opyn_gamma_protocol/specs/controller.spec,opyn_gamma_protocol,,Yes,,"Functionality: Enable the manipulation and settlement of vaults containing options, specifically for withdrawing long positions, burning options, and settling vaults post-expiry. It also allows users to query the net value of a vault's excess collateral, ensuring operations respect the underlying collateralization and ownership rules."
f42822566974f4f8ba598551edb94bb1,2155 | 2158,rule,zeroMintDoesNotIncreaseBalance,154,163,mint | changeSupply,"rule zeroMintDoesNotIncreaseBalance(address user) {
env e;
requireInvariant rebasingCreditsPerTokenMustBeGreaterThan0();
// probably must assume invariant rebasingCreditsPerTokenMustBeGreaterThan0
address who;
invoke balanceOf(who);
assert !lastReverted;
}
// Requireing rebasingCreditsPerToken to be greater than zero is important
// since much of the rebasing/nonRebasing accounting will fail if it is zero.
//
// Once the contract is initialized, the rebasingCreditsPerToken should never
// again be zero, since a positive value is set in the initializer and there is a
// require statement guarding against it going back down to zero in the only
// function that updates it.
invariant rebasingCreditsPerTokenMustBeGreaterThan0()
rebasingCreditsPerToken() > 0
// a condition for changeSupply() not to revert:
// TODO: Check in init_state. probably wrong in constructor/initialization?
rule totalSupplyIntegrity(method f) {
require totalSupply() >= (rebasingCredits()*ONE()) / rebasingCreditsPerToken() + nonRebasingSupply();
requireInvariant rebasingCreditsPerTokenMustBeGreaterThan0;
// need to require that nonRebasingCreditsPerToken is < 1e18?
executeAFunction(f);
assert totalSupply() >= (rebasingCredits()*ONE()) / rebasingCreditsPerToken() + nonRebasingSupply();
uint before = balanceOf(user);
mint(e, user, 0);
uint after = balanceOf(user);
assert after == before;
","mint (Lines 42-87), | changeSupply (Lines 472-507), "," function mint(
address _asset,
uint256 _amount,
uint256 _minimumOusdAmount
) external whenNotCapitalPaused nonReentrant {
require(assets[_asset].isSupported, ""Asset is not supported"");
require(_amount > 0, ""Amount must be greater than 0"");
uint256 price = IMinMaxOracle(priceProvider).priceMin(
Helpers.getSymbol(_asset)
);
if (price > 1e8) {
price = 1e8;
}
uint256 assetDecimals = Helpers.getDecimals(_asset);
uint256 unitAdjustedDeposit = _amount.scaleBy(int8(18 - assetDecimals));
uint256 priceAdjustedDeposit = _amount.mulTruncateScale(
price.scaleBy(int8(10)), // 18-8 because oracles have 8 decimals precision
10**assetDecimals
);
if (_minimumOusdAmount > 0) {
require(
priceAdjustedDeposit >= _minimumOusdAmount,
""Mint amount lower than minimum""
);
}
emit Mint(msg.sender, priceAdjustedDeposit);
// Rebase must happen before any transfers occur.
if (unitAdjustedDeposit >= rebaseThreshold && !rebasePaused) {
_rebase();
}
// Mint matching OUSD
oUSD.mint(msg.sender, priceAdjustedDeposit);
// Transfer the deposited coins to the vault
IERC20 asset = IERC20(_asset);
asset.safeTransferFrom(msg.sender, address(this), _amount);
if (unitAdjustedDeposit >= autoAllocateThreshold) {
_allocate();
}
}
| function changeSupply(uint256 _newTotalSupply)
external
onlyVault
nonReentrant
{
require(_totalSupply > 0, ""Cannot increase 0 supply"");
if (_totalSupply == _newTotalSupply) {
emit TotalSupplyUpdated(
_totalSupply,
rebasingCredits,
rebasingCreditsPerToken
);
return;
}
_totalSupply = _newTotalSupply > MAX_SUPPLY
? MAX_SUPPLY
: _newTotalSupply;
rebasingCreditsPerToken = rebasingCredits.divPrecisely(
_totalSupply.sub(nonRebasingSupply)
);
require(rebasingCreditsPerToken > 0, ""Invalid change in supply"");
_totalSupply = rebasingCredits
.divPrecisely(rebasingCreditsPerToken)
.add(nonRebasingSupply);
emit TotalSupplyUpdated(
_totalSupply,
rebasingCredits,
rebasingCreditsPerToken
);
}
",./ousd/spec/ousd.spec,ousd,,Yes,,"Functionality: The code allows users to mint a new asset (OUSD) by depositing a supported asset, ensuring the deposited amount meets a minimum OUSD value threshold. It optionally triggers a rebase and allocation of funds based on thresholds, after adjusting for price and decimals precision. Additionally, it permits authorized entities to adjust the total supply of a system's internal credits, ensuring the new supply does not invalidate the credits-to-token ratio."
172b126d74fd4b7f46a10cdaadc8bd21,2140 | 2141,rule,changesRebaseState,79,90,rebaseOptIn | rebaseOptOut,"rule changesRebaseState(method f) {
address who;
uint8 _rebaseState = rebaseState(who);
executeAFunction(f);
uint8 rebaseState_ = rebaseState(who);
assert _rebaseState == rebaseState_
|| f.selector == rebaseOptIn().selector
|| f.selector == rebaseOptOut().selector;
}
","rebaseOptIn (Lines 424-445), | rebaseOptOut (Lines 450-464), "," function rebaseOptIn() public nonReentrant {
require(_isNonRebasingAccount(msg.sender), ""Account has not opted out"");
// Convert balance into the same amount at the current exchange rate
uint256 newCreditBalance = _creditBalances[msg.sender]
.mul(rebasingCreditsPerToken)
.div(_creditsPerToken(msg.sender));
// Decreasing non rebasing supply
nonRebasingSupply = nonRebasingSupply.sub(balanceOf(msg.sender));
_creditBalances[msg.sender] = newCreditBalance;
// Increase rebasing credits, totalSupply remains unchanged so no
// adjustment necessary
rebasingCredits = rebasingCredits.add(_creditBalances[msg.sender]);
rebaseState[msg.sender] = RebaseOptions.OptIn;
// Delete any fixed credits per token
delete nonRebasingCreditsPerToken[msg.sender];
}
| function rebaseOptOut() public nonReentrant {
require(!_isNonRebasingAccount(msg.sender), ""Account has not opted in"");
// Increase non rebasing supply
nonRebasingSupply = nonRebasingSupply.add(balanceOf(msg.sender));
// Set fixed credits per token
nonRebasingCreditsPerToken[msg.sender] = rebasingCreditsPerToken;
// Decrease rebasing credits, total supply remains unchanged so no
// adjustment necessary
rebasingCredits = rebasingCredits.sub(_creditBalances[msg.sender]);
// Mark explicitly opted out of rebasing
rebaseState[msg.sender] = RebaseOptions.OptOut;
}
",./ousd/spec/ousd.spec,ousd,,Yes,,"Functionality: Provide users the ability to opt in or out of a rebasing mechanism. When opting in, convert user's balance to the current exchange rate, adjusting the non-rebasing and rebasing supplies accordingly. For opting out, increase the non-rebasing supply and set a fixed credit per token rate, while adjusting the rebasing credits."
0ab50333e9e0f234a3fc8d7851508941,2150 | 2153,rule,mintDoesNotDecreaseBalance,143,152,mint | changeSupply,"rule mintDoesNotDecreaseBalance(address burned, uint256 amount){
env e;
requireInvariant rebasingCreditsPerTokenMustBeGreaterThan0();
// probably must assume invariant rebasingCreditsPerTokenMustBeGreaterThan0
address who;
invoke balanceOf(who);
assert !lastReverted;
}
// Requireing rebasingCreditsPerToken to be greater than zero is important
// since much of the rebasing/nonRebasing accounting will fail if it is zero.
//
// Once the contract is initialized, the rebasingCreditsPerToken should never
// again be zero, since a positive value is set in the initializer and there is a
// require statement guarding against it going back down to zero in the only
// function that updates it.
invariant rebasingCreditsPerTokenMustBeGreaterThan0()
rebasingCreditsPerToken() > 0
// a condition for changeSupply() not to revert:
// TODO: Check in init_state. probably wrong in constructor/initialization?
rule totalSupplyIntegrity(method f) {
require totalSupply() >= (rebasingCredits()*ONE()) / rebasingCreditsPerToken() + nonRebasingSupply();
requireInvariant rebasingCreditsPerTokenMustBeGreaterThan0;
// need to require that nonRebasingCreditsPerToken is < 1e18?
executeAFunction(f);
assert totalSupply() >= (rebasingCredits()*ONE()) / rebasingCreditsPerToken() + nonRebasingSupply();
uint before = balanceOf(burned);
mint(e, burned, amount);
uint after = balanceOf(burned);
assert after >= before;
","mint (Lines 42-87), | changeSupply (Lines 472-507), "," function mint(
address _asset,
uint256 _amount,
uint256 _minimumOusdAmount
) external whenNotCapitalPaused nonReentrant {
require(assets[_asset].isSupported, ""Asset is not supported"");
require(_amount > 0, ""Amount must be greater than 0"");
uint256 price = IMinMaxOracle(priceProvider).priceMin(
Helpers.getSymbol(_asset)
);
if (price > 1e8) {
price = 1e8;
}
uint256 assetDecimals = Helpers.getDecimals(_asset);
uint256 unitAdjustedDeposit = _amount.scaleBy(int8(18 - assetDecimals));
uint256 priceAdjustedDeposit = _amount.mulTruncateScale(
price.scaleBy(int8(10)), // 18-8 because oracles have 8 decimals precision
10**assetDecimals
);
if (_minimumOusdAmount > 0) {
require(
priceAdjustedDeposit >= _minimumOusdAmount,
""Mint amount lower than minimum""
);
}
emit Mint(msg.sender, priceAdjustedDeposit);
// Rebase must happen before any transfers occur.
if (unitAdjustedDeposit >= rebaseThreshold && !rebasePaused) {
_rebase();
}
// Mint matching OUSD
oUSD.mint(msg.sender, priceAdjustedDeposit);
// Transfer the deposited coins to the vault
IERC20 asset = IERC20(_asset);
asset.safeTransferFrom(msg.sender, address(this), _amount);
if (unitAdjustedDeposit >= autoAllocateThreshold) {
_allocate();
}
}
| function changeSupply(uint256 _newTotalSupply)
external
onlyVault
nonReentrant
{
require(_totalSupply > 0, ""Cannot increase 0 supply"");
if (_totalSupply == _newTotalSupply) {
emit TotalSupplyUpdated(
_totalSupply,
rebasingCredits,
rebasingCreditsPerToken
);
return;
}
_totalSupply = _newTotalSupply > MAX_SUPPLY
? MAX_SUPPLY
: _newTotalSupply;
rebasingCreditsPerToken = rebasingCredits.divPrecisely(
_totalSupply.sub(nonRebasingSupply)
);
require(rebasingCreditsPerToken > 0, ""Invalid change in supply"");
_totalSupply = rebasingCredits
.divPrecisely(rebasingCreditsPerToken)
.add(nonRebasingSupply);
emit TotalSupplyUpdated(
_totalSupply,
rebasingCredits,
rebasingCreditsPerToken
);
}
",./ousd/spec/ousd.spec,ousd,,Yes,,"Functionality: Allow users to mint a stablecoin (OUSD) by depositing supported assets, ensuring the mint amount is not less than a minimum requirement based on asset price. It also handles supply adjustments, maintaining a stable value through rebasing while ensuring supply changes respect a maximum limit."
f4466f865ca52d7ffa25b07318044952,2171,rule,zeroBurnDoesNotDecreaseBalance,199,208,changeSupply,"rule zeroBurnDoesNotDecreaseBalance(address burned){
env e;
requireInvariant rebasingCreditsPerTokenMustBeGreaterThan0();
// probably must assume invariant rebasingCreditsPerTokenMustBeGreaterThan0
address who;
invoke balanceOf(who);
assert !lastReverted;
}
// Requireing rebasingCreditsPerToken to be greater than zero is important
// since much of the rebasing/nonRebasing accounting will fail if it is zero.
//
// Once the contract is initialized, the rebasingCreditsPerToken should never
// again be zero, since a positive value is set in the initializer and there is a
// require statement guarding against it going back down to zero in the only
// function that updates it.
invariant rebasingCreditsPerTokenMustBeGreaterThan0()
rebasingCreditsPerToken() > 0
// a condition for changeSupply() not to revert:
// TODO: Check in init_state. probably wrong in constructor/initialization?
rule totalSupplyIntegrity(method f) {
require totalSupply() >= (rebasingCredits()*ONE()) / rebasingCreditsPerToken() + nonRebasingSupply();
requireInvariant rebasingCreditsPerTokenMustBeGreaterThan0;
// need to require that nonRebasingCreditsPerToken is < 1e18?
executeAFunction(f);
assert totalSupply() >= (rebasingCredits()*ONE()) / rebasingCreditsPerToken() + nonRebasingSupply();
uint before = balanceOf(burned);
burn(e, burned, 0);
uint after = balanceOf(burned);
assert before == after;
","changeSupply (Lines 472-507), "," function changeSupply(uint256 _newTotalSupply)
external
onlyVault
nonReentrant
{
require(_totalSupply > 0, ""Cannot increase 0 supply"");
if (_totalSupply == _newTotalSupply) {
emit TotalSupplyUpdated(
_totalSupply,
rebasingCredits,
rebasingCreditsPerToken
);
return;
}
_totalSupply = _newTotalSupply > MAX_SUPPLY
? MAX_SUPPLY
: _newTotalSupply;
rebasingCreditsPerToken = rebasingCredits.divPrecisely(
_totalSupply.sub(nonRebasingSupply)
);
require(rebasingCreditsPerToken > 0, ""Invalid change in supply"");
_totalSupply = rebasingCredits
.divPrecisely(rebasingCreditsPerToken)
.add(nonRebasingSupply);
emit TotalSupplyUpdated(
_totalSupply,
rebasingCredits,
rebasingCreditsPerToken
);
}
",./ousd/spec/ousd.spec,ousd,,Yes,,"Functionality: Adjust the total supply of a token, not exceeding a maximum limit, and recalibrate the per-token value based on rebasing credits. Emit an event to document the updated total supply, ensuring changes reflect the correct proportion of non-rebasing supply to maintain integrity and prevent invalid supply adjustments."
4b64abcbac1abba4a89abd58adb082d2,2136,rule,totalSupplyIntegrity,54,62,changeSupply,"rule totalSupplyIntegrity(method f) {
require totalSupply() >= (rebasingCredits()*ONE()) / rebasingCreditsPerToken() + nonRebasingSupply();
requireInvariant rebasingCreditsPerTokenMustBeGreaterThan0;
// probably must assume invariant rebasingCreditsPerTokenMustBeGreaterThan0
requireInvariant rebasingCreditsPerTokenMustBeGreaterThan0();
address who;
invoke balanceOf(who);
assert !lastReverted;
}
// Requireing rebasingCreditsPerToken to be greater than zero is important
// since much of the rebasing/nonRebasing accounting will fail if it is zero.
//
// Once the contract is initialized, the rebasingCreditsPerToken should never
// again be zero, since a positive value is set in the initializer and there is a
// require statement guarding against it going back down to zero in the only
// function that updates it.
invariant rebasingCreditsPerTokenMustBeGreaterThan0()
rebasingCreditsPerToken() > 0
// a condition for changeSupply() not to revert:
// TODO: Check in init_state. probably wrong in constructor/initialization?
// need to require that nonRebasingCreditsPerToken is < 1e18?
executeAFunction(f);
assert totalSupply() >= (rebasingCredits()*ONE()) / rebasingCreditsPerToken() + nonRebasingSupply();
","changeSupply (Lines 472-507), "," function changeSupply(uint256 _newTotalSupply)
external
onlyVault
nonReentrant
{
require(_totalSupply > 0, ""Cannot increase 0 supply"");
if (_totalSupply == _newTotalSupply) {
emit TotalSupplyUpdated(
_totalSupply,
rebasingCredits,
rebasingCreditsPerToken
);
return;
}
_totalSupply = _newTotalSupply > MAX_SUPPLY
? MAX_SUPPLY
: _newTotalSupply;
rebasingCreditsPerToken = rebasingCredits.divPrecisely(
_totalSupply.sub(nonRebasingSupply)
);
require(rebasingCreditsPerToken > 0, ""Invalid change in supply"");
_totalSupply = rebasingCredits
.divPrecisely(rebasingCreditsPerToken)
.add(nonRebasingSupply);
emit TotalSupplyUpdated(
_totalSupply,
rebasingCredits,
rebasingCreditsPerToken
);
}
",./ousd/spec/ousd.spec,ousd,,Yes,,"Functionality: Adjusts the total supply of a token to a specified value, with limitations set by a maximum supply threshold, ensuring no adjustment to zero or negative values. It recalculates a proportionate credit per token, ensuring the change is valid and emitting an event to signal the update."
f42822566974f4f8ba598551edb94bb1,2155 | 2158,rule,zeroMintDoesNotIncreaseBalance,154,163,mint | changeSupply,"rule zeroMintDoesNotIncreaseBalance(address user) {
env e;
requireInvariant rebasingCreditsPerTokenMustBeGreaterThan0();
// probably must assume invariant rebasingCreditsPerTokenMustBeGreaterThan0
address who;
invoke balanceOf(who);
assert !lastReverted;
}
// Requireing rebasingCreditsPerToken to be greater than zero is important
// since much of the rebasing/nonRebasing accounting will fail if it is zero.
//
// Once the contract is initialized, the rebasingCreditsPerToken should never
// again be zero, since a positive value is set in the initializer and there is a
// require statement guarding against it going back down to zero in the only
// function that updates it.
invariant rebasingCreditsPerTokenMustBeGreaterThan0()
rebasingCreditsPerToken() > 0
// a condition for changeSupply() not to revert:
// TODO: Check in init_state. probably wrong in constructor/initialization?
rule totalSupplyIntegrity(method f) {
require totalSupply() >= (rebasingCredits()*ONE()) / rebasingCreditsPerToken() + nonRebasingSupply();
requireInvariant rebasingCreditsPerTokenMustBeGreaterThan0;
// need to require that nonRebasingCreditsPerToken is < 1e18?
executeAFunction(f);
assert totalSupply() >= (rebasingCredits()*ONE()) / rebasingCreditsPerToken() + nonRebasingSupply();
uint before = balanceOf(user);
mint(e, user, 0);
uint after = balanceOf(user);
assert after == before;
","mint (Lines 42-87), | changeSupply (Lines 472-507), "," function mint(
address _asset,
uint256 _amount,
uint256 _minimumOusdAmount
) external whenNotCapitalPaused nonReentrant {
require(assets[_asset].isSupported, ""Asset is not supported"");
require(_amount > 0, ""Amount must be greater than 0"");
uint256 price = IMinMaxOracle(priceProvider).priceMin(
Helpers.getSymbol(_asset)
);
if (price > 1e8) {
price = 1e8;
}
uint256 assetDecimals = Helpers.getDecimals(_asset);
uint256 unitAdjustedDeposit = _amount.scaleBy(int8(18 - assetDecimals));
uint256 priceAdjustedDeposit = _amount.mulTruncateScale(
price.scaleBy(int8(10)), // 18-8 because oracles have 8 decimals precision
10**assetDecimals
);
if (_minimumOusdAmount > 0) {
require(
priceAdjustedDeposit >= _minimumOusdAmount,
""Mint amount lower than minimum""
);
}
emit Mint(msg.sender, priceAdjustedDeposit);
// Rebase must happen before any transfers occur.
if (unitAdjustedDeposit >= rebaseThreshold && !rebasePaused) {
_rebase();
}
// Mint matching OUSD
oUSD.mint(msg.sender, priceAdjustedDeposit);
// Transfer the deposited coins to the vault
IERC20 asset = IERC20(_asset);
asset.safeTransferFrom(msg.sender, address(this), _amount);
if (unitAdjustedDeposit >= autoAllocateThreshold) {
_allocate();
}
}
| function changeSupply(uint256 _newTotalSupply)
external
onlyVault
nonReentrant
{
require(_totalSupply > 0, ""Cannot increase 0 supply"");
if (_totalSupply == _newTotalSupply) {
emit TotalSupplyUpdated(
_totalSupply,
rebasingCredits,
rebasingCreditsPerToken
);
return;
}
_totalSupply = _newTotalSupply > MAX_SUPPLY
? MAX_SUPPLY
: _newTotalSupply;
rebasingCreditsPerToken = rebasingCredits.divPrecisely(
_totalSupply.sub(nonRebasingSupply)
);
require(rebasingCreditsPerToken > 0, ""Invalid change in supply"");
_totalSupply = rebasingCredits
.divPrecisely(rebasingCreditsPerToken)
.add(nonRebasingSupply);
emit TotalSupplyUpdated(
_totalSupply,
rebasingCredits,
rebasingCreditsPerToken
);
}
",./ousd/spec/ousd.spec,ousd,,Yes,,"Functionality: Enable users to mint a new digital asset (OUSD) by depositing a supported asset, after calculating its value based on current market prices, ensuring the deposit meets a minimum value, and potentially triggering a rebase to adjust the supply if certain thresholds are met."
73689d9fc34026be926eb7e27b25c843,2148,rule,additiveMint,125,141,mint,"rule additiveMint(address minter, uint256 x, uint256 y) {
env e;
storage init = lastStorage;
mint(e, minter, x);
mint(e, minter, y);
uint b1 = balanceOf(minter);
require x+y <= MAX_UINT256();
uint sumXY = x+y;
mint(e, minter, sumXY) at init;
uint b2 = balanceOf(minter);
assert b1 == b2, ""mint is not additive in balance of burned"";
}
","mint (Lines 42-87), "," function mint(
address _asset,
uint256 _amount,
uint256 _minimumOusdAmount
) external whenNotCapitalPaused nonReentrant {
require(assets[_asset].isSupported, ""Asset is not supported"");
require(_amount > 0, ""Amount must be greater than 0"");
uint256 price = IMinMaxOracle(priceProvider).priceMin(
Helpers.getSymbol(_asset)
);
if (price > 1e8) {
price = 1e8;
}
uint256 assetDecimals = Helpers.getDecimals(_asset);
uint256 unitAdjustedDeposit = _amount.scaleBy(int8(18 - assetDecimals));
uint256 priceAdjustedDeposit = _amount.mulTruncateScale(
price.scaleBy(int8(10)), // 18-8 because oracles have 8 decimals precision
10**assetDecimals
);
if (_minimumOusdAmount > 0) {
require(
priceAdjustedDeposit >= _minimumOusdAmount,
""Mint amount lower than minimum""
);
}
emit Mint(msg.sender, priceAdjustedDeposit);
// Rebase must happen before any transfers occur.
if (unitAdjustedDeposit >= rebaseThreshold && !rebasePaused) {
_rebase();
}
// Mint matching OUSD
oUSD.mint(msg.sender, priceAdjustedDeposit);
// Transfer the deposited coins to the vault
IERC20 asset = IERC20(_asset);
asset.safeTransferFrom(msg.sender, address(this), _amount);
if (unitAdjustedDeposit >= autoAllocateThreshold) {
_allocate();
}
}
",./ousd/spec/ousd.spec,ousd,,Yes,,"Functionality: Validate the asset and amount for minting, calculating its price and adjusting for decimals to ensure it meets the minimum required OUSD amount. Emit a Mint event, potentially trigger a rebase if above threshold, mint OUSD to the sender, transfer deposited assets to the contract, and possibly initiate allocation if above a defined threshold."
8971fb1874e7a89ff1c97e87fa8b565f,2127,invariant,optingInAndOutSyncdWithNonRebasingState,344,366,changeSupply,"invariant optingInAndOutSyncdWithNonRebasingState(address a)
(rebaseState(a) == OPT_IN() => nonRebasingCreditsPerToken(a) == 0) &&
(rebaseState(a) == OPT_OUT() => nonRebasingCreditsPerToken(a) > 0) // otherwise - no need to check
rule isRebasingPredicateSynchronized(address a) {
requireInvariant optingInAndOutSyncdWithNonRebasingState;
requireInvariant rebasingCreditsPerTokenMustBeGreaterThan0();
// probably must assume invariant rebasingCreditsPerTokenMustBeGreaterThan0
address who;
invoke balanceOf(who);
assert !lastReverted;
}
// Requireing rebasingCreditsPerToken to be greater than zero is important
// since much of the rebasing/nonRebasing accounting will fail if it is zero.
//
// Once the contract is initialized, the rebasingCreditsPerToken should never
// again be zero, since a positive value is set in the initializer and there is a
// require statement guarding against it going back down to zero in the only
// function that updates it.
invariant rebasingCreditsPerTokenMustBeGreaterThan0()
rebasingCreditsPerToken() > 0
// a condition for changeSupply() not to revert:
// TODO: Check in init_state. probably wrong in constructor/initialization?
rule totalSupplyIntegrity(method f) {
require totalSupply() >= (rebasingCredits()*ONE()) / rebasingCreditsPerToken() + nonRebasingSupply();
requireInvariant rebasingCreditsPerTokenMustBeGreaterThan0;
// need to require that nonRebasingCreditsPerToken is < 1e18?
executeAFunction(f);
assert totalSupply() >= (rebasingCredits()*ONE()) / rebasingCreditsPerToken() + nonRebasingSupply();
uint256 _previousNonRebasingCreditsPerToken = nonRebasingCreditsPerToken(a);
bool becomesNonRebasing = Certora_isNonRebasingAccount(a);
// the only thing we can say for sure here is that if it was non rebasing, then it remains non rebasing
if (_previousNonRebasingCreditsPerToken > 0) {
assert becomesNonRebasing;
} // can't say anything else because a contract will be migrated.
// after we call _isNonRebasingAccount, and it returns true, it must be the case that nonRebasingCreditsPerToken is positive.
if (becomesNonRebasing) {
assert nonRebasingCreditsPerToken(a) > 0;
} else {
assert nonRebasingCreditsPerToken(a) == 0;
}
","changeSupply (Lines 472-507), "," function changeSupply(uint256 _newTotalSupply)
external
onlyVault
nonReentrant
{
require(_totalSupply > 0, ""Cannot increase 0 supply"");
if (_totalSupply == _newTotalSupply) {
emit TotalSupplyUpdated(
_totalSupply,
rebasingCredits,
rebasingCreditsPerToken
);
return;
}
_totalSupply = _newTotalSupply > MAX_SUPPLY
? MAX_SUPPLY
: _newTotalSupply;
rebasingCreditsPerToken = rebasingCredits.divPrecisely(
_totalSupply.sub(nonRebasingSupply)
);
require(rebasingCreditsPerToken > 0, ""Invalid change in supply"");
_totalSupply = rebasingCredits
.divPrecisely(rebasingCreditsPerToken)
.add(nonRebasingSupply);
emit TotalSupplyUpdated(
_totalSupply,
rebasingCredits,
rebasingCreditsPerToken
);
}
",./ousd/spec/ousd.spec,ousd,,Yes,,"Functionality: Adjust the total supply of a token within predefined limits, ensuring it cannot exceed a maximum value or drop to zero. It recalculates a per-token credit value, ensuring it remains positive, and emits an event detailing the adjusted supply, total credits, and the calculated per-token credit value."
edfff2a81ec7a1cafbc532a35123aaa0,2132,rule,neverRevert_BalanceOf,33,39,changeSupply,"rule neverRevert_BalanceOf {
// probably must assume invariant rebasingCreditsPerTokenMustBeGreaterThan0
requireInvariant rebasingCreditsPerTokenMustBeGreaterThan0();
address who;
invoke balanceOf(who);
assert !lastReverted;
}
// Requireing rebasingCreditsPerToken to be greater than zero is important
// since much of the rebasing/nonRebasing accounting will fail if it is zero.
//
// Once the contract is initialized, the rebasingCreditsPerToken should never
// again be zero, since a positive value is set in the initializer and there is a
// require statement guarding against it going back down to zero in the only
// function that updates it.
invariant rebasingCreditsPerTokenMustBeGreaterThan0()
rebasingCreditsPerToken() > 0
// a condition for changeSupply() not to revert:
// TODO: Check in init_state. probably wrong in constructor/initialization?
rule totalSupplyIntegrity(method f) {
require totalSupply() >= (rebasingCredits()*ONE()) / rebasingCreditsPerToken() + nonRebasingSupply();
requireInvariant rebasingCreditsPerTokenMustBeGreaterThan0;
// need to require that nonRebasingCreditsPerToken is < 1e18?
executeAFunction(f);
assert totalSupply() >= (rebasingCredits()*ONE()) / rebasingCreditsPerToken() + nonRebasingSupply();
","changeSupply (Lines 472-507), "," function changeSupply(uint256 _newTotalSupply)
external
onlyVault
nonReentrant
{
require(_totalSupply > 0, ""Cannot increase 0 supply"");
if (_totalSupply == _newTotalSupply) {
emit TotalSupplyUpdated(
_totalSupply,
rebasingCredits,
rebasingCreditsPerToken
);
return;
}
_totalSupply = _newTotalSupply > MAX_SUPPLY
? MAX_SUPPLY
: _newTotalSupply;
rebasingCreditsPerToken = rebasingCredits.divPrecisely(
_totalSupply.sub(nonRebasingSupply)
);
require(rebasingCreditsPerToken > 0, ""Invalid change in supply"");
_totalSupply = rebasingCredits
.divPrecisely(rebasingCreditsPerToken)
.add(nonRebasingSupply);
emit TotalSupplyUpdated(
_totalSupply,
rebasingCredits,
rebasingCreditsPerToken
);
}
",./ousd/spec/ousd.spec,ousd,,Yes,,"Functionality: Safely adjust the total supply of a token, ensuring it does not exceed a maximum limit, and update its rebasing credits per token proportionally. It emits an event upon successful supply adjustment or in case the new supply matches the current, without making changes."
edfff2a81ec7a1cafbc532a35123aaa0,2132,rule,neverRevert_BalanceOf,33,39,changeSupply,"rule neverRevert_BalanceOf {
// probably must assume invariant rebasingCreditsPerTokenMustBeGreaterThan0
requireInvariant rebasingCreditsPerTokenMustBeGreaterThan0();
address who;
invoke balanceOf(who);
assert !lastReverted;
}
// Requireing rebasingCreditsPerToken to be greater than zero is important
// since much of the rebasing/nonRebasing accounting will fail if it is zero.
//
// Once the contract is initialized, the rebasingCreditsPerToken should never
// again be zero, since a positive value is set in the initializer and there is a
// require statement guarding against it going back down to zero in the only
// function that updates it.
invariant rebasingCreditsPerTokenMustBeGreaterThan0()
rebasingCreditsPerToken() > 0
// a condition for changeSupply() not to revert:
// TODO: Check in init_state. probably wrong in constructor/initialization?
rule totalSupplyIntegrity(method f) {
require totalSupply() >= (rebasingCredits()*ONE()) / rebasingCreditsPerToken() + nonRebasingSupply();
requireInvariant rebasingCreditsPerTokenMustBeGreaterThan0;
// need to require that nonRebasingCreditsPerToken is < 1e18?
executeAFunction(f);
assert totalSupply() >= (rebasingCredits()*ONE()) / rebasingCreditsPerToken() + nonRebasingSupply();
","changeSupply (Lines 472-507), "," function changeSupply(uint256 _newTotalSupply)
external
onlyVault
nonReentrant
{
require(_totalSupply > 0, ""Cannot increase 0 supply"");
if (_totalSupply == _newTotalSupply) {
emit TotalSupplyUpdated(
_totalSupply,
rebasingCredits,
rebasingCreditsPerToken
);
return;
}
_totalSupply = _newTotalSupply > MAX_SUPPLY
? MAX_SUPPLY
: _newTotalSupply;
rebasingCreditsPerToken = rebasingCredits.divPrecisely(
_totalSupply.sub(nonRebasingSupply)
);
require(rebasingCreditsPerToken > 0, ""Invalid change in supply"");
_totalSupply = rebasingCredits
.divPrecisely(rebasingCreditsPerToken)
.add(nonRebasingSupply);
emit TotalSupplyUpdated(
_totalSupply,
rebasingCredits,
rebasingCreditsPerToken
);
}
",./ousd/spec/ousd.spec,ousd,,Yes,,"Functionality: Adjust the total token supply to a new value, within the bounds of a maximum supply limit, recalculating a per-token credit ratio. This adjustment restricts changes to a non-zero supply and ensures the recalculated credits per token remain positive, emitting an updated supply event upon change."
8817c3e3f94e6cb1fef12918c6792b78,2255,rule,unrelatedUserBalanceNotChangingParametric,929,978,_dripsState,"// rule unrelatedUserBalanceNotChangingParametric(
// method f, uint256 senderId, uint256 receiverId, uint256 assetId) {
// env e; env eB; env eF;
// calldataarg args;
// // step 1 - balance before of receiverId
// bytes32 dripsHashBefore; bytes32 dripsHistoryHashBefore;
// uint32 updateTimeBefore; uint128 balanceBefore; uint32 maxEndBefore;
// dripsHashBefore, dripsHistoryHashBefore, updateTimeBefore,
// balanceBefore, maxEndBefore = _dripsState(eB, receiverId, assetId);
// uint256 userId1; uint256 config1;
// uint256 userId2; uint256 config2;
// uint256 userId3; uint256 config3;
// userId1, config1, userId2, config2, userId3, config3 = unpackArgs(e, args);
// DH.DripsReceiver argsReceiver1;
// require argsReceiver1.userId == userId1;
// require argsReceiver1.config == config1;
// DH.DripsReceiver argsReceiver2;
// require argsReceiver2.userId == userId2;
// require argsReceiver2.config == config2;
// DH.DripsReceiver argsReceiver3;
// require argsReceiver3.userId == userId3;
// require argsReceiver3.config == config3;
// require argsReceiver1.userId != receiverId;
// require argsReceiver2.userId != receiverId;
// require argsReceiver3.userId != receiverId;
// f(e, args);
// //assert false; // false 2
// // step 3 - balance after of user2
// bytes32 dripsHashAfter; bytes32 dripsHistoryHashAfter;
// uint32 updateTimeAfter; uint128 balanceAfter; uint32 maxEndAfter;
// dripsHashAfter, dripsHistoryHashAfter, updateTimeAfter,
// balanceAfter, maxEndAfter = _dripsState(eF, receiverId, assetId);
// // check that balance of user2 was not modified
// assert balanceBefore == balanceAfter, ""balanceOf receiverId changed"";
// //assert false;
// }
","_dripsState (Lines 509-529), "," function _dripsState(uint256 userId, uint256 assetId)
//internal
public
view
returns (
bytes32 dripsHash,
bytes32 dripsHistoryHash,
uint32 updateTime,
uint128 balance,
uint32 maxEnd
)
{
DripsState storage state = _dripsStorage().states[assetId][userId];
return (
state.dripsHash,
state.dripsHistoryHash,
state.updateTime,
state.balance,
state.maxEnd
);
}
",./radicle_drips/specs/DripsHub.spec,radicle_drips,,Yes,,"Functionality: Retrieve the state of drips for a specific user and asset, returning the current drips configuration hash, drips history hash, the last update time, the user's balance in the drips mechanism, and the maximum end time of any ongoing drips."
82c40e04f3e556bbdf4feac170959366,2266,rule,correctnessOfSplit,38,55,split,"rule correctnessOfSplit() {
env e; uint256 userId; uint256 assetId; uint128 collectableAmt; uint128 splitAmt;
uint128 splittableBefore; uint128 collectableBefore;
uint128 splittableAfter; uint128 collectableAfter;
splittableBefore = splittable(e, userId, assetId);
collectableBefore = collectable(e, userId, assetId);
collectableAmt, splitAmt = split(e, userId, assetId, true);
splittableAfter = splittable(e, userId, assetId);
collectableAfter = collectable(e, userId, assetId);
assert splittableBefore >= splittableAfter;
assert collectableBefore + collectableAmt == collectableAfter;
assert splittableBefore + collectableBefore >= splittableAfter + collectableAfter;
}
","split (Lines 343-349), "," function split(
uint256 userId,
IERC20 erc20,
SplitsReceiver[] memory currReceivers
) public whenNotPaused returns (uint128 collectableAmt, uint128 splitAmt) {
return Splits._split(userId, _assetId(erc20), currReceivers);
}
",./radicle_drips/specs/Splits.spec,radicle_drips,,Yes,,"Functionality: Perform a funds split for a specific user and ERC20 token, distributing amounts to specified receivers. This method calculates the collectable and split amounts based on current receiver configurations, using the internal `_split` function and pausing execution if the contract is paused."
a02f160902ea2b8f5f1fd31d36969688,2350,rule,whoChangedBalanceOfUserId,326,362,_dripsState,"rule whoChangedBalanceOfUserId(method f, uint256 userId) {
env eB;
env eF;
calldataarg args;
uint256 assetId;
bytes32 dripsHashBefore;
bytes32 dripsHistoryHashBefore;
uint32 updateTimeBefore;
uint128 balanceBefore;
uint32 maxEndBefore;
dripsHashBefore,
dripsHistoryHashBefore,
updateTimeBefore,
balanceBefore,
maxEndBefore = _dripsState(eB, userId, assetId);
f(eF,args); // call any function
bytes32 dripsHashAfter;
bytes32 dripsHistoryHashAfter;
uint32 updateTimeAfter;
uint128 balanceAfter;
uint32 maxEndAfter;
dripsHashAfter,
dripsHistoryHashAfter,
updateTimeAfter,
balanceAfter,
maxEndAfter = _dripsState(eF, userId, assetId);
assert balanceBefore == balanceAfter, ""balanceOfUser changed"";
}
","_dripsState (Lines 509-529), "," function _dripsState(uint256 userId, uint256 assetId)
//internal
public
view
returns (
bytes32 dripsHash,
bytes32 dripsHistoryHash,
uint32 updateTime,
uint128 balance,
uint32 maxEnd
)
{
DripsState storage state = _dripsStorage().states[assetId][userId];
return (
state.dripsHash,
state.dripsHistoryHash,
state.updateTime,
state.balance,
state.maxEnd
);
}
",./radicle_drips/specs/DripsHubBackup.spec,radicle_drips,,Yes,,"Functionality: Retrieve and return the state of drips for a specific user and asset, including the drips hash, drips history hash, the last update time, current balance, and the maximum end time, by accessing and querying data from a storage structure."
a33253c68f2bf1192bc92020f9ca8780,2336 | 2338 | 2339,rule,cannotFrontRunSplitTwoSameUsers,116,160,split | _setSplits | _assertSplitsValid,"rule cannotFrontRunSplitTwoSameUsers() {
env e; env e2; uint256 assetId; uint256 userA_Id; uint256 userB_Id; uint256 userC_Id;
uint128 userA_collectableAmt; uint128 userA_splitAmt;
uint128 userA_collectableAmt2; uint128 userA_splitAmt2;
uint128 userB_collectableAmt; uint128 userB_splitAmt;
uint128 userA_splittableBefore = splittable(e, userA_Id, assetId);
uint128 userB_splittableBefore = splittable(e, userB_Id, assetId);
uint128 userC_splittableBefore = splittable(e, userC_Id, assetId);
uint128 userA_collectableBefore = collectable(e, userA_Id, assetId);
uint128 userB_collectableBefore = collectable(e, userB_Id, assetId);
uint128 userC_collectableBefore = collectable(e, userC_Id, assetId);
require ( (userA_Id != userB_Id) &&
((userC_Id == userA_Id) || (userC_Id == userB_Id)) );
// prevents overflow in the edge cases of (userC == userA) or (userC == userB):
require userA_collectableBefore + userA_splittableBefore + userB_splittableBefore < 2^128;
require userB_collectableBefore + userB_splittableBefore + userA_splittableBefore < 2^128;
// setting up the currReceivers[] of userA and userB to be the same - singe receiver userC
uint256 length1 = getCurrSplitsReceiverLocaLength(e, true);
require length1 == 1; // only one receiver
uint256 index1; uint256 userId1; uint32 weight1;
userId1, weight1 = getCurrSplitsReceiverLocalArr(e, true, index1);
require userId1 == userC_Id;
require weight1 <= 1000000; // safe assumption
require weight1 > 0; // safe assumption
// safe assumptions since the function _assertSplitsValid()
// verified that totalWeight <= _TOTAL_SPLITS_WEIGHT upon _setSplits()
// we required that there is only one receiver, therefore totalWeight = weight1
// _TOTAL_SPLITS_WEIGHT == 1000000, hence the assumption above is safe
// also _assertSplitsValid() verified that weight != 0
storage initStorage = lastStorage;
userA_collectableAmt, userA_splitAmt = split(e, userA_Id, assetId, true);
uint128 userC_splittableAfterSplitA = splittable(e, userC_Id, assetId);
userB_collectableAmt, userB_splitAmt = split(e, userB_Id, assetId, true) at initStorage;
uint128 userC_splittableAfterSplitB = splittable(e, userC_Id, assetId);
userA_collectableAmt2, userA_splitAmt2 = split@withrevert(e, userA_Id, assetId, true);
assert !lastReverted;
}
","split (Lines 343-349), | _setSplits (Lines 215-223), | _assertSplitsValid (Lines 229-247), "," function split(
uint256 userId,
IERC20 erc20,
SplitsReceiver[] memory currReceivers
) public whenNotPaused returns (uint128 collectableAmt, uint128 splitAmt) {
return Splits._split(userId, _assetId(erc20), currReceivers);
}
| function _setSplits(uint256 userId, SplitsReceiver[] memory receivers) internal {
SplitsState storage state = _splitsStorage().splitsStates[userId];
bytes32 newSplitsHash = _hashSplits(receivers);
emit SplitsSet(userId, newSplitsHash);
if (newSplitsHash != state.splitsHash) {
_assertSplitsValid(receivers, newSplitsHash);
state.splitsHash = newSplitsHash;
}
}
| function _assertSplitsValid(SplitsReceiver[] memory receivers, bytes32 receiversHash) internal {
require(receivers.length <= _MAX_SPLITS_RECEIVERS, ""Too many splits receivers"");
uint64 totalWeight = 0;
uint256 prevUserId;
for (uint256 i = 0; i < receivers.length; i++) {
SplitsReceiver memory receiver = receivers[i];
uint32 weight = receiver.weight;
require(weight != 0, ""Splits receiver weight is zero"");
totalWeight += weight;
uint256 userId = receiver.userId;
if (i > 0) {
require(prevUserId != userId, ""Duplicate splits receivers"");
require(prevUserId < userId, ""Splits receivers not sorted by user ID"");
}
prevUserId = userId;
emit SplitsReceiverSeen(receiversHash, userId, weight);
}
require(totalWeight <= _TOTAL_SPLITS_WEIGHT, ""Splits weights sum too high"");
}
",./radicle_drips/specs/Splits2.spec,radicle_drips,,Yes,,"Functionality: Facilitate the distribution of ERC20 tokens to multiple recipients based on predefined splits, validate distribution parameters including the maximum number of recipients, ensure uniqueness and order of recipients, and manage the total allocation weight within an allowed range."
bb50a156cf13a8276faff05171a8c44f,2352 | 2353 | 2354,rule,singleUserTimeUpdateNotChangingOtherUserBalance,392,490,"DH.create, create | _dripsState | _updateReceiverStates","rule singleUserTimeUpdateNotChangingOtherUserBalance(method f, uint256 userId) {
env e; env eB; env eF;
calldataarg args;
// uint8 i;
// userId1 and userId2 - receivers Id
uint256 assetId; uint256 userId1; uint256 userId2;
require userId != userId1; // != userId2;
require userId1 < userId2; // sorted
require userId != userId2;
// step 1 - balance before of user2
bytes32 dripsHashBefore; bytes32 dripsHistoryHashBefore;
uint32 updateTimeBefore; uint128 balanceBefore; uint32 maxEndBefore;
dripsHashBefore, dripsHistoryHashBefore, updateTimeBefore,
balanceBefore, maxEndBefore = _dripsState(eB, userId2, assetId);
// assert false; // false 0
// step 2 - setup user1 changes and then call _updateReceiverStates()
/* //setting values to config by create:
uint192 _amtPerSec;
uint32 _start;
uint32 _duration;
require _amtPerSec != 0;
*/
DH.DripsConfig configOld1;// = create(_amtPerSec, _start, _duration);
DH.DripsConfig configOld2;// = DH.create(_amtPerSec+1, _start+1, _duration+1);
DH.DripsConfig configNew1;// = DH.create(_amtPerSec+2, _start+2, _duration+2);
// DH.DripsConfig configNew2;
require configOld1 != configNew1;
// require configOld2 == configNew2;
DH.DripsReceiver receiverOld1;
require receiverOld1.userId == userId1;
require receiverOld1.config == configOld1;
DH.DripsReceiver receiverOld2;
require receiverOld2.userId == userId2;
require receiverOld2.config == configOld2;
DH.DripsReceiver receiverNew1;
require receiverNew1.userId == userId1;
require receiverNew1.config == configNew1;
// DripsReceiver[] memory currReceivers;
// DripsReceiver[] memory newReceivers;
// currReceivers[i].userId = userId1;
// currReceivers[i].config = configCurr;
// require sorted
// require no duplicate
// require amtPerSec != 0
// require(i < _MAX_DRIPS_RECEIVERS,"""");
// require currReceivers == newReceivers;
// newReceivers[i].config = configNew; // the only change in newReceivers is configNew of userId2
// DripsState storage state = _dripsStorage().states[assetId][userId];
// uint32 lastUpdate = state.updateTime;
// uint32 currMaxEnd = state.maxEnd;
// uint32 newMaxEnd = sizeof(uint32);
// assert false; // false 1
//assert configOld2 != configNew2; //returned 0
_helperUpdateReceiverStates( e,
receiverOld1,
receiverOld2,
receiverNew1,
assetId,
userId
);
//assert false; // false 2
// step 3 - balance after of user2
bytes32 dripsHashAfter; bytes32 dripsHistoryHashAfter;
uint32 updateTimeAfter; uint128 balanceAfter; uint32 maxEndAfter;
dripsHashAfter, dripsHistoryHashAfter, updateTimeAfter,
balanceAfter, maxEndAfter = _dripsState(eF, userId2, assetId);
// check that balance of user2 was not modified
assert balanceBefore == balanceAfter, ""balanceOfUser2 changed"";
assert false;
}
","create (Lines 59-68), | _dripsState (Lines 509-529), | _updateReceiverStates (Lines 818-1089), "," function create(
uint192 _amtPerSec,
uint32 _start,
uint32 _duration
) internal pure returns (DripsConfig) {
uint256 config = _amtPerSec;
config = (config << 32) | _start;
config = (config << 32) | _duration;
return DripsConfig.wrap(config);
}
| function _dripsState(uint256 userId, uint256 assetId)
//internal
public
view
returns (
bytes32 dripsHash,
bytes32 dripsHistoryHash,
uint32 updateTime,
uint128 balance,
uint32 maxEnd
)
{
DripsState storage state = _dripsStorage().states[assetId][userId];
return (
state.dripsHash,
state.dripsHistoryHash,
state.updateTime,
state.balance,
state.maxEnd
);
}
| function _updateReceiverStates(
mapping(uint256 => DripsState) storage states,
DripsReceiver[] memory currReceivers,
uint32 lastUpdate,
uint32 currMaxEnd,
DripsReceiver[] memory newReceivers,
uint32 newMaxEnd
//) private {
) internal virtual {
//return;
//require(currReceivers.length == 1, ""Attempt to reduce computation"");
//require(newReceivers.length == 1, ""Attempt to reduce computation"");
uint256 currIdx = 0;
uint256 newIdx = 0;
while (true) {
bool pickCurr = currIdx < currReceivers.length;
DripsReceiver memory currRecv;
if (pickCurr) currRecv = currReceivers[currIdx];
bool pickNew = newIdx < newReceivers.length;
DripsReceiver memory newRecv;
if (pickNew) newRecv = newReceivers[newIdx];
// if-1
// Limit picking both curr and new to situations when they differ only by start/end time
if (
pickCurr &&
pickNew &&
(currRecv.userId != newRecv.userId ||
currRecv.config.amtPerSec() != newRecv.config.amtPerSec())
) {
pickCurr = _isOrdered(currRecv, newRecv);
pickNew = !pickCurr;
}
if (pickCurr && pickNew) {
// if-2: same userId, same amtPerSec
// Shift the existing drip to fulfil the new configuration
// states[currRecv.userId].amtDeltas[_currTimestamp()].thisCycle = thisCycleMapping[currRecv.userId][_currTimestamp()];
// states[currRecv.userId].amtDeltas[_currTimestamp()].nextCycle = nextCycleMapping[currRecv.userId][_currTimestamp()];
// states[currRecv.userId].nextReceivableCycle = nextReceivableCycleMapping[currRecv.userId];
DripsState storage state = states[currRecv.userId];
(uint32 currStart, uint32 currEnd) = _dripsRangeInFuture(
currRecv,
lastUpdate,
currMaxEnd
);
(uint32 newStart, uint32 newEnd) = _dripsRangeInFuture(
newRecv,
_currTimestamp(),
newMaxEnd
);
{
int256 amtPerSec = int256(uint256(currRecv.config.amtPerSec()));
// Move the start and end times if updated
_addDeltaRange(state, currStart, newStart, -amtPerSec);
_addDeltaRange(state, currEnd, newEnd, amtPerSec);
}
// Ensure that the user receives the updated cycles
uint32 currStartCycle = _cycleOf(currStart);
uint32 newStartCycle = _cycleOf(newStart);
if (currStartCycle > newStartCycle && state.nextReceivableCycle > newStartCycle) {
state.nextReceivableCycle = newStartCycle;
}
} else if (pickCurr) {
// if-3
// Remove an existing drip
DripsState storage state = states[currRecv.userId];
(uint32 start, uint32 end) = _dripsRangeInFuture(currRecv, lastUpdate, currMaxEnd);
//require (end - start == 10);
int256 amtPerSec = int256(uint256(currRecv.config.amtPerSec()));
_addDeltaRange(state, start, end, -amtPerSec);
//
} else if (pickNew) {
// if-4
// Create a new drip
DripsState storage state = states[newRecv.userId];
(uint32 start, uint32 end) = _dripsRangeInFuture(
newRecv,
_currTimestamp(),
newMaxEnd
);
int256 amtPerSec = int256(uint256(newRecv.config.amtPerSec()));
_addDeltaRange(state, start, end, amtPerSec);
// Ensure that the user receives the updated cycles
uint32 startCycle = _cycleOf(start);
if (state.nextReceivableCycle == 0 || state.nextReceivableCycle > startCycle) {
state.nextReceivableCycle = startCycle;
}
//
} else {
break;
}
if (pickCurr) currIdx++;
if (pickNew) newIdx++;
}
}
/// @notice Calculates the time range in the future in which a receiver will be dripped to.
/// @param receiver The drips receiver
/// @param maxEnd The maximum end time of drips
function _dripsRangeInFuture(
DripsReceiver memory receiver,
uint32 updateTime,
uint32 maxEnd
//) private view returns (uint32 start, uint32 end) {
) internal view returns (uint32 start, uint32 end) {
return _dripsRange(receiver, updateTime, maxEnd, _currTimestamp(), type(uint32).max);
}
/// @notice Calculates the time range in which a receiver is to be dripped to.
/// This range is capped to provide a view on drips through a specific time window.
/// @param receiver The drips receiver
/// @param updateTime The time when drips are configured
/// @param maxEnd The maximum end time of drips
/// @param startCap The timestamp the drips range start should be capped to
/// @param endCap The timestamp the drips range end should be capped to
function _dripsRange(
DripsReceiver memory receiver,
uint32 updateTime,
uint32 maxEnd,
uint32 startCap,
uint32 endCap
//) private pure returns (uint32 start, uint32 end_) {
) internal pure returns (uint32 start, uint32 end_) {
start = receiver.config.start();
if (start == 0) start = updateTime;
uint40 end = uint40(start) + receiver.config.duration();
if (end == start || end > maxEnd) end = maxEnd;
if (start < startCap) start = startCap;
if (end > endCap) end = endCap;
if (end < start) end = start;
return (start, uint32(end));
}
/// @notice Adds funds received by a user in a given time range
/// @param state The user state
/// @param start The timestamp from which the delta takes effect
/// @param end The timestamp until which the delta takes effect
/// @param amtPerSec The dripping rate
function _addDeltaRange(
DripsState storage state,
uint32 start,
uint32 end,
int256 amtPerSec
//) private {
) internal {
if (start == end) return;
mapping(uint32 => AmtDelta) storage amtDeltas = state.amtDeltas;
_addDelta(amtDeltas, start, amtPerSec);
_addDelta(amtDeltas, end, -amtPerSec);
}
/// @notice Adds delta of funds received by a user at a given time
/// @param amtDeltas The user amount deltas
/// @param timestamp The timestamp when the deltas need to be added
/// @param amtPerSec The dripping rate
function _addDelta(
mapping(uint32 => AmtDelta) storage amtDeltas,
uint256 timestamp,
int256 amtPerSec
//) private {
) internal virtual {
unchecked {
// In order to set a delta on a specific timestamp it must be introduced in two cycles.
// These formulas follow the logic from `_drippedAmt`, see it for more details.
int256 amtPerSecMultiplier = int256(_AMT_PER_SEC_MULTIPLIER);
int256 fullCycle = (int256(uint256(_cycleSecs)) * amtPerSec) / amtPerSecMultiplier;
int256 nextCycle = (int256(timestamp % _cycleSecs) * amtPerSec) / amtPerSecMultiplier;
AmtDelta storage amtDelta = amtDeltas[_cycleOf(uint32(timestamp))];
// Any over- or under-flows are fine, they're guaranteed to be fixed by a matching
// under- or over-flow from the other call to `_addDelta` made by `_addDeltaRange`.
// This is because the total balance of `Drips` can never exceed `type(int128).max`,
// so in the end no amtDelta can have delta higher than `type(int128).max`.
amtDelta.thisCycle += int128(fullCycle - nextCycle);
amtDelta.nextCycle += int128(nextCycle);
}
}
/// @notice Checks if two receivers fulfil the sortedness requirement of the receivers list.
/// @param prev The previous receiver
/// @param prev The next receiver
function _isOrdered(DripsReceiver memory prev, DripsReceiver memory next)
//private
internal
pure
returns (bool)
{
if (prev.userId != next.userId) return prev.userId < next.userId;
return prev.config.lt(next.config);
}
/// @notice Calculates the amount dripped over a time range.
/// The amount dripped in the `N`th second of each cycle is:
/// `(N + 1) * amtPerSec / AMT_PER_SEC_MULTIPLIER - N * amtPerSec / AMT_PER_SEC_MULTIPLIER`.
/// For a range of `N`s from `0` to `M` the sum of the dripped amounts is calculated as:
/// `M * amtPerSec / AMT_PER_SEC_MULTIPLIER` assuming that `M <= cycleSecs`.
/// For an arbitrary time range across multiple cycles the amount is calculated as the sum of
/// the amount dripped in the start cycle, each of the full cycles in between and the end cycle.
/// This algorithm has the following properties:
/// - During every second full units are dripped, there are no partially dripped units.
/// - Undripped fractions are dripped when they add up into full units.
/// - Undripped fractions don't add up across cycle end boundaries.
/// - Some seconds drip more units and some less.
/// - Every `N`th second of each cycle drips the same amount.
/// - Every full cycle drips the same amount.
/// - The amount dripped in a given second is independent from the dripping start and end.
/// - Dripping over time ranges `A:B` and then `B:C` is equivalent to dripping over `A:C`.
/// - Different drips existing in the system don't interfere with each other.
/// @param amtPerSec The dripping rate
/// @param start The dripping start time
/// @param end The dripping end time
/// @param amt The dripped amount
function _drippedAmt(
uint256 amtPerSec,
uint256 start,
uint256 end
//) private view returns (uint256 amt) {
) internal view returns (uint256 amt) {
// This function is written in Yul because it can be called thousands of times
// per transaction and it needs to be optimized as much as possible.
// As of Solidity 0.8.13, rewriting it in unchecked Solidity triples its gas cost.
uint256 cycleSecs = _cycleSecs;
// solhint-disable-next-line no-inline-assembly
assembly {
let endedCycles := sub(div(end, cycleSecs), div(start, cycleSecs))
let amtPerCycle := div(mul(cycleSecs, amtPerSec), _AMT_PER_SEC_MULTIPLIER)
amt := mul(endedCycles, amtPerCycle)
let amtEnd := div(mul(mod(end, cycleSecs), amtPerSec), _AMT_PER_SEC_MULTIPLIER)
amt := add(amt, amtEnd)
let amtStart := div(mul(mod(start, cycleSecs), amtPerSec), _AMT_PER_SEC_MULTIPLIER)
amt := sub(amt, amtStart)
}
}
/// @notice Calculates the cycle containing the given timestamp.
/// @param timestamp The timestamp.
/// @return cycle The cycle containing the timestamp.
//function _cycleOf(uint32 timestamp) private view returns (uint32 cycle) {
function _cycleOf(uint32 timestamp) internal view returns (uint32 cycle) {
unchecked {
return timestamp / _cycleSecs + 1;
//return timestamp + 1; // attempt to simplify
}
}
/// @notice The current timestamp, casted to the library's internal representation.
/// @return timestamp The current timestamp
//function _currTimestamp() private view returns (uint32 timestamp) {
function _currTimestamp() internal view returns (uint32 timestamp) {
return uint32(block.timestamp);
}
/// @notice Returns the Drips storage.
/// @return dripsStorage The storage.
//function _dripsStorage() private view returns (DripsStorage storage dripsStorage) {
function _dripsStorage() internal view returns (DripsStorage storage dripsStorage) {
bytes32 slot = _dripsStorageSlot;
// solhint-disable-next-line no-inline-assembly
assembly {
dripsStorage.slot := slot
}
}
}
",./radicle_drips/specs/DripsHubBackup.spec,radicle_drips,,Yes,,"Functionality: Manage and update the states of drips receivers with added complexity involving timing and funds distribution. It includes functionalities to create drips configurations, update receiver states based on new configurations, calculate the amount dripped over a time range, and manage funds received by users within specified timeframes."
21d9c3b44533dd7b2f54ea2f42689a71,2244,rule,ifTheOnlyOneDripperStopsReceivableDripsCanNotIncrease,661,669,_receivableDrips,"// rule ifTheOnlyOneDripperStopsReceivableDripsCanNotIncrease()
// {
// // make sure there is only one sender and one receiver
// // make sure the sender is dripping to the receiver
// // calculate the _receivableDrips(receiver) before dripping stops
// // stop the dripping
// // calculate the _receivableDrips(receiver) after dripping stops
// // after == before
// }
","_receivableDrips (Lines 224-236), "," function _receivableDrips(
uint256 userId,
uint256 assetId,
uint32 maxCycles
) public
// internal
view returns (uint128 receivableAmt, uint32 receivableCycles) {
(receivableAmt, receivableCycles, , , ) = _receivableDripsVerbose(
userId,
assetId,
maxCycles
);
}
",./radicle_drips/specs/DripsHub.spec,radicle_drips,,Yes,,"Functionality: Calculate and return the amount receivable (`receivableAmt`) and the number of receivable cycles (`receivableCycles`) for a given user's asset, based on a maximum number of cycles (`maxCycles`), by calling another function `_receivableDripsVerbose`."
90a6b394d17ec347fccba99e4b390a9f,2276 | 2278 | 2279,rule,integrityOfSplit,143,209,split | _setSplits | _assertSplitsValid,"rule integrityOfSplit() {
env e; uint256 assetId;
uint256 userA_Id; uint256 userB_Id; uint256 userC_Id; uint256 userD_Id;
require userA_Id != userB_Id; require userA_Id != userD_Id;
require userA_Id != userC_Id; require userB_Id != userD_Id;
require userB_Id != userC_Id; require userC_Id != userD_Id;
// obtaining splittable/collectable states before calling split()
uint128 userA_splittableBefore = splittable(e, userA_Id, assetId);
require userA_splittableBefore > 0;
uint128 userA_collectableBefore = collectable(e, userA_Id, assetId);
uint128 userB_splittableBefore = splittable(e, userB_Id, assetId);
uint128 userB_collectableBefore = collectable(e, userB_Id, assetId);
uint128 userC_splittableBefore = splittable(e, userC_Id, assetId);
uint128 userC_collectableBefore = collectable(e, userC_Id, assetId);
uint128 userD_splittableBefore = splittable(e, userD_Id, assetId);
uint128 userD_collectableBefore = collectable(e, userD_Id, assetId);
// setting up the currReceivers[] of userA
/// are invariant of the split
rule moneyNotLostOrCreatedDuringSplit() {
uint256 userA_Id; uint256 userB_Id;
uint256 length; uint256 index1; uint256 userId1; uint32 weight1;
userId1, weight1 = getCurrSplitsReceiverLocalArr(e, true, index1);
length = getCurrSplitsReceiverLocaLength(e, true);
require length == 1; // only one splitsReceiver
require userId1 == userB_Id; // making sure it is userB (not limiting it to be userA)
require weight1 <= 1000000; // safe assumptions since the function _assertSplitsValid()
// verified that totalWeight <= _TOTAL_SPLITS_WEIGHT upon _setSplits()
// we required that there is only one receiver, therefore totalWeight = weight1
// _TOTAL_SPLITS_WEIGHT == 1000000, hence the assumption above is safe
// recording the state before split()
// calling the split() on userA
uint128 userA_collectableAmt; uint128 userA_splitAmt;
userA_collectableAmt, userA_splitAmt = split(e, userA_Id, assetId, true);
// recording the state after split()
uint128 userA_splittableAfter = splittable(e, userA_Id, assetId);
uint128 userA_collectableAfter = collectable(e, userA_Id, assetId);
uint128 userB_splittableAfter = splittable(e, userB_Id, assetId);
uint128 userB_collectableAfter = collectable(e, userB_Id, assetId);
// the expectation:
uint128 moneyBefore = userA_splittableBefore + userA_collectableBefore + userB_splittableBefore + userB_collectableBefore;
uint128 moneyAfter = userA_splittableAfter + userA_collectableAfter + userB_splittableAfter + userB_collectableAfter;
assert moneyBefore == moneyAfter;
}
uint256 index1; uint256 userId1; uint32 weight1;
uint256 index2; uint256 userId2; uint32 weight2;
userId2, weight2 = getCurrSplitsReceiverLocalArr(e, true, index2);
require index1 != index2; // different indexes sample different splitReceivers
require userId1 == userB_Id; // userB is on the list of splitReceivers of userA
require userId2 != userC_Id; // the second splitReceiver is not userC
require userId2 != userA_Id; // the second splitReceiver is not the splitter itself
require userId2 == userD_Id; // since we run with loop_iter 2, there are max 2 receivers
// obtaining splittable/collectable states after calling split()
uint128 userC_splittableAfter = splittable(e, userC_Id, assetId);
uint128 userC_collectableAfter = collectable(e, userC_Id, assetId);
uint128 userD_splittableAfter = splittable(e, userD_Id, assetId);
uint128 userD_collectableAfter = collectable(e, userD_Id, assetId);
// UserA's splittable should NOT increase
/// @notice The sanity rule should always fail.
rule sanity {
method f; env e; calldataarg args;
f(e, args);
assert false,
""This rule should always fail"";
assert userA_splittableAfter <= userA_splittableBefore;
assert userA_splittableAfter == 0; // it should be zero
// UserB is on the list of UserA's splitters, therefore ""userB's splittable should NOT decrease""
assert userB_splittableAfter >= userB_splittableBefore;
// UserC is NOT on the list of UserA's splitters, therefore ""userC's splittable should NOT change""
assert userC_splittableAfter == userC_splittableBefore;
// UserA's collectable should NOT decrease, UserB and UserC's collectable should NOT change
assert userA_collectableAfter >= userA_collectableBefore;
assert userB_collectableAfter == userB_collectableBefore;
assert userC_collectableAfter == userC_collectableBefore;
// The increase of the splittable of the receivers userB and userD should be equal the splittable of userA
assert (userB_splittableAfter - userB_splittableBefore) +
(userD_splittableAfter - userD_splittableBefore) +
(userA_collectableAfter - userA_collectableBefore) == userA_splittableBefore;
","split (Lines 343-349), | _setSplits (Lines 215-223), | _assertSplitsValid (Lines 229-247), "," function split(
uint256 userId,
IERC20 erc20,
SplitsReceiver[] memory currReceivers
) public whenNotPaused returns (uint128 collectableAmt, uint128 splitAmt) {
return Splits._split(userId, _assetId(erc20), currReceivers);
}
| function _setSplits(uint256 userId, SplitsReceiver[] memory receivers) internal {
SplitsState storage state = _splitsStorage().splitsStates[userId];
bytes32 newSplitsHash = _hashSplits(receivers);
emit SplitsSet(userId, newSplitsHash);
if (newSplitsHash != state.splitsHash) {
_assertSplitsValid(receivers, newSplitsHash);
state.splitsHash = newSplitsHash;
}
}
| function _assertSplitsValid(SplitsReceiver[] memory receivers, bytes32 receiversHash) internal {
require(receivers.length <= _MAX_SPLITS_RECEIVERS, ""Too many splits receivers"");
uint64 totalWeight = 0;
uint256 prevUserId;
for (uint256 i = 0; i < receivers.length; i++) {
SplitsReceiver memory receiver = receivers[i];
uint32 weight = receiver.weight;
require(weight != 0, ""Splits receiver weight is zero"");
totalWeight += weight;
uint256 userId = receiver.userId;
if (i > 0) {
require(prevUserId != userId, ""Duplicate splits receivers"");
require(prevUserId < userId, ""Splits receivers not sorted by user ID"");
}
prevUserId = userId;
emit SplitsReceiverSeen(receiversHash, userId, weight);
}
require(totalWeight <= _TOTAL_SPLITS_WEIGHT, ""Splits weights sum too high"");
}
",./radicle_drips/specs/Splits.spec,radicle_drips,,Yes,,"Functionality: Validate and update a user's split configurations, ensuring the total weights do not exceed a set limit, receivers have non-zero weights, are unique, properly sorted, and do not exceed a maximum number. Emit relevant events for updated splits and observed receivers for tracking purposes."
f96340bb5b2edebb42346d3192f88b3e,2248,rule,integrityOfPast,688,766,setDrips,"rule integrityOfPast(method f)
{
require requireValidSlots();
env e0; address erc20;
calldataarg args; uint256 dripperId; uint256 receiverId;
require erc20 == 0x100;
require dripperId == 1;
require receiverId == 2;
// setup one dripper and one receiver with start dripping timestamp of now
uint192 amtPerSec; uint32 start; uint32 duration;
require amtPerSec == 1;
require start == 5;
require duration == 100;
DH.DripsConfig configBefore = _helperCreateConfig(amtPerSec, start, duration);
require e0.block.timestamp == start;
int128 balanceDelta;
DH.DripsReceiver currReceiverBefore;
require currReceiverBefore.userId == 0; // this will force passing empty currReceivers
DH.DripsReceiver newReceiverBefore;
require newReceiverBefore.userId == receiverId;
require receiverId != 0;
require newReceiverBefore.config == configBefore;
//_helperSetDrips01(e0, dripperId, erc20, currReceiverBefore, balanceDelta, newReceiverBefore);
//helperSetDrips01(e0, dripperId, erc20, currReceiverBefore, balanceDelta, newReceiverBefore);
// let at least one cycle pass
uint32 cycleSecs = getCycleSecs();
require cycleSecs == 2;
env e1;
require e1.block.timestamp > e0.block.timestamp + cycleSecs;
// calculate the ReceivableDripsBefore of the receiver
// collectableAll() can be used if the user has also set splits
uint128 ReceivableDripsBefore; uint32 receivableCyclesBefore;
// type(uint32).max = 2^32 - 1 = 4294967295
ReceivableDripsBefore, receivableCyclesBefore = receivableDrips(e1, receiverId, erc20, 4294967295);
// change the dripper configuration to start dripping to the receiver in the future
// i.e. try to alter the past, as if the past dripping did not occur
// use the same amtPerSec and duration, only change the start time to the future
uint32 newStart;
require newStart > e1.block.timestamp + 10 * cycleSecs;
DH.DripsConfig configAfter = _helperCreateConfig(amtPerSec, newStart, duration);
DH.DripsReceiver newReceiverAfter;
require newReceiverAfter.userId == receiverId;
require newReceiverAfter.config == configAfter;
//_helperSetDrips11(e1, dripperId, erc20, newReceiverBefore, balanceDelta, newReceiverAfter);
//setDrips(e1, dripperId, erc20, _helperArrOfStruct(e1, newReceiverBefore), balanceDelta, _helperArrOfStruct(e1, newReceiverAfter));
//helperSetDrips11(e1, dripperId, erc20, newReceiverBefore, balanceDelta, newReceiverAfter);
// calculate again the ReceivableDripsAfter of the receiver
// at a time before the newStart begins
env e2;
require e2.block.timestamp > e1.block.timestamp;
require e2.block.timestamp < newStart;
uint128 ReceivableDripsAfter; uint32 receivableCyclesAfter;
ReceivableDripsAfter, receivableCyclesAfter = receivableDrips(e2, receiverId, erc20, 4294967295);
// validate that the past dripping stays, i.e. what was already dripped is still receivable
assert ReceivableDripsBefore == ReceivableDripsAfter;
assert false; // sanity
rule sanity(method f){
//uint32 cycleSecs = getCycleSecs();
//require cycleSecs == 2;
//setupState();
env e;
calldataarg args;
f(e,args);
assert false;
}
","setDrips (Lines 87-102), "," function setDrips(
IERC20 erc20,
DripsReceiver[] calldata currReceivers,
int128 balanceDelta,
DripsReceiver[] calldata newReceivers
) public returns (uint128 newBalance, int128 realBalanceDelta) {
if (balanceDelta > 0) _transferFromCaller(erc20, uint128(balanceDelta));
(newBalance, realBalanceDelta) = dripsHub.setDrips(
calcUserId(msg.sender),
erc20,
currReceivers,
balanceDelta,
newReceivers
);
if (realBalanceDelta < 0) erc20.safeTransfer(msg.sender, uint128(-realBalanceDelta));
}
",./radicle_drips/specs/DripsHub.spec,radicle_drips,,Yes,,"Functionality: This function adjusts a user's contributions to a DripsHub by transferring ERC20 tokens to or from the calling user, based on the desired balance change. It updates the user's drips configuration, transferring additional funds if increasing their balance or returning excess funds if decreasing."
f40242dd01fb5bcfc6a3fadde0825f66,2362 | 2363,rule,tokensNonInterference,120,170,deposit | withdraw,"rule tokensNonInterference() {
env e;
calldataarg args;
bool depositOrWithdraw;
address user;
uint256 amtDeposited;
uint256 amtWithdrawn;
uint256 tokenABalanceOfUserBefore; uint256 tokenABalanceOfUserAfter;
uint256 tokenBBalanceOfUserBefore; uint256 tokenBBalanceOfUserAfter;
uint256 tokenABalanceOfReserveBefore; uint256 tokenABalanceOfReserveAfter;
uint256 tokenBBalanceOfReserveBefore; uint256 tokenBBalanceOfReserveAfter;
uint256 tokenADepositedBefore; uint256 tokenADepositedAfter;
uint256 tokenBDepositedBefore; uint256 tokenBDepositedAfter;
tokenABalanceOfUserBefore = tokenA.balanceOf(user);
tokenBBalanceOfUserBefore = tokenB.balanceOf(user);
tokenABalanceOfReserveBefore = tokenA.balanceOf(reserveH);
tokenBBalanceOfReserveBefore = tokenB.balanceOf(reserveH);
tokenADepositedBefore = getDeposited(tokenA);
tokenBDepositedBefore = getDeposited(tokenB);
require tokenADepositedBefore == tokenABalanceOfReserveBefore;
require tokenBDepositedBefore == tokenBBalanceOfReserveBefore;
//require e.msg.sender != 0;
require reserveH.getPlugins(tokenA) == 0;
require reserveH.getPlugins(tokenB) == 0;
//deposit(e, tokenA, user, amtDeposited);
//f(e,args);
//withdraw(e, tokenA, user, amtWithdrawn);
if (depositOrWithdraw) {
deposit(e, tokenA, user, amtDeposited);
} else {
withdraw(e, tokenA, user, amtWithdrawn);
}
require amtDeposited == amtWithdrawn;
tokenABalanceOfUserAfter = tokenA.balanceOf(user);
tokenBBalanceOfUserAfter = tokenB.balanceOf(user);
tokenABalanceOfReserveAfter = tokenA.balanceOf(reserveH);
tokenBBalanceOfReserveAfter = tokenB.balanceOf(reserveH);
tokenADepositedAfter = getDeposited(tokenA);
tokenBDepositedAfter = getDeposited(tokenB);
assert tokenBBalanceOfUserBefore == tokenBBalanceOfUserAfter;
assert tokenBBalanceOfReserveBefore == tokenBBalanceOfReserveAfter;
assert tokenBDepositedBefore == tokenBDepositedAfter;
}
","deposit (Lines 171-182), | withdraw (Lines 191-203), "," function deposit(
IERC20 token,
address from,
uint256 amt
) public override onlyUser {
IReservePlugin plugin = plugins[token];
require(from != address(plugin) && from != address(this), ""Reserve: deposition from self"");
deposited[token] += amt;
_transfer(token, from, _pluginAddr(plugin), amt);
if (plugin != NO_PLUGIN) plugin.afterDeposition(token, amt);
emit Deposited(msg.sender, token, from, amt);
}
| function withdraw(
IERC20 token,
address to,
uint256 amt
) public override onlyUser {
uint256 balance = deposited[token];
require(balance >= amt, ""Reserve: withdrawal over balance"");
deposited[token] = balance - amt;
IReservePlugin plugin = plugins[token];
if (plugin != NO_PLUGIN) plugin.beforeWithdrawal(token, amt);
_transfer(token, _pluginAddr(plugin), to, amt);
emit Withdrawn(msg.sender, token, to, amt);
}
",./radicle_drips/specs/Reserve.spec,radicle_drips,,Yes,,"Functionality: Enable users to deposit and withdraw ERC20 tokens into a reserve, updating balances accordingly. It involves checking for self-depositions, handling plugin interactions before withdrawal and after deposition, and ensuring transactions do not exceed available balances. Events are emitted for both deposit and withdrawal actions."
efff4092bc3b8f8ce76091de03bbe3cb,2306 | 2308 | 2309,rule,should,466,523,split | _setSplits | _assertSplitsValid," ""This rule should always fail"";
}
*/
/// @notice front running split() does not affect receiver
/// userA has a single splitReceiver userC
/// userB also has the same single splitReceiver UserC
/// we want to verify split() can be called on userA successfully
/// even if someone front runs it and calls splits() first on userB
/// no assumptions about userA, userB, userC
rule cannotFrontRunSplitGeneralCase() {
env e; env e2; uint256 assetId; uint256 userA_Id; uint256 userB_Id; uint256 userC_Id;
uint128 userA_collectableAmt; uint128 userA_splitAmt;
uint128 userA_collectableAmt2; uint128 userA_splitAmt2;
uint128 userB_collectableAmt; uint128 userB_splitAmt;
uint128 userA_splittableBefore = splittable(e, userA_Id, assetId);
uint128 userB_splittableBefore = splittable(e, userB_Id, assetId);
uint128 userC_splittableBefore = splittable(e, userC_Id, assetId);
uint128 userA_collectableBefore = collectable(e, userA_Id, assetId);
uint128 userB_collectableBefore = collectable(e, userB_Id, assetId);
uint128 userC_collectableBefore = collectable(e, userC_Id, assetId);
// prevents overflow of the splittable of the receiver userC:
/// are invariant of the split
rule moneyNotLostOrCreatedDuringSplit() {
env e; uint256 assetId;
uint256 userA_Id; uint256 userB_Id;
// setting up the currReceivers[] of userA
uint256 length; uint256 index1; uint256 userId1; uint32 weight1;
userId1, weight1 = getCurrSplitsReceiverLocalArr(e, true, index1);
length = getCurrSplitsReceiverLocaLength(e, true);
require length == 1; // only one splitsReceiver
require userId1 == userB_Id; // making sure it is userB (not limiting it to be userA)
require weight1 <= 1000000; // safe assumptions since the function _assertSplitsValid()
// verified that totalWeight <= _TOTAL_SPLITS_WEIGHT upon _setSplits()
// we required that there is only one receiver, therefore totalWeight = weight1
// _TOTAL_SPLITS_WEIGHT == 1000000, hence the assumption above is safe
// recording the state before split()
// calling the split() on userA
uint128 userA_collectableAmt; uint128 userA_splitAmt;
userA_collectableAmt, userA_splitAmt = split(e, userA_Id, assetId, true);
// recording the state after split()
uint128 userA_splittableAfter = splittable(e, userA_Id, assetId);
uint128 userA_collectableAfter = collectable(e, userA_Id, assetId);
uint128 userB_splittableAfter = splittable(e, userB_Id, assetId);
uint128 userB_collectableAfter = collectable(e, userB_Id, assetId);
// the expectation:
uint128 moneyBefore = userA_splittableBefore + userA_collectableBefore + userB_splittableBefore + userB_collectableBefore;
uint128 moneyAfter = userA_splittableAfter + userA_collectableAfter + userB_splittableAfter + userB_collectableAfter;
assert moneyBefore == moneyAfter;
require userA_splittableBefore + userB_splittableBefore + userC_splittableBefore < 2^128;
// prevents overflow of the collectable of the splitters userA and userB:
require userA_collectableBefore + userA_splittableBefore < 2^128;
require userB_collectableBefore + userB_splittableBefore < 2^128;
// prevents overflow in the edge cases of (userC == userA) or (userC == userB):
require userA_collectableBefore + userA_splittableBefore + userB_splittableBefore < 2^128;
require userB_collectableBefore + userB_splittableBefore + userA_splittableBefore < 2^128;
// setting up the currReceivers[] of userA and userB to be the same - singe receiver userC
uint256 length1 = getCurrSplitsReceiverLocaLength(e, true);
require length1 == 1; // only one receiver
uint256 index1; uint256 userId1; uint32 weight1;
require userId1 == userC_Id;
require weight1 <= 1000000; // safe assumption
require weight1 > 0; // safe assumption
// safe assumptions since the function _assertSplitsValid()
// verified that totalWeight <= _TOTAL_SPLITS_WEIGHT upon _setSplits()
// we required that there is only one receiver, therefore totalWeight = weight1
// _TOTAL_SPLITS_WEIGHT == 1000000, hence the assumption above is safe
// also _assertSplitsValid() verified that weight != 0
storage initStorage = lastStorage;
uint128 userC_splittableAfterSplitA = splittable(e, userC_Id, assetId);
userB_collectableAmt, userB_splitAmt = split(e, userB_Id, assetId, true) at initStorage;
uint128 userC_splittableAfterSplitB = splittable(e, userC_Id, assetId);
userA_collectableAmt2, userA_splitAmt2 = split@withrevert(e, userA_Id, assetId, true);
assert !lastReverted;
","split (Lines 343-349), | _setSplits (Lines 215-223), | _assertSplitsValid (Lines 229-247), "," function split(
uint256 userId,
IERC20 erc20,
SplitsReceiver[] memory currReceivers
) public whenNotPaused returns (uint128 collectableAmt, uint128 splitAmt) {
return Splits._split(userId, _assetId(erc20), currReceivers);
}
| function _setSplits(uint256 userId, SplitsReceiver[] memory receivers) internal {
SplitsState storage state = _splitsStorage().splitsStates[userId];
bytes32 newSplitsHash = _hashSplits(receivers);
emit SplitsSet(userId, newSplitsHash);
if (newSplitsHash != state.splitsHash) {
_assertSplitsValid(receivers, newSplitsHash);
state.splitsHash = newSplitsHash;
}
}
| function _assertSplitsValid(SplitsReceiver[] memory receivers, bytes32 receiversHash) internal {
require(receivers.length <= _MAX_SPLITS_RECEIVERS, ""Too many splits receivers"");
uint64 totalWeight = 0;
uint256 prevUserId;
for (uint256 i = 0; i < receivers.length; i++) {
SplitsReceiver memory receiver = receivers[i];
uint32 weight = receiver.weight;
require(weight != 0, ""Splits receiver weight is zero"");
totalWeight += weight;
uint256 userId = receiver.userId;
if (i > 0) {
require(prevUserId != userId, ""Duplicate splits receivers"");
require(prevUserId < userId, ""Splits receivers not sorted by user ID"");
}
prevUserId = userId;
emit SplitsReceiverSeen(receiversHash, userId, weight);
}
require(totalWeight <= _TOTAL_SPLITS_WEIGHT, ""Splits weights sum too high"");
}
",./radicle_drips/specs/Splits.spec,radicle_drips,,Yes,,"Functionality: Validate and record splitting configurations for users, ensuring that each split configuration has unique, non-zero-weighted receivers sorted by user ID, does not exceed the maximum number of receivers or the total permissible weight, and emits events for changes in splits settings and validations."
9597955c8e2bbe3631118f5f7c3e7f61,2397,rule,solvency,109,146,_tokenBalanceOf,"rule solvency(address token, address from, address to,
uint256 amount, uint256 share, method f,
uint256 _strategy,
uint256 strategy_,
address straToken,
uint256 _systemBalance,
uint256 systemBalance_,
uint256 _strategyBalance,
uint256 strategyBalance_ ) {
//link the strategy to the current token
require strategyInstance.token() == token;
// link the strategy owner to the bentobox
require strategyInstance.owner() == currentContract;
require harnessBorrower() == borrower;
require harnessToken() == token;
mathint _actual = tokenBalanceOf(token); //casting form uint256
require _systemBalance == tokenBalanceOfUser(token, currentContract);
mathint _asElastic = totalTokenAmount(token); //casting from uint128
require _actual == _asElastic;
require _strategy == getStrategyTokenBalance(token);
require straToken == strategy(token);
//proven in zeroStrategy
invariant zeroStrategy(address token)
strategy(token) == 0 => getStrategyTokenBalance(token) == 0
invariant integrityOfTotalShare(address token)
totalTokenShare(token) == shareSum(token)
// Rules
/**
* solvency:
require straToken == 0 => _strategy == 0;
require _strategyBalance == tokenBalanceOfUser(token, straToken);
env e;
calldataarg args;
callFunctionWithParams(token, from, to, amount, share, f);
mathint actual_ = tokenBalanceOf(token); //casting form uint256
require systemBalance_ == tokenBalanceOfUser(token, currentContract);
mathint asElastic_ = totalTokenAmount(token); //casting from uint128
require strategy_ == getStrategyTokenBalance(token);
assert actual_ >= asElastic_, ""system solvency is broken"";
}
* internal representation of total assets:
* _tokenBalanceOf(token) >= totals[token].elastics
* checking if the the total assets within the BentoBox and outside
* the BentoBox are preserved
*/
","_tokenBalanceOf (Lines 762-764), "," function _tokenBalanceOf(IERC20 token) internal view returns (uint256 amount) {
amount = token.balanceOf(address(this)).add(strategyData[token].balance);
}
",./sushi_benttobox/spec/bentoBoxCompoundStrategy.spec,sushi_benttobox,,Yes,,"Functionality: Retrieve and sum the current balance of a specified ERC20 token held by the contract with any additional balance recorded in the contract's strategy data, then return the total amount as a uint256 variable."
7e9aac58bbbccc00c71b63c64ab4325f,2412,rule,validDecreaseToBalanceOf,198,213,transferMultiple,"rule validDecreaseToBalanceOf(address token, address a,
address from, address to,
address other, method f) {
uint256 amount;
uint256 share;
require from == harnessFrom();
uint256 vBefore = balanceOf(token, a);
callFunctionWithParams(token, from, to, amount, share, f);
uint256 vAfter = balanceOf(token, a);
assert (vBefore > vAfter => ( from == a && (
f.selector == transfer(address, address, address, uint256).selector ||
f.selector == withdraw(address, address, address, uint256, uint256).selector ||
f.selector == transferMultiple(address, address, address[], uint256[]).selector)));
}
","transferMultiple (Lines 42-51), "," function transferMultiple(IERC20 token, address from, address[] calldata tos, uint256[] calldata shares) public override {
require (tos.length <= 3);
// this would not constraint tos for any other rule except noChangeToOthersBalances,
// because harnessOther is only constraint in noChangeToOthersBalances
assumeTosNotOther(tos, harnessOther);
require(from == harnessFrom);
super.transferMultiple(token, from, tos, shares);
}
",./sushi_benttobox/spec/bentoBoxCompoundStrategy.spec,sushi_benttobox,,Yes,,"Functionality: Enforce restrictions on bulk token transfers by verifying that the number of recipient addresses (`tos`) does not exceed three, ensuring these addresses are not a specific unauthorized address (`harnessOther`), and confirming the sender (`from`) matches a predetermined address (`harnessFrom`) before executing the transfer."
f6e4ce1109082cda4c2c1c2473673d39,2642,rule,named,135,151,toBase," Contributes to proof of rule named ""Identity"" in GDoc.
*/
rule toElasticAndToBaseAreInverse2down {
bool roundUp = false;
uint128 base1 = getBase();
uint128 elastic1 = getElastic();
require base1 != 0 && elastic1 != 0;
uint256 amount;
uint256 amountToBase = toBase(amount, roundUp);
uint256 amountToBaseToElastic = toElastic(amountToBase, roundUp);
uint256 error_margin2 = elastic1 / base1 + 1;
assert only_slightly_larger_than(amount, amountToBaseToElastic, error_margin2);
}
","toBase (Lines 21-23), "," function toBase(uint256 elastic, bool roundUp) public view returns (uint256 base) {
base = rebase.toBase(elastic, roundUp);
}
",./sushi_benttobox/spec/rebase.spec,sushi_benttobox,,Yes,,"Functionality: Convert a specified amount (elastic) into its base equivalent by calling the `toBase` method from the `rebase` object. Additionally, the conversion adheres to a rounding direction specified by the `roundUp` boolean, determining whether to round the resulting base value up or not."
e1b2e43f16e886fc37949cddfb10f341,2441,rule,validDecreaseToBalanceOf,182,197,transferMultiple,"rule validDecreaseToBalanceOf(address token, address a,
address from, address to,
address other, method f) {
uint256 amount;
uint256 share;
require from == harnessFrom();
uint256 vBefore = balanceOf(token, a);
callFunctionWithParams(token, from, to, amount, share, f);
uint256 vAfter = balanceOf(token, a);
assert (vBefore > vAfter => ( from == a && (
f.selector == transfer(address, address, address, uint256).selector ||
f.selector == withdraw(address, address, address, uint256, uint256).selector ||
f.selector == transferMultiple(address, address, address[], uint256[]).selector)));
}
","transferMultiple (Lines 42-51), "," function transferMultiple(IERC20 token, address from, address[] calldata tos, uint256[] calldata shares) public override {
require (tos.length <= 3);
// this would not constraint tos for any other rule except noChangeToOthersBalances,
// because harnessOther is only constraint in noChangeToOthersBalances
assumeTosNotOther(tos, harnessOther);
require(from == harnessFrom);
super.transferMultiple(token, from, tos, shares);
}
",./sushi_benttobox/spec/bentobox.spec,sushi_benttobox,,Yes,,"Functionality: Enforce a rule where only a maximum of three recipients can be specified for a token transfer operation from a single source. Additionally, ensure that the transaction originates only from a specified address and excludes any transfers that might affect a predefined set of balances negatively."
d296507cc1113d76649bdf4021822e7c,2388 | 2389,rule,integrityExit,152,165,exit | checkAplusBeqC,"rule integrityExit(uint256 balance) {
require receiver() == receiverInstance;
env e;
uint256 balanceBefore = tokenBalanceOf(tokenInstance,receiverInstance);
int256 amountAdded = exit(e, balance);
uint256 balanceAfter = tokenBalanceOf(tokenInstance,receiverInstance);
mathint t = balanceBefore + balance;
require t <= MAX_UNSIGNED_INT();
uint256 expectedBalance = balanceBefore + balance;
assert checkAplusBeqC(expectedBalance, amountAdded, balanceAfter), ""wrong balance transfered to receiver"";
}","exit (Lines 46-50), | checkAplusBeqC (Lines 28-36), "," function exit(uint256 balance) external override returns (int256 amountAdded) {
uint256 b = getCurrentBalance(balance);
token.transfer(receiver, b);
return safeSub(b, balance);
}
| function checkAplusBeqC(uint256 a, int256 b, uint256 c) public returns (bool) {
if (b >= 0) {
uint256 b_ = uint256(b);
return a.add(b_) == c;
} else if (b < 0) {
uint256 b_ = uint256(-b);
return a.sub(b_) == c;
}
}
",./sushi_benttobox/spec/compoundStrategy.spec,sushi_benttobox,,Yes,,"Functionality: Transfer a specific balance amount from the token to the receiver and return the difference between the final balance and the initial balance. Additionally, evaluate whether the sum of the first number and a signed second number equals the third number, handling both positive and negative cases for the second number."
28cad6aafbbf352327b1ba4df3d94fdb,2392,invariant,zeroStrategy,94,146,_tokenBalanceOf,"invariant zeroStrategy(address token)
strategy(token) == 0 => getStrategyTokenBalance(token) == 0
invariant integrityOfTotalShare(address token)
totalTokenShare(token) == shareSum(token)
// Rules
/**
* solvency:
rule solvency(address token, address from, address to,
uint256 amount, uint256 share, method f,
uint256 _strategy,
uint256 strategy_,
address straToken,
uint256 _systemBalance,
uint256 systemBalance_,
uint256 _strategyBalance,
uint256 strategyBalance_ ) {
//link the strategy to the current token
require strategyInstance.token() == token;
// link the strategy owner to the bentobox
require strategyInstance.owner() == currentContract;
require harnessBorrower() == borrower;
require harnessToken() == token;
mathint _actual = tokenBalanceOf(token); //casting form uint256
require _systemBalance == tokenBalanceOfUser(token, currentContract);
mathint _asElastic = totalTokenAmount(token); //casting from uint128
require _actual == _asElastic;
require _strategy == getStrategyTokenBalance(token);
require straToken == strategy(token);
//proven in zeroStrategy
require straToken == 0 => _strategy == 0;
require _strategyBalance == tokenBalanceOfUser(token, straToken);
env e;
calldataarg args;
callFunctionWithParams(token, from, to, amount, share, f);
mathint actual_ = tokenBalanceOf(token); //casting form uint256
require systemBalance_ == tokenBalanceOfUser(token, currentContract);
mathint asElastic_ = totalTokenAmount(token); //casting from uint128
require strategy_ == getStrategyTokenBalance(token);
assert actual_ >= asElastic_, ""system solvency is broken"";
}
* internal representation of total assets:
* _tokenBalanceOf(token) >= totals[token].elastics
* checking if the the total assets within the BentoBox and outside
* the BentoBox are preserved
*/
","_tokenBalanceOf (Lines 762-764), "," function _tokenBalanceOf(IERC20 token) internal view returns (uint256 amount) {
amount = token.balanceOf(address(this)).add(strategyData[token].balance);
}
",./sushi_benttobox/spec/bentoBoxCompoundStrategy.spec,sushi_benttobox,,Yes,,Functionality: Calculate the total balance of a specific ERC20 token associated with the contract by summing the token's balance directly held by the contract and the balance recorded in a separate strategy data structure for that token.
79c9aec6f0686cbc25a0242e49b76a72,2379,rule,ifExitedIsTrueThenMethodsRevertExceptOwner,101,113,claimOwnership,"rule ifExitedIsTrueThenMethodsRevertExceptOwner() {
env e;
require exited() == true;
method f;
calldataarg args;
require !f.isView && f.selector != claimOwnership().selector;
require e.msg.sender != owner();
f@withrevert(e, args);
assert(lastReverted, ""Methods didn't revert"");
}
","claimOwnership (Lines 386-396), "," function claimOwnership() public {
address _pendingOwner = pendingOwner;
// Checks
require(msg.sender == _pendingOwner, ""Ownable: caller != pending owner"");
// Effects
emit OwnershipTransferred(owner, _pendingOwner);
owner = _pendingOwner;
pendingOwner = address(0);
}
",./sushi_benttobox/spec/compoundStrategy.spec,sushi_benttobox,,Yes,,"Functionality: Transfer the contract's ownership to a pre-designated pending owner. It verifies that the caller of this function is the current pending owner, then emits an event signaling the transfer of ownership, updates the contract's owner to the new owner, and resets the pending owner to a null address."
09961ed97c1b3fd554fc854fbe72872a,2450,rule,toBaseIsMonotone,48,56,toBase,"rule toBaseIsMonotone {
bool roundUp;
uint x;
uint y;
require x < y;
uint xToBase = toBase(x, roundUp);
uint yToBase = toBase(y, roundUp);
assert xToBase <= yToBase;
}
","toBase (Lines 21-23), "," function toBase(uint256 elastic, bool roundUp) public view returns (uint256 base) {
base = rebase.toBase(elastic, roundUp);
}
",./sushi_benttobox/spec/rebase.spec,sushi_benttobox,,Yes,,"Functionality: Convert an amount specified in the elastic unit to the base unit using the `rebase` object's `toBase` method, optionally rounding up the result. The conversion is defined by the rebase mechanism's underlying logic, which typically involves adjusting for accumulated interest or contract-specific scaling factors."
8f1ff28b8387f64d1e0676b313659db6,2364 | 2366,rule,integrityHarvest,46,67,harvest | checkAplusBeqC,"rule integrityHarvest(uint256 balance, uint256 strategyBalanceBefore) {
require receiver() == receiverInstance;
require strategyBalanceBefore == tokenInstance.balanceOf(currentContract);
uint256 balanceBefore = tokenInstance.balanceOf(receiverInstance);
env e;
int256 amountAdded = harvest(e, balance,_);
require amountAdded < MIN_INT();
uint256 strategyBalanceAfter = tokenInstance.balanceOf(currentContract);
uint256 balanceAfter = tokenInstance.balanceOf(receiverInstance);
if (compareGTzero(amountAdded)) {
// strategy made profit
assert checkAplusBeqC(balanceBefore, amountAdded, balanceAfter), ""wrong balance transfered to receiver"";
} else {
// strategy made loss
assert balanceBefore == balanceAfter, ""balance should not change if profit is negative"";
}
}
","harvest (Lines 26-33), | checkAplusBeqC (Lines 28-36), "," function harvest(uint256 balance, address sender) external override returns (int256 amountAdded) {
uint256 b = getCurrentBalance(balance);
int256 gain = safeSub(b, balance);
if (gain > 0) {
token.transfer(receiver, uint256(gain));
}
return gain;
}
| function checkAplusBeqC(uint256 a, int256 b, uint256 c) public returns (bool) {
if (b >= 0) {
uint256 b_ = uint256(b);
return a.add(b_) == c;
} else if (b < 0) {
uint256 b_ = uint256(-b);
return a.sub(b_) == c;
}
}
",./sushi_benttobox/spec/strategy.spec,sushi_benttobox,,Yes,,"Functionality: Calculate and transfer the positive gains of a balance to a receiver by subtracting the initial balance from the current balance. Also, verify if the sum or difference of two numbers (a plus/minus b) equals a third number (c), handling both positive and negative cases for b."
9a553dd57f62d2198f955fd7453a7dc5,2421,invariant,zeroStrategy,78,130,_tokenBalanceOf,"invariant zeroStrategy(address token)
strategy(token) == 0 => getStrategyTokenBalance(token) == 0
invariant integrityOfTotalShare(address token)
totalTokenShare(token) == shareSum(token)
// Rules
/**
* solvency:
rule solvency(address token, address from, address to,
uint256 amount, uint256 share, method f,
uint256 _strategy,
uint256 strategy_,
address straToken,
uint256 _systemBalance,
uint256 systemBalance_,
uint256 _strategyBalance,
uint256 strategyBalance_ ) {
//link the strategy to the current token
require strategyInstance.token() == token;
// link the strategy owner to the bentobox
require strategyInstance.owner() == currentContract;
require harnessBorrower() == borrower;
require harnessToken() == token;
mathint _actual = tokenBalanceOf(token); //casting form uint256
require _systemBalance == tokenBalanceOfUser(token, currentContract);
mathint _asElastic = totalTokenAmount(token); //casting from uint128
require _actual == _asElastic;
require _strategy == getStrategyTokenBalance(token);
require straToken == strategy(token);
//proven in zeroStrategy
require straToken == 0 => _strategy == 0;
require _strategyBalance == tokenBalanceOfUser(token, straToken);
env e;
calldataarg args;
callFunctionWithParams(token, from, to, amount, share, f);
mathint actual_ = tokenBalanceOf(token); //casting form uint256
require systemBalance_ == tokenBalanceOfUser(token, currentContract);
mathint asElastic_ = totalTokenAmount(token); //casting from uint128
require strategy_ == getStrategyTokenBalance(token);
assert actual_ >= asElastic_, ""system solvency is broken"";
}
* internal representation of total assets:
* _tokenBalanceOf(token) >= totals[token].elastics
* checking if the the total assets within the BentoBox and outside
* the BentoBox are preserved
*/
","_tokenBalanceOf (Lines 762-764), "," function _tokenBalanceOf(IERC20 token) internal view returns (uint256 amount) {
amount = token.balanceOf(address(this)).add(strategyData[token].balance);
}
",./sushi_benttobox/spec/bentobox.spec,sushi_benttobox,,Yes,,"Functionality: Calculate and return the combined total balance of a specified ERC20 token, considering both the balance held directly by the contract and an additional amount potentially managed by a strategy, as indicated in `strategyData` for that token."
5b6710c4341e78f1615e26805e65fcc4,518 | 519 | 520 | 522 | 524,rule,integrityOfEmpty,128,132,isUsingAsCollateralOrBorrowing | isBorrowing | isUsingAsCollateral | isUsingAsCollateralAny | isBorrowingAny,"// rule integrityOfEmpty(uint256 reserveIndex){
// bool borrowingOrCollateral = isUsingAsCollateralOrBorrowing(reserveIndex);
invariant isUsingAsCollateralOrBorrowing(uint256 reserveIndex )
(isUsingAsCollateral(reserveIndex) || isBorrowing(reserveIndex)) <=> isUsingAsCollateralOrBorrowing(reserveIndex)
// // if at 1 asset is used as collateral and isUsingAsCollateralOne, then any other asset is not used as collateral
// rule integrityOfisUsingAsCollateralOne(uint256 reserveIndex, uint256 reserveIndexOther){
invariant integrityOfisUsingAsCollateralOne(uint256 reserveIndex, uint256 reserveIndexOther)
isUsingAsCollateral(reserveIndex) && isUsingAsCollateralOne() =>
!isUsingAsCollateral(reserveIndexOther) || reserveIndexOther == reserveIndex
// // if at least 1 asset is used as collateral, isUsingAsCollateralAny is true
// // ** not implmented yet - if isUsingAsCollateralAny is true then there exist at least 1 asset that is being used as collateral
// rule integrityOfisUsingAsCollateralAny(uint256 reserveIndex){
invariant integrityOfisUsingAsCollateralAny(uint256 reserveIndex)
isUsingAsCollateral(reserveIndex) => isUsingAsCollateralAny()
// // if at 1 asset is used for borrowing and isBorrowingOne, then any other asset is not used for borrowing
// rule integrityOfisBorrowingOne(uint256 reserveIndex, uint256 reserveIndexOther){
invariant integrityOfisBorrowingOne(uint256 reserveIndex, uint256 reserveIndexOther)
isBorrowing(reserveIndex) && isBorrowingOne() => !isBorrowing(reserveIndexOther) || reserveIndexOther == reserveIndex
// // if at least 1 asset is borrowed, isBorrowing is true
// // ** not implmented yet - if isBorrowingAny is true then there exist at least 1 asset that is being used for borrowing
// rule integrityOfisBorrowingAny(uint256 reserveIndex){
invariant integrityOfisBorrowingAny(uint256 reserveIndex)
isBorrowing(reserveIndex) => isBorrowingAny()
// // if user data is empty then for any index neither borrowing nor collateral is set
invariant integrityOfEmpty(uint256 reserveIndex)
isEmpty() => !isBorrowingAny() && !isUsingAsCollateralOrBorrowing(reserveIndex)
// invariant notEmpty(uint256 reserveIndex)
// (isBorrowingAny() || isUsingAsCollateral(reserveIndex)) => !isEmpty()
// if IsolationModeState is active then there must be exactly one asset register as collateral.
// note that this is a necessary requirement, but it is not sufficient.
rule integrityOfIsolationModeState(){
// invariant integrityOfIsolationModeState(calldataarg args)
// !isUsingAsCollateralOne() => !isIsolated()
rule integrityOfSiloedBorrowingState(){
bool existExactlyOneBorrow = isBorrowingOne();
bool answer; address asset;
answer, asset = getSiloedBorrowingState();
assert answer => existExactlyOneBorrow;
}
bool existExactlyOneCollateral = isUsingAsCollateralOne();
bool answer; address asset; uint256 ceiling;
answer, asset, ceiling = getIsolationModeState();
assert answer => existExactlyOneCollateral;
// bool anyBorrowed = isBorrowingAny();
// assert isEmpty() => !borrowingOrCollateral;
// }
// bool reserveBorrowing = isBorrowing(reserveIndex);
// assert reserveBorrowing => isBorrowingAny();
// // assert exists uint256 index. isBorrowingAny() => isBorrowing(index);
// bool reserveBorrowingOther = isBorrowing(reserveIndexOther);
// assert reserveBorrowing && isBorrowingOne() => !reserveBorrowingOther || reserveIndexOther == reserveIndex;
// bool reserveCollateral = isUsingAsCollateral(reserveIndex);
// assert reserveCollateral => isUsingAsCollateralAny();
// // assert exists uint256 index. isUsingAsCollateralAny() => isUsingAsCollateral(index);
// bool reserveCollateralOther = isUsingAsCollateral(reserveIndexOther);
// assert reserveCollateral && isUsingAsCollateralOne() => !reserveCollateralOther || reserveIndexOther == reserveIndex;
","isUsingAsCollateralOrBorrowing (Lines 71-79), | isBorrowing (Lines 87-95), | isUsingAsCollateral (Lines 103-111), | isUsingAsCollateralAny (Lines 131-135), | isBorrowingAny (Lines 153-155), "," function isUsingAsCollateralOrBorrowing(
DataTypes.UserConfigurationMap memory self,
uint256 reserveIndex
) internal pure returns (bool) {
unchecked {
require(reserveIndex < ReserveConfiguration.MAX_RESERVES_COUNT, Errors.INVALID_RESERVE_INDEX);
return (self.data >> (reserveIndex << 1)) & 3 != 0;
}
}
| function isBorrowing(
DataTypes.UserConfigurationMap memory self,
uint256 reserveIndex
) internal pure returns (bool) {
unchecked {
require(reserveIndex < ReserveConfiguration.MAX_RESERVES_COUNT, Errors.INVALID_RESERVE_INDEX);
return (self.data >> (reserveIndex << 1)) & 1 != 0;
}
}
| function isUsingAsCollateral(
DataTypes.UserConfigurationMap memory self,
uint256 reserveIndex
) internal pure returns (bool) {
unchecked {
require(reserveIndex < ReserveConfiguration.MAX_RESERVES_COUNT, Errors.INVALID_RESERVE_INDEX);
return (self.data >> ((reserveIndex << 1) + 1)) & 1 != 0;
}
}
| function isUsingAsCollateralAny(
DataTypes.UserConfigurationMap memory self
) internal pure returns (bool) {
return self.data & COLLATERAL_MASK != 0;
}
| function isBorrowingAny(DataTypes.UserConfigurationMap memory self) internal pure returns (bool) {
return self.data & BORROWING_MASK != 0;
}
",./aave_v3/specs/UserConfiguration.spec,aave_v3,,Yes,,"Functionality: Determine the borrowing and collateral usage status of a user within a financial protocol. The code checks if a user is using assets as collateral, borrowing, or engaging in any of these activities, leveraging bitwise operations to query the user's configuration stored as a compact data structure."
0b98e96bc072889dd6362ca32821031f,418 | 419,rule,burnNoChangeToOther,271,287,balanceOf | burn,"rule burnNoChangeToOther(address user, address recieverOfUnderlying, uint256 amount, uint256 index, address other)
{
require other != user && other != recieverOfUnderlying;
env e;
uint256 otherDataBefore = additionalData(other);
uint256 otherBalanceBefore = balanceOf(other);
burn(e, user, recieverOfUnderlying, amount, index);
uint256 otherDataAfter = additionalData(other);
uint256 otherBalanceAfter = balanceOf(other);
assert otherDataBefore == otherDataAfter &&
otherBalanceBefore == otherBalanceAfter;
}
","balanceOf (Lines 101-112), | burn (Lines 178-245), "," function balanceOf(address account) public view virtual override returns (uint256) {
uint256 accountBalance = super.balanceOf(account);
uint256 stableRate = _userState[account].additionalData;
if (accountBalance == 0) {
return 0;
}
uint256 cumulatedInterest = MathUtils.calculateCompoundedInterest(
stableRate,
_timestamps[account]
);
return accountBalance.rayMul(cumulatedInterest);
}
| function burn(
address from,
uint256 amount
) external virtual override onlyPool returns (uint256, uint256) {
(, uint256 currentBalance, uint256 balanceIncrease) = _calculateBalanceIncrease(from);
uint256 previousSupply = totalSupply();
uint256 nextAvgStableRate = 0;
uint256 nextSupply = 0;
uint256 userStableRate = _userState[from].additionalData;
// Since the total supply and each single user debt accrue separately,
// there might be accumulation errors so that the last borrower repaying
// might actually try to repay more than the available debt supply.
// In this case we simply set the total supply and the avg stable rate to 0
if (previousSupply <= amount) {
_avgStableRate = 0;
_totalSupply = 0;
} else {
nextSupply = _totalSupply = previousSupply - amount;
uint256 firstTerm = uint256(_avgStableRate).rayMul(previousSupply.wadToRay());
uint256 secondTerm = userStableRate.rayMul(amount.wadToRay());
// For the same reason described above, when the last user is repaying it might
// happen that user rate * user balance > avg rate * total supply. In that case,
// we simply set the avg rate to 0
if (secondTerm >= firstTerm) {
nextAvgStableRate = _totalSupply = _avgStableRate = 0;
} else {
nextAvgStableRate = _avgStableRate = (
(firstTerm - secondTerm).rayDiv(nextSupply.wadToRay())
).toUint128();
}
}
if (amount == currentBalance) {
_userState[from].additionalData = 0;
_timestamps[from] = 0;
} else {
//solium-disable-next-line
_timestamps[from] = uint40(block.timestamp);
}
//solium-disable-next-line
_totalSupplyTimestamp = uint40(block.timestamp);
if (balanceIncrease > amount) {
uint256 amountToMint = balanceIncrease - amount;
_mint(from, amountToMint, previousSupply);
emit Transfer(address(0), from, amountToMint);
emit Mint(
from,
from,
amountToMint,
currentBalance,
balanceIncrease,
userStableRate,
nextAvgStableRate,
nextSupply
);
} else {
uint256 amountToBurn = amount - balanceIncrease;
_burn(from, amountToBurn, previousSupply);
emit Transfer(from, address(0), amountToBurn);
emit Burn(from, amountToBurn, currentBalance, balanceIncrease, nextAvgStableRate, nextSupply);
}
return (nextSupply, nextAvgStableRate);
}
",./aave_v3/specs/AToken.spec,aave_v3,,Yes,,"Functionality: Adjust user and total balances within a lending protocol by calculating compounded interest for account balances, and manage token supply through burn or mint operations based on the repayment or accrual of interest, ensuring accounting integrity through dynamic total supply and rate adjustments."
34abe06e6ad3fdef0c1c59516bf3ec68,437 | 438 | 439 | 441 | 443,invariant,integrityOfisUsingAsCollateralOne,91,101,isUsingAsCollateralOrBorrowing | isBorrowing | isUsingAsCollateral | isUsingAsCollateralAny | isBorrowingAny,"invariant integrityOfisUsingAsCollateralOne(uint256 reserveIndex, uint256 reserveIndexOther)
isUsingAsCollateral(reserveIndex) && isUsingAsCollateralOne() =>
!isUsingAsCollateral(reserveIndexOther) || reserveIndexOther == reserveIndex
// // if at least 1 asset is used as collateral, isUsingAsCollateralAny is true
// // ** not implmented yet - if isUsingAsCollateralAny is true then there exist at least 1 asset that is being used as collateral
// rule integrityOfisUsingAsCollateralAny(uint256 reserveIndex){
invariant integrityOfisUsingAsCollateralAny(uint256 reserveIndex)
isUsingAsCollateral(reserveIndex) => isUsingAsCollateralAny()
// // if at 1 asset is used for borrowing and isBorrowingOne, then any other asset is not used for borrowing
// rule integrityOfisBorrowingOne(uint256 reserveIndex, uint256 reserveIndexOther){
invariant integrityOfisBorrowingOne(uint256 reserveIndex, uint256 reserveIndexOther)
isBorrowing(reserveIndex) && isBorrowingOne() => !isBorrowing(reserveIndexOther) || reserveIndexOther == reserveIndex
// // if at least 1 asset is borrowed, isBorrowing is true
// // ** not implmented yet - if isBorrowingAny is true then there exist at least 1 asset that is being used for borrowing
// rule integrityOfisBorrowingAny(uint256 reserveIndex){
invariant integrityOfisBorrowingAny(uint256 reserveIndex)
isBorrowing(reserveIndex) => isBorrowingAny()
// // if user data is empty then for any index neither borrowing nor collateral is set
// rule integrityOfEmpty(uint256 reserveIndex){
invariant integrityOfEmpty(uint256 reserveIndex)
isEmpty() => !isBorrowingAny() && !isUsingAsCollateralOrBorrowing(reserveIndex)
invariant isUsingAsCollateralOrBorrowing(uint256 reserveIndex )
(isUsingAsCollateral(reserveIndex) || isBorrowing(reserveIndex)) <=> isUsingAsCollateralOrBorrowing(reserveIndex)
// // if at 1 asset is used as collateral and isUsingAsCollateralOne, then any other asset is not used as collateral
// rule integrityOfisUsingAsCollateralOne(uint256 reserveIndex, uint256 reserveIndexOther){
// invariant notEmpty(uint256 reserveIndex)
// (isBorrowingAny() || isUsingAsCollateral(reserveIndex)) => !isEmpty()
// if IsolationModeState is active then there must be exactly one asset register as collateral.
// note that this is a necessary requirement, but it is not sufficient.
rule integrityOfIsolationModeState(){
// invariant integrityOfIsolationModeState(calldataarg args)
// !isUsingAsCollateralOne() => !isIsolated()
rule integrityOfSiloedBorrowingState(){
bool existExactlyOneBorrow = isBorrowingOne();
bool answer; address asset;
answer, asset = getSiloedBorrowingState();
assert answer => existExactlyOneBorrow;
}
bool existExactlyOneCollateral = isUsingAsCollateralOne();
bool answer; address asset; uint256 ceiling;
answer, asset, ceiling = getIsolationModeState();
assert answer => existExactlyOneCollateral;
// bool borrowingOrCollateral = isUsingAsCollateralOrBorrowing(reserveIndex);
// bool anyBorrowed = isBorrowingAny();
// assert isEmpty() => !borrowingOrCollateral;
// }
// bool reserveBorrowing = isBorrowing(reserveIndex);
// assert reserveBorrowing => isBorrowingAny();
// // assert exists uint256 index. isBorrowingAny() => isBorrowing(index);
// bool reserveBorrowingOther = isBorrowing(reserveIndexOther);
// assert reserveBorrowing && isBorrowingOne() => !reserveBorrowingOther || reserveIndexOther == reserveIndex;
// bool reserveCollateral = isUsingAsCollateral(reserveIndex);
// assert reserveCollateral => isUsingAsCollateralAny();
// // assert exists uint256 index. isUsingAsCollateralAny() => isUsingAsCollateral(index);
// bool reserveCollateralOther = isUsingAsCollateral(reserveIndexOther);
// assert reserveCollateral && isUsingAsCollateralOne() => !reserveCollateralOther || reserveIndexOther == reserveIndex;
","isUsingAsCollateralOrBorrowing (Lines 71-79), | isBorrowing (Lines 87-95), | isUsingAsCollateral (Lines 103-111), | isUsingAsCollateralAny (Lines 131-135), | isBorrowingAny (Lines 153-155), "," function isUsingAsCollateralOrBorrowing(
DataTypes.UserConfigurationMap memory self,
uint256 reserveIndex
) internal pure returns (bool) {
unchecked {
require(reserveIndex < ReserveConfiguration.MAX_RESERVES_COUNT, Errors.INVALID_RESERVE_INDEX);
return (self.data >> (reserveIndex << 1)) & 3 != 0;
}
}
| function isBorrowing(
DataTypes.UserConfigurationMap memory self,
uint256 reserveIndex
) internal pure returns (bool) {
unchecked {
require(reserveIndex < ReserveConfiguration.MAX_RESERVES_COUNT, Errors.INVALID_RESERVE_INDEX);
return (self.data >> (reserveIndex << 1)) & 1 != 0;
}
}
| function isUsingAsCollateral(
DataTypes.UserConfigurationMap memory self,
uint256 reserveIndex
) internal pure returns (bool) {
unchecked {
require(reserveIndex < ReserveConfiguration.MAX_RESERVES_COUNT, Errors.INVALID_RESERVE_INDEX);
return (self.data >> ((reserveIndex << 1) + 1)) & 1 != 0;
}
}
| function isUsingAsCollateralAny(
DataTypes.UserConfigurationMap memory self
) internal pure returns (bool) {
return self.data & COLLATERAL_MASK != 0;
}
| function isBorrowingAny(DataTypes.UserConfigurationMap memory self) internal pure returns (bool) {
return self.data & BORROWING_MASK != 0;
}
",./aave_v3/specs/UserConfiguration.spec,aave_v3,,Yes,,"Functionality: Determine the user's interaction with reserves in a decentralized finance protocol by checking if assets are being used as collateral or if there is any borrowing activity. These functions facilitate querying whether specific reserves are utilized for borrowing, used as collateral, or if any such activities exist across all reserves."
d286347bed34bbf33e877c5571387424,400,rule,permitIntegrity,58,65,permit,"rule permitIntegrity(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s)
{
env e;
uint256 nonceBefore = nonces(owner);
permit(e, owner, spender, value, deadline, v, r, s);
assert allowance(owner, spender) == value;
assert nonces(owner) == nonceBefore + 1;
}
","permit (Lines 170-193), "," function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external override {
require(owner != address(0), Errors.ZERO_ADDRESS_NOT_VALID);
//solium-disable-next-line
require(block.timestamp <= deadline, Errors.INVALID_EXPIRATION);
uint256 currentValidNonce = _nonces[owner];
bytes32 digest = keccak256(
abi.encodePacked(
'\x19\x01',
DOMAIN_SEPARATOR(),
keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, currentValidNonce, deadline))
)
);
require(owner == ecrecover(digest, v, r, s), Errors.INVALID_SIGNATURE);
_nonces[owner] = currentValidNonce + 1;
_approve(owner, spender, value);
}
",./aave_v3/specs/AToken.spec,aave_v3,,Yes,,"Functionality: Validate the signature for a permit to approve a spender by an owner within a deadline, using EIP-2612's permit method. It increases the nonce for the owner after authenticating the permit and approves the spender to spend a specified value of the owner's tokens."
9834b93a34f460bef753f707bca5e47f,594 | 595,rule,burnNoChangeToOther,292,307,balanceOf | burn,"rule burnNoChangeToOther(address user, uint256 amount, address other) {
require other != user;
env e;
uint256 otherDataBefore = additionalData(other);
uint256 otherBalanceBefore = balanceOf(e, other);
burn(e, user, amount);
uint256 otherDataAfter = additionalData(other);
uint256 otherBalanceAfter = balanceOf(e, other);
assert otherDataBefore == otherDataAfter &&
otherBalanceBefore == otherBalanceAfter;
}
","balanceOf (Lines 101-112), | burn (Lines 178-245), "," function balanceOf(address account) public view virtual override returns (uint256) {
uint256 accountBalance = super.balanceOf(account);
uint256 stableRate = _userState[account].additionalData;
if (accountBalance == 0) {
return 0;
}
uint256 cumulatedInterest = MathUtils.calculateCompoundedInterest(
stableRate,
_timestamps[account]
);
return accountBalance.rayMul(cumulatedInterest);
}
| function burn(
address from,
uint256 amount
) external virtual override onlyPool returns (uint256, uint256) {
(, uint256 currentBalance, uint256 balanceIncrease) = _calculateBalanceIncrease(from);
uint256 previousSupply = totalSupply();
uint256 nextAvgStableRate = 0;
uint256 nextSupply = 0;
uint256 userStableRate = _userState[from].additionalData;
// Since the total supply and each single user debt accrue separately,
// there might be accumulation errors so that the last borrower repaying
// might actually try to repay more than the available debt supply.
// In this case we simply set the total supply and the avg stable rate to 0
if (previousSupply <= amount) {
_avgStableRate = 0;
_totalSupply = 0;
} else {
nextSupply = _totalSupply = previousSupply - amount;
uint256 firstTerm = uint256(_avgStableRate).rayMul(previousSupply.wadToRay());
uint256 secondTerm = userStableRate.rayMul(amount.wadToRay());
// For the same reason described above, when the last user is repaying it might
// happen that user rate * user balance > avg rate * total supply. In that case,
// we simply set the avg rate to 0
if (secondTerm >= firstTerm) {
nextAvgStableRate = _totalSupply = _avgStableRate = 0;
} else {
nextAvgStableRate = _avgStableRate = (
(firstTerm - secondTerm).rayDiv(nextSupply.wadToRay())
).toUint128();
}
}
if (amount == currentBalance) {
_userState[from].additionalData = 0;
_timestamps[from] = 0;
} else {
//solium-disable-next-line
_timestamps[from] = uint40(block.timestamp);
}
//solium-disable-next-line
_totalSupplyTimestamp = uint40(block.timestamp);
if (balanceIncrease > amount) {
uint256 amountToMint = balanceIncrease - amount;
_mint(from, amountToMint, previousSupply);
emit Transfer(address(0), from, amountToMint);
emit Mint(
from,
from,
amountToMint,
currentBalance,
balanceIncrease,
userStableRate,
nextAvgStableRate,
nextSupply
);
} else {
uint256 amountToBurn = amount - balanceIncrease;
_burn(from, amountToBurn, previousSupply);
emit Transfer(from, address(0), amountToBurn);
emit Burn(from, amountToBurn, currentBalance, balanceIncrease, nextAvgStableRate, nextSupply);
}
return (nextSupply, nextAvgStableRate);
}
",./aave_v3/specs/StableDebtToken.spec,aave_v3,,Yes,,"Functionality: Adjust a user's account balance by calculating compounded interest based on their stable rate and timestamp, and manage the burning of tokens. This involves updating total supply, user stable rates, and average stable rates, while handling cases where the total supply becomes fully repaid or overpaid."
cd74f6164fe5b2edd58a2c20ba1ccdc0,586 | 587 | 588,rule,inverseMintBurn,201,208,mint | balanceOf | burn,"rule inverseMintBurn(address a, address delegatedUser, uint256 amount, uint256 rate) {
env e;
uint256 balancebefore = balanceOf(e, a);
mint(e, delegatedUser, a, amount, rate);
burn(e, a, amount);
uint256 balanceAfter = balanceOf(e, a);
assert balancebefore == balanceAfter, ""burn is not the inverse of mint"";
}
","mint (Lines 124-175), | balanceOf (Lines 101-112), | burn (Lines 178-245), "," function mint(
address user,
address onBehalfOf,
uint256 amount,
uint256 rate
) external virtual override onlyPool returns (bool, uint256, uint256) {
MintLocalVars memory vars;
if (user != onBehalfOf) {
_decreaseBorrowAllowance(onBehalfOf, user, amount);
}
(, uint256 currentBalance, uint256 balanceIncrease) = _calculateBalanceIncrease(onBehalfOf);
vars.previousSupply = totalSupply();
vars.currentAvgStableRate = _avgStableRate;
vars.nextSupply = _totalSupply = vars.previousSupply + amount;
vars.amountInRay = amount.wadToRay();
vars.currentStableRate = _userState[onBehalfOf].additionalData;
vars.nextStableRate = (vars.currentStableRate.rayMul(currentBalance.wadToRay()) +
vars.amountInRay.rayMul(rate)).rayDiv((currentBalance + amount).wadToRay());
_userState[onBehalfOf].additionalData = vars.nextStableRate.toUint128();
//solium-disable-next-line
_totalSupplyTimestamp = _timestamps[onBehalfOf] = uint40(block.timestamp);
// Calculates the updated average stable rate
vars.currentAvgStableRate = _avgStableRate = (
(vars.currentAvgStableRate.rayMul(vars.previousSupply.wadToRay()) +
rate.rayMul(vars.amountInRay)).rayDiv(vars.nextSupply.wadToRay())
).toUint128();
uint256 amountToMint = amount + balanceIncrease;
_mint(onBehalfOf, amountToMint, vars.previousSupply);
emit Transfer(address(0), onBehalfOf, amountToMint);
emit Mint(
user,
onBehalfOf,
amountToMint,
currentBalance,
balanceIncrease,
vars.nextStableRate,
vars.currentAvgStableRate,
vars.nextSupply
);
return (currentBalance == 0, vars.nextSupply, vars.currentAvgStableRate);
}
| function balanceOf(address account) public view virtual override returns (uint256) {
uint256 accountBalance = super.balanceOf(account);
uint256 stableRate = _userState[account].additionalData;
if (accountBalance == 0) {
return 0;
}
uint256 cumulatedInterest = MathUtils.calculateCompoundedInterest(
stableRate,
_timestamps[account]
);
return accountBalance.rayMul(cumulatedInterest);
}
| function burn(
address from,
uint256 amount
) external virtual override onlyPool returns (uint256, uint256) {
(, uint256 currentBalance, uint256 balanceIncrease) = _calculateBalanceIncrease(from);
uint256 previousSupply = totalSupply();
uint256 nextAvgStableRate = 0;
uint256 nextSupply = 0;
uint256 userStableRate = _userState[from].additionalData;
// Since the total supply and each single user debt accrue separately,
// there might be accumulation errors so that the last borrower repaying
// might actually try to repay more than the available debt supply.
// In this case we simply set the total supply and the avg stable rate to 0
if (previousSupply <= amount) {
_avgStableRate = 0;
_totalSupply = 0;
} else {
nextSupply = _totalSupply = previousSupply - amount;
uint256 firstTerm = uint256(_avgStableRate).rayMul(previousSupply.wadToRay());
uint256 secondTerm = userStableRate.rayMul(amount.wadToRay());
// For the same reason described above, when the last user is repaying it might
// happen that user rate * user balance > avg rate * total supply. In that case,
// we simply set the avg rate to 0
if (secondTerm >= firstTerm) {
nextAvgStableRate = _totalSupply = _avgStableRate = 0;
} else {
nextAvgStableRate = _avgStableRate = (
(firstTerm - secondTerm).rayDiv(nextSupply.wadToRay())
).toUint128();
}
}
if (amount == currentBalance) {
_userState[from].additionalData = 0;
_timestamps[from] = 0;
} else {
//solium-disable-next-line
_timestamps[from] = uint40(block.timestamp);
}
//solium-disable-next-line
_totalSupplyTimestamp = uint40(block.timestamp);
if (balanceIncrease > amount) {
uint256 amountToMint = balanceIncrease - amount;
_mint(from, amountToMint, previousSupply);
emit Transfer(address(0), from, amountToMint);
emit Mint(
from,
from,
amountToMint,
currentBalance,
balanceIncrease,
userStableRate,
nextAvgStableRate,
nextSupply
);
} else {
uint256 amountToBurn = amount - balanceIncrease;
_burn(from, amountToBurn, previousSupply);
emit Transfer(from, address(0), amountToBurn);
emit Burn(from, amountToBurn, currentBalance, balanceIncrease, nextAvgStableRate, nextSupply);
}
return (nextSupply, nextAvgStableRate);
}
",./aave_v3/specs/StableDebtToken.spec,aave_v3,,Yes,,"Functionality: Adjust users' balances and the system's total supply based on mint and burn actions. The code calculates new user and system-wide interest rates when tokens are minted or burned, updates ownership and timestamps, and emits events to log these actions."
6cba815f971eb840c0cfa029125938b9,427 | 428 | 429 | 431 | 433,invariant,isUsingAsCollateralOrBorrowing,81,89,isUsingAsCollateralOrBorrowing | isBorrowing | isUsingAsCollateral | isUsingAsCollateralAny | isBorrowingAny,"invariant isUsingAsCollateralOrBorrowing(uint256 reserveIndex )
(isUsingAsCollateral(reserveIndex) || isBorrowing(reserveIndex)) <=> isUsingAsCollateralOrBorrowing(reserveIndex)
// // if at 1 asset is used as collateral and isUsingAsCollateralOne, then any other asset is not used as collateral
// rule integrityOfisUsingAsCollateralOne(uint256 reserveIndex, uint256 reserveIndexOther){
invariant integrityOfisUsingAsCollateralOne(uint256 reserveIndex, uint256 reserveIndexOther)
isUsingAsCollateral(reserveIndex) && isUsingAsCollateralOne() =>
!isUsingAsCollateral(reserveIndexOther) || reserveIndexOther == reserveIndex
// // if at least 1 asset is used as collateral, isUsingAsCollateralAny is true
// // ** not implmented yet - if isUsingAsCollateralAny is true then there exist at least 1 asset that is being used as collateral
// rule integrityOfisUsingAsCollateralAny(uint256 reserveIndex){
invariant integrityOfisUsingAsCollateralAny(uint256 reserveIndex)
isUsingAsCollateral(reserveIndex) => isUsingAsCollateralAny()
// // if at 1 asset is used for borrowing and isBorrowingOne, then any other asset is not used for borrowing
// rule integrityOfisBorrowingOne(uint256 reserveIndex, uint256 reserveIndexOther){
invariant integrityOfisBorrowingOne(uint256 reserveIndex, uint256 reserveIndexOther)
isBorrowing(reserveIndex) && isBorrowingOne() => !isBorrowing(reserveIndexOther) || reserveIndexOther == reserveIndex
// // if at least 1 asset is borrowed, isBorrowing is true
// // ** not implmented yet - if isBorrowingAny is true then there exist at least 1 asset that is being used for borrowing
// rule integrityOfisBorrowingAny(uint256 reserveIndex){
invariant integrityOfisBorrowingAny(uint256 reserveIndex)
isBorrowing(reserveIndex) => isBorrowingAny()
// // if user data is empty then for any index neither borrowing nor collateral is set
// rule integrityOfEmpty(uint256 reserveIndex){
invariant integrityOfEmpty(uint256 reserveIndex)
isEmpty() => !isBorrowingAny() && !isUsingAsCollateralOrBorrowing(reserveIndex)
// invariant notEmpty(uint256 reserveIndex)
// (isBorrowingAny() || isUsingAsCollateral(reserveIndex)) => !isEmpty()
// if IsolationModeState is active then there must be exactly one asset register as collateral.
// note that this is a necessary requirement, but it is not sufficient.
rule integrityOfIsolationModeState(){
// invariant integrityOfIsolationModeState(calldataarg args)
// !isUsingAsCollateralOne() => !isIsolated()
rule integrityOfSiloedBorrowingState(){
bool existExactlyOneBorrow = isBorrowingOne();
bool answer; address asset;
answer, asset = getSiloedBorrowingState();
assert answer => existExactlyOneBorrow;
}
bool existExactlyOneCollateral = isUsingAsCollateralOne();
bool answer; address asset; uint256 ceiling;
answer, asset, ceiling = getIsolationModeState();
assert answer => existExactlyOneCollateral;
// bool borrowingOrCollateral = isUsingAsCollateralOrBorrowing(reserveIndex);
// bool anyBorrowed = isBorrowingAny();
// assert isEmpty() => !borrowingOrCollateral;
// }
// bool reserveBorrowing = isBorrowing(reserveIndex);
// assert reserveBorrowing => isBorrowingAny();
// // assert exists uint256 index. isBorrowingAny() => isBorrowing(index);
// bool reserveBorrowingOther = isBorrowing(reserveIndexOther);
// assert reserveBorrowing && isBorrowingOne() => !reserveBorrowingOther || reserveIndexOther == reserveIndex;
// bool reserveCollateral = isUsingAsCollateral(reserveIndex);
// assert reserveCollateral => isUsingAsCollateralAny();
// // assert exists uint256 index. isUsingAsCollateralAny() => isUsingAsCollateral(index);
// bool reserveCollateralOther = isUsingAsCollateral(reserveIndexOther);
// assert reserveCollateral && isUsingAsCollateralOne() => !reserveCollateralOther || reserveIndexOther == reserveIndex;
","isUsingAsCollateralOrBorrowing (Lines 71-79), | isBorrowing (Lines 87-95), | isUsingAsCollateral (Lines 103-111), | isUsingAsCollateralAny (Lines 131-135), | isBorrowingAny (Lines 153-155), "," function isUsingAsCollateralOrBorrowing(
DataTypes.UserConfigurationMap memory self,
uint256 reserveIndex
) internal pure returns (bool) {
unchecked {
require(reserveIndex < ReserveConfiguration.MAX_RESERVES_COUNT, Errors.INVALID_RESERVE_INDEX);
return (self.data >> (reserveIndex << 1)) & 3 != 0;
}
}
| function isBorrowing(
DataTypes.UserConfigurationMap memory self,
uint256 reserveIndex
) internal pure returns (bool) {
unchecked {
require(reserveIndex < ReserveConfiguration.MAX_RESERVES_COUNT, Errors.INVALID_RESERVE_INDEX);
return (self.data >> (reserveIndex << 1)) & 1 != 0;
}
}
| function isUsingAsCollateral(
DataTypes.UserConfigurationMap memory self,
uint256 reserveIndex
) internal pure returns (bool) {
unchecked {
require(reserveIndex < ReserveConfiguration.MAX_RESERVES_COUNT, Errors.INVALID_RESERVE_INDEX);
return (self.data >> ((reserveIndex << 1) + 1)) & 1 != 0;
}
}
| function isUsingAsCollateralAny(
DataTypes.UserConfigurationMap memory self
) internal pure returns (bool) {
return self.data & COLLATERAL_MASK != 0;
}
| function isBorrowingAny(DataTypes.UserConfigurationMap memory self) internal pure returns (bool) {
return self.data & BORROWING_MASK != 0;
}
",./aave_v3/specs/UserConfiguration.spec,aave_v3,,Yes,,"Functionality: Determine user interactions with reserves by verifying if they are using assets as collateral, borrowing, or engaging in either activity for any reserve. It manipulates bits within a user configuration map to check user status per reserve, utilizing bitwise operations for efficiency."
|