From e0be3f5166071c27419de2e35e9197b89a665095 Mon Sep 17 00:00:00 2001
From: t4sk Example of upgradeable proxy contract. Never use this in production. Example of upgradeable proxy contract. Never use this in production. This example shows
delegatecall
and return data when fallback
is called.
Example of how to declare variables inside assembly
Example of how to declare variables inside assembly
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
@@ -3756,7 +3756,7 @@ Each slot in the array can store 32 bytes.
}
}
}
-
`,Oy=({prev:s,next:a})=>r.jsx(A,{version:Ey,title:Qy,description:Ty,cyfrinLink:Uy,html:_y,prev:s,next:a,codes:Ly}),Py="0.8.26",$y="Bitwise Operators",qy="Learn about bitwise operators in Solidity",sm="https://www.cyfrin.io/glossary/bitwise-operators-solidity-code-example",am=[{fileName:"Bitwise.sol",code:"Ly8gU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IE1JVApwcmFnbWEgc29saWRpdHkgXjAuOC4yNjsKCmNvbnRyYWN0IEJpdHdpc2VPcHMgewogICAgLy8geCAgICAgPSAxMTEwID0gOCArIDQgKyAyICsgMCA9IDE0CiAgICAvLyB5ICAgICA9IDEwMTEgPSA4ICsgMCArIDIgKyAxID0gMTEKICAgIC8vIHggJiB5ID0gMTAxMCA9IDggKyAwICsgMiArIDAgPSAxMAogICAgZnVuY3Rpb24gYW5kKHVpbnQyNTYgeCwgdWludDI1NiB5KSBleHRlcm5hbCBwdXJlIHJldHVybnMgKHVpbnQyNTYpIHsKICAgICAgICByZXR1cm4geCAmIHk7CiAgICB9CgogICAgLy8geCAgICAgPSAxMTAwID0gOCArIDQgKyAwICsgMCA9IDEyCiAgICAvLyB5ICAgICA9IDEwMDEgPSA4ICsgMCArIDAgKyAxID0gOQogICAgLy8geCB8IHkgPSAxMTAxID0gOCArIDQgKyAwICsgMSA9IDEzCiAgICBmdW5jdGlvbiBvcih1aW50MjU2IHgsIHVpbnQyNTYgeSkgZXh0ZXJuYWwgcHVyZSByZXR1cm5zICh1aW50MjU2KSB7CiAgICAgICAgcmV0dXJuIHggfCB5OwogICAgfQoKICAgIC8vIHggICAgID0gMTEwMCA9IDggKyA0ICsgMCArIDAgPSAxMgogICAgLy8geSAgICAgPSAwMTAxID0gMCArIDQgKyAwICsgMSA9IDUKICAgIC8vIHggXiB5ID0gMTAwMSA9IDggKyAwICsgMCArIDEgPSA5CiAgICBmdW5jdGlvbiB4b3IodWludDI1NiB4LCB1aW50MjU2IHkpIGV4dGVybmFsIHB1cmUgcmV0dXJucyAodWludDI1NikgewogICAgICAgIHJldHVybiB4IF4geTsKICAgIH0KCiAgICAvLyB4ICA9IDAwMDAxMTAwID0gICAwICsgIDAgKyAgMCArICAwICsgOCArIDQgKyAwICsgMCA9IDEyCiAgICAvLyB+eCA9IDExMTEwMDExID0gMTI4ICsgNjQgKyAzMiArIDE2ICsgMCArIDAgKyAyICsgMSA9IDI0MwogICAgZnVuY3Rpb24gbm90KHVpbnQ4IHgpIGV4dGVybmFsIHB1cmUgcmV0dXJucyAodWludDgpIHsKICAgICAgICByZXR1cm4gfng7CiAgICB9CgogICAgLy8gMSA8PCAwID0gMDAwMSAtLT4gMDAwMSA9IDEKICAgIC8vIDEgPDwgMSA9IDAwMDEgLS0+IDAwMTAgPSAyCiAgICAvLyAxIDw8IDIgPSAwMDAxIC0tPiAwMTAwID0gNAogICAgLy8gMSA8PCAzID0gMDAwMSAtLT4gMTAwMCA9IDgKICAgIC8vIDMgPDwgMiA9IDAwMTEgLS0+IDExMDAgPSAxMgogICAgZnVuY3Rpb24gc2hpZnRMZWZ0KHVpbnQyNTYgeCwgdWludDI1NiBiaXRzKQogICAgICAgIGV4dGVybmFsCiAgICAgICAgcHVyZQogICAgICAgIHJldHVybnMgKHVpbnQyNTYpCiAgICB7CiAgICAgICAgcmV0dXJuIHggPDwgYml0czsKICAgIH0KCiAgICAvLyA4ICA+PiAwID0gMTAwMCAtLT4gMTAwMCA9IDgKICAgIC8vIDggID4+IDEgPSAxMDAwIC0tPiAwMTAwID0gNAogICAgLy8gOCAgPj4gMiA9IDEwMDAgLS0+IDAwMTAgPSAyCiAgICAvLyA4ICA+PiAzID0gMTAwMCAtLT4gMDAwMSA9IDEKICAgIC8vIDggID4+IDQgPSAxMDAwIC0tPiAwMDAwID0gMAogICAgLy8gMTIgPj4gMSA9IDExMDAgLS0+IDAxMTAgPSA2CiAgICBmdW5jdGlvbiBzaGlmdFJpZ2h0KHVpbnQyNTYgeCwgdWludDI1NiBiaXRzKQogICAgICAgIGV4dGVybmFsCiAgICAgICAgcHVyZQogICAgICAgIHJldHVybnMgKHVpbnQyNTYpCiAgICB7CiAgICAgICAgcmV0dXJuIHggPj4gYml0czsKICAgIH0KCiAgICAvLyBHZXQgbGFzdCBuIGJpdHMgZnJvbSB4CiAgICBmdW5jdGlvbiBnZXRMYXN0TkJpdHModWludDI1NiB4LCB1aW50MjU2IG4pCiAgICAgICAgZXh0ZXJuYWwKICAgICAgICBwdXJlCiAgICAgICAgcmV0dXJucyAodWludDI1NikKICAgIHsKICAgICAgICAvLyBFeGFtcGxlLCBsYXN0IDMgYml0cwogICAgICAgIC8vIHggICAgICAgID0gMTEwMSA9IDEzCiAgICAgICAgLy8gbWFzayAgICAgPSAwMTExID0gNwogICAgICAgIC8vIHggJiBtYXNrID0gMDEwMSA9IDUKICAgICAgICB1aW50MjU2IG1hc2sgPSAoMSA8PCBuKSAtIDE7CiAgICAgICAgcmV0dXJuIHggJiBtYXNrOwogICAgfQoKICAgIC8vIEdldCBsYXN0IG4gYml0cyBmcm9tIHggdXNpbmcgbW9kIG9wZXJhdG9yCiAgICBmdW5jdGlvbiBnZXRMYXN0TkJpdHNVc2luZ01vZCh1aW50MjU2IHgsIHVpbnQyNTYgbikKICAgICAgICBleHRlcm5hbAogICAgICAgIHB1cmUKICAgICAgICByZXR1cm5zICh1aW50MjU2KQogICAgewogICAgICAgIC8vIDEgPDwgbiA9IDIgKiogbgogICAgICAgIHJldHVybiB4ICUgKDEgPDwgbik7CiAgICB9CgogICAgLy8gR2V0IHBvc2l0aW9uIG9mIG1vc3Qgc2lnbmlmaWNhbnQgYml0CiAgICAvLyB4ID0gMTEwMCA9IDEyLCBtb3N0IHNpZ25pZmljYW50IGJpdCA9IDEwMDAsIHNvIHRoaXMgZnVuY3Rpb24gd2lsbCByZXR1cm4gMwogICAgZnVuY3Rpb24gbW9zdFNpZ25pZmljYW50Qml0KHVpbnQyNTYgeCkgZXh0ZXJuYWwgcHVyZSByZXR1cm5zICh1aW50MjU2KSB7CiAgICAgICAgdWludDI1NiBpID0gMDsKICAgICAgICB3aGlsZSAoKHggPj49IDEpID4gMCkgewogICAgICAgICAgICArK2k7CiAgICAgICAgfQogICAgICAgIHJldHVybiBpOwogICAgfQoKICAgIC8vIEdldCBmaXJzdCBuIGJpdHMgZnJvbSB4CiAgICAvLyBsZW4gPSBsZW5ndGggb2YgYml0cyBpbiB4ID0gcG9zaXRpb24gb2YgbW9zdCBzaWduaWZpY2FudCBiaXQgb2YgeCwgKyAxCiAgICBmdW5jdGlvbiBnZXRGaXJzdE5CaXRzKHVpbnQyNTYgeCwgdWludDI1NiBuLCB1aW50MjU2IGxlbikKICAgICAgICBleHRlcm5hbAogICAgICAgIHB1cmUKICAgICAgICByZXR1cm5zICh1aW50MjU2KQogICAgewogICAgICAgIC8vIEV4YW1wbGUKICAgICAgICAvLyB4ICAgICAgICA9IDExMTAgPSAxNCwgbiA9IDIsIGxlbiA9IDQKICAgICAgICAvLyBtYXNrICAgICA9IDExMDAgPSAxMgogICAgICAgIC8vIHggJiBtYXNrID0gMTEwMCA9IDEyCiAgICAgICAgdWludDI1NiBtYXNrID0gKCgxIDw8IG4pIC0gMSkgPDwgKGxlbiAtIG4pOwogICAgICAgIHJldHVybiB4ICYgbWFzazsKICAgIH0KfQo="},{fileName:"MostSignificantBitAssembly.sol",code:"Ly8gU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IE1JVApwcmFnbWEgc29saWRpdHkgXjAuOC4yNjsKCmNvbnRyYWN0IE1vc3RTaWduaWZpY2FudEJpdEFzc2VtYmx5IHsKICAgIGZ1bmN0aW9uIG1vc3RTaWduaWZpY2FudEJpdCh1aW50MjU2IHgpCiAgICAgICAgZXh0ZXJuYWwKICAgICAgICBwdXJlCiAgICAgICAgcmV0dXJucyAodWludDI1NiBtc2IpCiAgICB7CiAgICAgICAgYXNzZW1ibHkgewogICAgICAgICAgICBsZXQgZiA6PSBzaGwoNywgZ3QoeCwgMHhGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRikpCiAgICAgICAgICAgIHggOj0gc2hyKGYsIHgpCiAgICAgICAgICAgIC8vIG9yIGNhbiBiZSByZXBsYWNlZCB3aXRoIGFkZAogICAgICAgICAgICBtc2IgOj0gb3IobXNiLCBmKQogICAgICAgIH0KICAgICAgICBhc3NlbWJseSB7CiAgICAgICAgICAgIGxldCBmIDo9IHNobCg2LCBndCh4LCAweEZGRkZGRkZGRkZGRkZGRkYpKQogICAgICAgICAgICB4IDo9IHNocihmLCB4KQogICAgICAgICAgICBtc2IgOj0gb3IobXNiLCBmKQogICAgICAgIH0KICAgICAgICBhc3NlbWJseSB7CiAgICAgICAgICAgIGxldCBmIDo9IHNobCg1LCBndCh4LCAweEZGRkZGRkZGKSkKICAgICAgICAgICAgeCA6PSBzaHIoZiwgeCkKICAgICAgICAgICAgbXNiIDo9IG9yKG1zYiwgZikKICAgICAgICB9CiAgICAgICAgYXNzZW1ibHkgewogICAgICAgICAgICBsZXQgZiA6PSBzaGwoNCwgZ3QoeCwgMHhGRkZGKSkKICAgICAgICAgICAgeCA6PSBzaHIoZiwgeCkKICAgICAgICAgICAgbXNiIDo9IG9yKG1zYiwgZikKICAgICAgICB9CiAgICAgICAgYXNzZW1ibHkgewogICAgICAgICAgICBsZXQgZiA6PSBzaGwoMywgZ3QoeCwgMHhGRikpCiAgICAgICAgICAgIHggOj0gc2hyKGYsIHgpCiAgICAgICAgICAgIG1zYiA6PSBvcihtc2IsIGYpCiAgICAgICAgfQogICAgICAgIGFzc2VtYmx5IHsKICAgICAgICAgICAgbGV0IGYgOj0gc2hsKDIsIGd0KHgsIDB4RikpCiAgICAgICAgICAgIHggOj0gc2hyKGYsIHgpCiAgICAgICAgICAgIG1zYiA6PSBvcihtc2IsIGYpCiAgICAgICAgfQogICAgICAgIGFzc2VtYmx5IHsKICAgICAgICAgICAgbGV0IGYgOj0gc2hsKDEsIGd0KHgsIDB4MykpCiAgICAgICAgICAgIHggOj0gc2hyKGYsIHgpCiAgICAgICAgICAgIG1zYiA6PSBvcihtc2IsIGYpCiAgICAgICAgfQogICAgICAgIGFzc2VtYmx5IHsKICAgICAgICAgICAgbGV0IGYgOj0gZ3QoeCwgMHgxKQogICAgICAgICAgICBtc2IgOj0gb3IobXNiLCBmKQogICAgICAgIH0KICAgIH0KfQo="},{fileName:"MostSignificantBitFunction.sol",code:"Ly8gU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IE1JVApwcmFnbWEgc29saWRpdHkgXjAuOC4yNjsKCmNvbnRyYWN0IE1vc3RTaWduaWZpY2FudEJpdEZ1bmN0aW9uIHsKICAgIC8vIEZpbmQgbW9zdCBzaWduaWZpY2FudCBiaXQgdXNpbmcgYmluYXJ5IHNlYXJjaAogICAgZnVuY3Rpb24gbW9zdFNpZ25pZmljYW50Qml0KHVpbnQyNTYgeCkKICAgICAgICBleHRlcm5hbAogICAgICAgIHB1cmUKICAgICAgICByZXR1cm5zICh1aW50MjU2IG1zYikKICAgIHsKICAgICAgICAvLyB4ID49IDIgKiogMTI4CiAgICAgICAgaWYgKHggPj0gMHgxMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDApIHsKICAgICAgICAgICAgeCA+Pj0gMTI4OwogICAgICAgICAgICBtc2IgKz0gMTI4OwogICAgICAgIH0KICAgICAgICAvLyB4ID49IDIgKiogNjQKICAgICAgICBpZiAoeCA+PSAweDEwMDAwMDAwMDAwMDAwMDAwKSB7CiAgICAgICAgICAgIHggPj49IDY0OwogICAgICAgICAgICBtc2IgKz0gNjQ7CiAgICAgICAgfQogICAgICAgIC8vIHggPj0gMiAqKiAzMgogICAgICAgIGlmICh4ID49IDB4MTAwMDAwMDAwKSB7CiAgICAgICAgICAgIHggPj49IDMyOwogICAgICAgICAgICBtc2IgKz0gMzI7CiAgICAgICAgfQogICAgICAgIC8vIHggPj0gMiAqKiAxNgogICAgICAgIGlmICh4ID49IDB4MTAwMDApIHsKICAgICAgICAgICAgeCA+Pj0gMTY7CiAgICAgICAgICAgIG1zYiArPSAxNjsKICAgICAgICB9CiAgICAgICAgLy8geCA+PSAyICoqIDgKICAgICAgICBpZiAoeCA+PSAweDEwMCkgewogICAgICAgICAgICB4ID4+PSA4OwogICAgICAgICAgICBtc2IgKz0gODsKICAgICAgICB9CiAgICAgICAgLy8geCA+PSAyICoqIDQKICAgICAgICBpZiAoeCA+PSAweDEwKSB7CiAgICAgICAgICAgIHggPj49IDQ7CiAgICAgICAgICAgIG1zYiArPSA0OwogICAgICAgIH0KICAgICAgICAvLyB4ID49IDIgKiogMgogICAgICAgIGlmICh4ID49IDB4NCkgewogICAgICAgICAgICB4ID4+PSAyOwogICAgICAgICAgICBtc2IgKz0gMjsKICAgICAgICB9CiAgICAgICAgLy8geCA+PSAyICoqIDEKICAgICAgICBpZiAoeCA+PSAweDIpIG1zYiArPSAxOwogICAgfQp9Cg=="}],nm=`// SPDX-License-Identifier: MIT
+
`,Oy=({prev:s,next:a})=>r.jsx(A,{version:Ey,title:Qy,description:Ty,cyfrinLink:Ly,html:_y,prev:s,next:a,codes:Uy}),Py="0.8.26",$y="Bitwise Operators",qy="Learn about bitwise operators in Solidity",sm="https://www.cyfrin.io/glossary/bitwise-operators-solidity-code-example",am=[{fileName:"Bitwise.sol",code:"Ly8gU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IE1JVApwcmFnbWEgc29saWRpdHkgXjAuOC4yNjsKCmNvbnRyYWN0IEJpdHdpc2VPcHMgewogICAgLy8geCAgICAgPSAxMTEwID0gOCArIDQgKyAyICsgMCA9IDE0CiAgICAvLyB5ICAgICA9IDEwMTEgPSA4ICsgMCArIDIgKyAxID0gMTEKICAgIC8vIHggJiB5ID0gMTAxMCA9IDggKyAwICsgMiArIDAgPSAxMAogICAgZnVuY3Rpb24gYW5kKHVpbnQyNTYgeCwgdWludDI1NiB5KSBleHRlcm5hbCBwdXJlIHJldHVybnMgKHVpbnQyNTYpIHsKICAgICAgICByZXR1cm4geCAmIHk7CiAgICB9CgogICAgLy8geCAgICAgPSAxMTAwID0gOCArIDQgKyAwICsgMCA9IDEyCiAgICAvLyB5ICAgICA9IDEwMDEgPSA4ICsgMCArIDAgKyAxID0gOQogICAgLy8geCB8IHkgPSAxMTAxID0gOCArIDQgKyAwICsgMSA9IDEzCiAgICBmdW5jdGlvbiBvcih1aW50MjU2IHgsIHVpbnQyNTYgeSkgZXh0ZXJuYWwgcHVyZSByZXR1cm5zICh1aW50MjU2KSB7CiAgICAgICAgcmV0dXJuIHggfCB5OwogICAgfQoKICAgIC8vIHggICAgID0gMTEwMCA9IDggKyA0ICsgMCArIDAgPSAxMgogICAgLy8geSAgICAgPSAwMTAxID0gMCArIDQgKyAwICsgMSA9IDUKICAgIC8vIHggXiB5ID0gMTAwMSA9IDggKyAwICsgMCArIDEgPSA5CiAgICBmdW5jdGlvbiB4b3IodWludDI1NiB4LCB1aW50MjU2IHkpIGV4dGVybmFsIHB1cmUgcmV0dXJucyAodWludDI1NikgewogICAgICAgIHJldHVybiB4IF4geTsKICAgIH0KCiAgICAvLyB4ICA9IDAwMDAxMTAwID0gICAwICsgIDAgKyAgMCArICAwICsgOCArIDQgKyAwICsgMCA9IDEyCiAgICAvLyB+eCA9IDExMTEwMDExID0gMTI4ICsgNjQgKyAzMiArIDE2ICsgMCArIDAgKyAyICsgMSA9IDI0MwogICAgZnVuY3Rpb24gbm90KHVpbnQ4IHgpIGV4dGVybmFsIHB1cmUgcmV0dXJucyAodWludDgpIHsKICAgICAgICByZXR1cm4gfng7CiAgICB9CgogICAgLy8gMSA8PCA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IHggICAgICAgID0gMTEwMSA9IDEzCiAgICAgICAgLy8gbWFzayAgICAgPSAwMTExID0gNwogICAgICAgIC8vIHggJiBtYXNrID0gMDEwMSA9IDUKICAgICAgICB1aW50MjU2IG1hc2sgPSAoMSA8PCBuKSAtIDE7CiAgICAgICAgcmV0dXJuIHggJiBtYXNrOwogICAgfQoKICAgIC8vIEdldCBsYXN0IG4gYml0cyBmcm9tIHggdXNpbmcgbW9kIG9wZXJhdG9yCiAgICBmdW5jdGlvbiBnZXRMYXN0TkJpdHNVc2luZ01vZCh1aW50MjU2IHgsIHVpbnQyNTYgbikKICAgICAgICBleHRlcm5hbAogICAgICAgIHB1cmUKICAgICAgICByZXR1cm5zICh1aW50MjU2KQogICAgewogICAgICAgIC8vIDEgPDwgbiA9IDIgKiogbgogICAgICAgIHJldHVybiB4ICUgKDEgPDwgbik7CiAgICB9CgogICAgLy8gR2V0IHBvc2l0aW9uIG9mIG1vc3Qgc2lnbmlmaWNhbnQgYml0CiAgICAvLyB4ID0gMTEwMCA9IDEyLCBtb3N0IHNpZ25pZmljYW50IGJpdCA9IDEwMDAsIHNvIHRoaXMgZnVuY3Rpb24gd2lsbCByZXR1cm4gMwogICAgZnVuY3Rpb24gbW9zdFNpZ25pZmljYW50Qml0KHVpbnQyNTYgeCkgZXh0ZXJuYWwgcHVyZSByZXR1cm5zICh1aW50MjU2KSB7CiAgICAgICAgdWludDI1NiBpID0gMDsKICAgICAgICB3aGlsZSAoKHggPj49IDEpID4gMCkgewogICAgICAgICAgICArK2k7CiAgICAgICAgfQogICAgICAgIHJldHVybiBpOwogICAgfQoKICAgIC8vIEdldCBmaXJzdCBuIGJpdHMgZnJvbSB4CiAgICAvLyBsZW4gPSBsZW5ndGggb2YgYml0cyBpbiB4ID0gcG9zaXRpb24gb2YgbW9zdCBzaWduaWZpY2FudCBiaXQgb2YgeCwgKyAxCiAgICBmdW5jdGlvbiBnZXRGaXJzdE5CaXRzKHVpbnQyNTYgeCwgdWludDI1NiBuLCB1aW50MjU2IGxlbikKICAgICAgICBleHRlcm5hbAogICAgICAgIHB1cmUKICAgICAgICByZXR1cm5zICh1aW50MjU2KQogICAgewogICAgICAgIC8vIEV4YW1wbGUKICAgICAgICAvLyB4ICAgICAgICA9IDExMTAgPSAxNCwgbiA9IDIsIGxlbiA9IDQKICAgICAgICAvLyBtYXNrICAgICA9IDExMDAgPSAxMgogICAgICAgIC8vIHggJiBtYXNrID0gMTEwMCA9IDEyCiAgICAgICAgdWludDI1NiBtYXNrID0gKCgxIDw8IG4pIC0gMSkgPDwgKGxlbiAtIG4pOwogICAgICAgIHJldHVybiB4ICYgbWFzazsKICAgIH0KfQo="},{fileName:"MostSignificantBitAssembly.sol",code:"Ly8gU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IE1JVApwcmFnbWEgc29saWRpdHkgXjAuOC4yNjsKCmNvbnRyYWN0IE1vc3RTaWduaWZpY2FudEJpdEFzc2VtYmx5IHsKICAgIGZ1bmN0aW9uIG1vc3RTaWduaWZpY2FudEJpdCh1aW50MjU2IHgpCiAgICAgICAgZXh0ZXJuYWwKICAgICAgICBwdXJlCiAgICAgICAgcmV0dXJucyAodWludDI1NiBtc2IpCiAgICB7CiAgICAgICAgYXNzZW1ibHkgewogICAgICAgICAgICBsZXQgZiA6PSBzaGwoNywgZ3QoeCwgMHhGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRkZGRikpCiAgICAgICAgICAgIHggOj0gc2hyKGYsIHgpCiAgICAgICAgICAgIC8vIG9yIGNhbiBiZSByZXBsYWNlZCB3aXRoIGFkZAogICAgICAgICAgICBtc2IgOj0gb3IobXNiLCBmKQogICAgICAgIH0KICAgICAgICBhc3NlbWJseSB7CiAgICAgICAgICAgIGxldCBmIDo9IHNobCg2LCBndCh4LCAweEZGRkZGRkZGRkZGRkZGRkYpKQogICAgICAgICAgICB4IDo9IHNocihmLCB4KQogICAgICAgICAgICBtc2IgOj0gb3IobXNiLCBmKQogICAgICAgIH0KICAgICAgICBhc3NlbWJseSB7CiAgICAgICAgICAgIGxldCBmIDo9IHNobCg1LCBndCh4LCAweEZGRkZGRkZGKSkKICAgICAgICAgICAgeCA6PSBzaHIoZiwgeCkKICAgICAgICAgICAgbXNiIDo9IG9yKG1zYiwgZikKICAgICAgICB9CiAgICAgICAgYXNzZW1ibHkgewogICAgICAgICAgICBsZXQgZiA6PSBzaGwoNCwgZ3QoeCwgMHhGRkZGKSkKICAgICAgICAgICAgeCA6PSBzaHIoZiwgeCkKICAgICAgICAgICAgbXNiIDo9IG9yKG1zYiwgZikKICAgICAgICB9CiAgICAgICAgYXNzZW1ibHkgewogICAgICAgICAgICBsZXQgZiA6PSBzaGwoMywgZ3QoeCwgMHhGRikpCiAgICAgICAgICAgIHggOj0gc2hyKGYsIHgpCiAgICAgICAgICAgIG1zYiA6PSBvcihtc2IsIGYpCiAgICAgICAgfQogICAgICAgIGFzc2VtYmx5IHsKICAgICAgICAgICAgbGV0IGYgOj0gc2hsKDIsIGd0KHgsIDB4RikpCiAgICAgICAgICAgIHggOj0gc2hyKGYsIHgpCiAgICAgICAgICAgIG1zYiA6PSBvcihtc2IsIGYpCiAgICAgICAgfQogICAgICAgIGFzc2VtYmx5IHsKICAgICAgICAgICAgbGV0IGYgOj0gc2hsKDEsIGd0KHgsIDB4MykpCiAgICAgICAgICAgIHggOj0gc2hyKGYsIHgpCiAgICAgICAgICAgIG1zYiA6PSBvcihtc2IsIGYpCiAgICAgICAgfQogICAgICAgIGFzc2VtYmx5IHsKICAgICAgICAgICAgbGV0IGYgOj0gZ3QoeCwgMHgxKQogICAgICAgICAgICBtc2IgOj0gb3IobXNiLCBmKQogICAgICAgIH0KICAgIH0KfQo="},{fileName:"MostSignificantBitFunction.sol",code:"Ly8gU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IE1JVApwcmFnbWEgc29saWRpdHkgXjAuOC4yNjsKCmNvbnRyYWN0IE1vc3RTaWduaWZpY2FudEJpdEZ1bmN0aW9uIHsKICAgIC8vIEZpbmQgbW9zdCBzaWduaWZpY2FudCBiaXQgdXNpbmcgYmluYXJ5IHNlYXJjaAogICAgZnVuY3Rpb24gbW9zdFNpZ25pZmljYW50Qml0KHVpbnQyNTYgeCkKICAgICAgICBleHRlcm5hbAogICAgICAgIHB1cmUKICAgICAgICByZXR1cm5zICh1aW50MjU2IG1zYikKICAgIHsKICAgICAgICAvLyB4ID49IDIgKiogMTI4CiAgICAgICAgaWYgKHggPj0gMHgxMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDApIHsKICAgICAgICAgICAgeCA+Pj0gMTI4OwogICAgICAgICAgICBtc2IgKz0gMTI4OwogICAgICAgIH0KICAgICAgICAvLyB4ID49IDIgKiogNjQKICAgICAgICBpZiAoeCA+PSAweDEwMDAwMDAwMDAwMDAwMDAwKSB7CiAgICAgICAgICAgIHggPj49IDY0OwogICAgICAgICAgICBtc2IgKz0gNjQ7CiAgICAgICAgfQogICAgICAgIC8vIHggPj0gMiAqKiAzMgogICAgICAgIGlmICh4ID49IDB4MTAwMDAwMDAwKSB7CiAgICAgICAgICAgIHggPj49IDMyOwogICAgICAgICAgICBtc2IgKz0gMzI7CiAgICAgICAgfQogICAgICAgIC8vIHggPj0gMiAqKiAxNgogICAgICAgIGlmICh4ID49IDB4MTAwMDApIHsKICAgICAgICAgICAgeCA+Pj0gMTY7CiAgICAgICAgICAgIG1zYiArPSAxNjsKICAgICAgICB9CiAgICAgICAgLy8geCA+PSAyICoqIDgKICAgICAgICBpZiAoeCA+PSAweDEwMCkgewogICAgICAgICAgICB4ID4+PSA4OwogICAgICAgICAgICBtc2IgKz0gODsKICAgICAgICB9CiAgICAgICAgLy8geCA+PSAyICoqIDQKICAgICAgICBpZiAoeCA+PSAweDEwKSB7CiAgICAgICAgICAgIHggPj49IDQ7CiAgICAgICAgICAgIG1zYiArPSA0OwogICAgICAgIH0KICAgICAgICAvLyB4ID49IDIgKiogMgogICAgICAgIGlmICh4ID49IDB4NCkgewogICAgICAgICAgICB4ID4+PSAyOwogICAgICAgICAgICBtc2IgKz0gMjsKICAgICAgICB9CiAgICAgICAgLy8geCA+PSAyICoqIDEKICAgICAgICBpZiAoeCA+PSAweDIpIG1zYiArPSAxOwogICAgfQp9Cg=="}],nm=`// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
contract BitwiseOps {
@@ -4211,7 +4211,7 @@ specify the location of the data.
uint80 answeredInRound
);
}
-
`,Qm=({prev:s,next:a})=>r.jsx(A,{version:Sm,title:xm,description:Jm,cyfrinLink:zm,html:Em,prev:s,next:a,codes:Dm}),Tm="0.8.26",Um="Constant Product AMM",Lm="Constant product AMM",_m="",Om=[{fileName:"CPAMM.sol",code:"Ly8gU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IE1JVApwcmFnbWEgc29saWRpdHkgXjAuOC4yNjsKCmNvbnRyYWN0IENQQU1NIHsKICAgIElFUkMyMCBwdWJsaWMgaW1tdXRhYmxlIHRva2VuMDsKICAgIElFUkMyMCBwdWJsaWMgaW1tdXRhYmxlIHRva2VuMTsKCiAgICB1aW50MjU2IHB1YmxpYyByZXNlcnZlMDsKICAgIHVpbnQyNTYgcHVibGljIHJlc2VydmUxOwoKICAgIHVpbnQyNTYgcHVibGljIHRvdGFsU3VwcGx5OwogICAgbWFwcGluZyhhZGRyZXNzID0+IHVpbnQyNTYpIHB1YmxpYyBiYWxhbmNlT2Y7CgogICAgY29uc3RydWN0b3IoYWRkcmVzcyBfdG9rZW4wLCBhZGRyZXNzIF90b2tlbjEpIHsKICAgICAgICB0b2tlbjAgPSBJRVJDMjAoX3Rva2VuMCk7CiAgICAgICAgdG9rZW4xID0gSUVSQzIwKF90b2tlbjEpOwogICAgfQoKICAgIGZ1bmN0aW9uIF9taW50KGFkZHJlc3MgX3RvLCB1aW50MjU2IF9hbW91bnQpIHByaXZhdGUgewogICAgICAgIGJhbGFuY2VPZltfdG9dICs9IF9hbW91bnQ7CiAgICAgICAgdG90YWxTdXBwbHkgK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CiAgICAgICAgdG9rZW5Jbi50cmFuc2ZlckZyb20obXNnLnNlbmRlciwgYWRkcmVzcyh0aGlzKSwgX2Ftb3VudEluKTsKCiAgICAgICAgLyoKICAgICAgICBIb3cgbXVjaCBkeSBmb3IgZHg/CgogICAgICAgIHh5ID0gawogICAgICAgICh4ICsgZHgpKHkgLSBkeSkgPSBrCiAgICAgICAgeSAtIGR5ID0gayAvICh4ICsgZHgpCiAgICAgICAgeSAtIGsgLyAoeCArIGR4KSA9IGR5CiAgICAgICAgeSAtIHh5IC8gKHggKyBkeCkgPSBkeQogICAgICAgICh5eCArIHlkeCAtIHh5KSAvICh4ICsgZHgpID0gZHkKICAgICAgICB5ZHggLyAoeCArIGR4KSA9IGR5CiAgICAgICAgKi8KICAgICAgICAvLyAwLjMlIGZlZQogICAgICAgIHVpbnQyNTYgYW1vdW50SW5XaXRoRmVlID0gKF9hbW91bnRJbiAqIDk5NykgLyAxMDAwOwogICAgICAgIGFtb3VudE91dCA9CiAgICAgICAgICAgIChyZXNlcnZlT3V0ICogYW1vdW50SW5XaXRoRmVlKSAvIChyZXNlcnZlSW4gKyBhbW91bnRJbldpdGhGZWUpOwoKICAgICAgICB0b2tlbk91dC50cmFuc2Zlcihtc2cuc2VuZGVyLCBhbW91bnRPdXQpOwoKICAgICAgICBfdXBkYXRlKAogICAgICAgICAgICB0b2tlbjAuYmFsYW5jZU9mKGFkZHJlc3ModGhpcykpLCB0b2tlbjEuYmFsYW5jZU9mKGFkZHJlc3ModGhpcykpCiAgICAgICAgKTsKICAgIH0KCiAgICBmdW5jdGlvbiBhZGRMaXF1aWRpdHkodWludDI1NiBfYW1vdW50MCwgdWludDI1NiBfYW1vdW50MSkKICAgICAgICBleHRlcm5hbAogICAgICAgIHJldHVybnMgKHVpbnQyNTYgc2hhcmVzKQogICAgewogICAgICAgIHRva2VuMC50cmFuc2ZlckZyb20obXNnLnNlbmRlciwgYWRkcmVzcyh0aGlzKSwgX2Ftb3VudDApOwogICAgICAgIHR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gc3FydCh4XjIpICAKICAgICAgICA9ICgoeCArIGR4KSAtIHgpIC8geAogICAgICAgID0gZHggLyB4CgogICAgICAgIFNpbmNlIGR4IC8gZHkgPSB4IC8geSwKICAgICAgICBkeCAvIHggPSBkeSAvIHkKCiAgICAgICAgRmluYWxseQogICAgICAgIChMMSAtIEwwKSAvIEwwID0gZHggLyB4ID0gZHkgLyB5CiAgICAgICAgKi8KICAgICAgICBpZiAodG90YWxTdXBwbHkgPT0gMCkgewogICAgICAgICAgICBzaGFyZXMgPSBfc3FydChfYW1vdW50MCAqIF9hbW91bnQxKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzaGFyZXMgPSBfbWluKAogICAgICAgICAgICAgICAgKF9hbW91bnQwICogdG90YWxTdXBwbHkpIC8gcmVzZXJ2ZTAsCiAgICAgICAgICAgICAgICAoX2Ftb3VudDEgKiB0b3RhbFN1cHBseSkgLyByZXNlcnZlMQogICAgICAgICAgICApOwogICAgICAgIH0KICAgICAgICByZXF1aXJlKHNoYXJlcyA+IDAsICJzaGFyZXMgPSAwIik7CiAgICAgICAgX21pbnQobXNnLnNlbmRlciwgc2hhcmVzKTsKCiAgICAgICAgX3VwZGF0ZSgKICAgICAgICAgICAgdG9rZW4wLmJhbGFuY2VPZihhZGRyZXNzKHRoaXMpKSwgdG9rZW4xLmJhbGFuY2VPZihhZGRyZXNzKHRoaXMpKQogICAgICAgICk7CiAgICB9CgogICAgZnVuY3Rpb24gcmVtb3ZlTGlxdWlkaXR5KHVpbnQyNTYgX3NoYXJlcykKICAgICAgICBleHRlcm5hbAogICAgICAgIHJldHVybnMgKHVpbnQyNTYgYW1vdW50MCwgdWludDI1NiBhbW91bnQxKQogICAgewogICAgICAgIC8qCiAgICAgICAgQ2xhaW0KICAgICAgICBkeCwgZHkgPSBhbW91bnQgb2YgbGlxdWlkaXR5IHRvIHJlbW92ZQogICAgICAgIGR4ID0gcyAvIFQgKiB4CiAgICAgICAgZHkgPSBzIC8gVCAqIHkKCi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RoaXMpKTsKCiAgICAgICAgYW1vdW50MCA9IChfc2hhcmVzICogYmFsMCkgLyB0b3RhbFN1cHBseTsKICAgICAgICBhbW91bnQxID0gKF9zaGFyZXMgKiBiYWwxKSAvIHRvdGFsU3VwcGx5OwogICAgICAgIHJlcXVpcmUoYW1vdW50MCA+IDAgJiYgYW1vdW50MSA+IDAsICJhbW91bnQwIG9yIGFtb3VudDEgPSAwIik7CgogICAgICAgIF9idXJuKG1zZy5zZW5kZXIsIF9zaGFyZXMpOwogICAgICAgIF91cGRhdGUoYmFsMCAtIGFtb3VudDAsIGJhbDEgLSBhbW91bnQxKTsKCiAgICAgICAgdG9rZW4wLnRyYW5zZmVyKG1zZy5zZW5kZXIsIGFtb3VudDApOwogICAgICAgIHRva2VuMS50cmFuc2Zlcihtc2cuc2VuZGVyLCBhbW91bnQxKTsKICAgIH0KCiAgICBmdW5jdGlvbiBfc3FydCh1aW50MjU2IHkpIHByaXZhdGUgcHVyZSByZXR1cm5zICh1aW50MjU2IHopIHsKICAgICAgICBpZiAoeSA+IDMpIHsKICAgICAgICAgICAgeiA9IHk7CiAgICAgICAgICAgIHVpbnQyNTYgeCA9IHkgLyAyICsgMTsKICAgICAgICAgICAgd2hpbGUgKHggPCB6KSB7CiAgICAgICAgICAgICAgICB6ID0geDsKICAgICAgICAgICAgICAgIHggPSAoeSAvIHggKyB4KSAvIDI7CiAgICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgaWYgKHkgIT0gMCkgewogICAgICAgICAgICB6ID0gMTsKICAgICAgICB9CiAgICB9CgogICAgZnVuY3Rpb24gX21pbih1aW50MjU2IHgsIHVpbnQyNTYgeSkgcHJpdmF0ZSBwdXJlIHJldHVybnMgKHVpbnQyNTYpIHsKICAgICAgICByZXR1cm4geCA8PSB5ID8geCA6IHk7CiAgICB9Cn0KCmludGVyZmFjZSBJRVJDMjAgewogICAgZnVuY3Rpb24gdG90YWxTdXBwbHkoKSBleHRlcm5hbCB2aWV3IHJldHVybnMgKHVpbnQyNTYpOwogICAgZnVuY3Rpb24gYmFsYW5jZU9mKGFkZHJlc3MgYWNjb3VudCkgZXh0ZXJuYWwgdmlldyByZXR1cm5zICh1aW50MjU2KTsKICAgIGZ1bmN0aW9uIHRyYW5zZmVyKGFkZHJlc3MgcmVjaXBpZW50LCB1aW50MjU2IGFtb3VudCkKICAgICAgICBleHRlcm5hbAogICAgICAgIHJldHVybnMgKGJvb2wpOwogICAgZnVuY3Rpb24gYWxsb3dhbmNlKGFkZHJlc3Mgb3duZXIsIGFkZHJlc3Mgc3BlbmRlcikKICAgICAgICBleHRlcm5hbAogICAgICAgIHZpZXcKICAgICAgICByZXR1cm5zICh1aW50MjU2KTsKICAgIGZ1bmN0aW9uIGFwcHJvdmUoYWRkcmVzcyBzcGVuZGVyLCB1aW50MjU2IGFtb3VudCkgZXh0ZXJuYWwgcmV0dXJucyAoYm9vbCk7CiAgICBmdW5jdGlvbiB0cmFuc2ZlckZyb20oYWRkcmVzcyBzZW5kZXIsIGFkZHJlc3MgcmVjaXBpZW50LCB1aW50MjU2IGFtb3VudCkKICAgICAgICBleHRlcm5hbAogICAgICAgIHJldHVybnMgKGJvb2wpOwp9Cg=="}],Pm=`Constant product AMM XY = K
Constant product AMM XY = K
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
@@ -4467,7 +4467,7 @@ specify the location of the data.
external
returns (bool);
}
-
`,$m=({prev:s,next:a})=>r.jsx(A,{version:Tm,title:Um,description:Lm,cyfrinLink:_m,html:Pm,prev:s,next:a,codes:Om}),qm="0.8.26",sb="Constant Sum AMM",ab="Constant sum AMM",nb="",lb=[{fileName:"CSAMM.sol",code:"Ly8gU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IE1JVApwcmFnbWEgc29saWRpdHkgXjAuOC4yNjsKCmNvbnRyYWN0IENTQU1NIHsKICAgIElFUkMyMCBwdWJsaWMgaW1tdXRhYmxlIHRva2VuMDsKICAgIElFUkMyMCBwdWJsaWMgaW1tdXRhYmxl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VybmFsCiAgICAgICAgcmV0dXJucyAodWludDI1NiBhbW91bnRPdXQpCiAgICB7CiAgICAgICAgcmVxdWlyZSgKICAgICAgICAgICAgX3Rva2VuSW4gPT0gYWRkcmVzcyh0b2tlbjApIHx8IF90b2tlbkluID09IGFkZHJlc3ModG9rZW4xKSwKICAgICAgICAgICAgImludmFsaWQgdG9rZW4iCiAgICAgICAgKTsKCiAgICAgICAgYm9vbCBpc1Rva2VuMCA9IF90b2tlbkluID09IGFkZHJlc3ModG9rZW4wKTsKCiAgICAgICAgKElFUkMyMCB0b2tlbkluLCBJRVJDMjAgdG9rZW5PdXQsIHVpbnQyNTYgcmVzSW4sIHVpbnQyNTYgcmVzT3V0KSA9CiAgICAgICAgaXNUb2tlbjAKICAgICAgICAgICAgPyAodG9rZW4wLCB0b2tlbjEsIHJlc2VydmUwLCByZXNlcnZlMSkKICAgICAgICAgICAgOiAodG9rZW4xLCB0b2tlbjAsIHJlc2VydmUxLCByZXNlcnZlMCk7CgogICAgICAgIHRva2VuSW4udHJhbnNmZXJGcm9tKG1zZy5zZW5kZXIsIGFkZHJlc3ModGhpcyksIF9hbW91bnRJbik7CiAgICAgICAgdWludDI1NiBhbW91bnRJbiA9IHRva2VuSW4uYmFsYW5jZU9mKGFkZHJlc3ModGhpcykpIC0gcmVzSW47CgogICAgICAgIC8vIDAuMyUgZmVlCiAgICAgICAgYW1vdW50T3V0ID0gKGFtb3VudEluICogOTk3KSAvIDEwMDA7CgogICAgICAgICh1aW50MjU2IHJlczAsIHVpbnQyNTYgcmVzMSkgPSBpc1Rva2VuMAogICAgICAgICAgICA/IChyZXNJbiArIGFtb3VudEluLCByZXNPdXQgLSBhbW91bnRPdXQpCiAgICAgICAgICAgIDogKHJlc091dCAtIGFtb3VudE91dCwgcmVzSW4gKyBhbW91bnRJbik7CgogICAgICAgIF91cGRhdGUocmVzMCwgcmVzMSk7CiAgICAgICAgdG9rZW5PdXQudHJhbnNmZXIobXNnLnNlbmRlciwgYW1vdW50T3V0KTsKICAgIH0KCiAgICBmdW5jdGlvbiBhZGRMaXF1aWRpdHkodWludDI1NiBfYW1vdW50MCwgdWludDI1NiBfYW1vdW50MSkKICAgICAgICBleHRlcm5hbAogICAgICAgIHJldHVybnMgKHVpbnQyNTYgc2hhcmVzKQogICAgewogICAgICAgIHRva2VuMC50cmFuc2ZlckZyb20obXNnLnNlbmRlciwgYWRkcmVzcyh0aGlzKSwgX2Ftb3VudDApOwogICAgICAgIHRva2VuMS50cmFuc2ZlckZyb20obXNnLnNlbmRlciwgYWRkcmVzcyh0aGlzKSwgX2Ftb3VudDEpOwoKICAgICAgICB1aW50MjU2IGJhbDAgPSB0b2tlbjAuYmFsYW5jZU9mKGFkZHJlc3ModGhpcykpOwogICAgICAgIHVpbnQyNTYgYmFsMSA9IHRva2VuMS5iYWxhbmNlT2YoYWRkcmVzcyh0aGlzKSk7CgogICAgICAgIHVpbnQyNTYgZDAgPSBiYWwwIC0gcmVzZXJ2ZTA7CiAgICAgICAgdWludDI1NiBkMSA9IGJhbDEgLSByZXNlcnZlMTsKCiAgICAgICAgLyoKICAgICAgICBhID0gYW1vdW50IGluCiAgICAgICAgTCA9IHRvdGFsIGxpcXVpZGl0eQogICAgICAgIHMgPSBzaGFyZXMgdG8gbWludAogICAgICAgIFQgPSB0b3RhbCBzdXBwbHkKCiAgICAgICAgcyBzaG91bGQgYmUgcHJvcG9ydGlvbmFsIHRvIGluY3JlYXNlIGZyb20gTCB0byBMICsgYQogICAgICAgIChMICsgYSkgLyBMID0gKFQgKyBzKSAvIFQKCiAgICAgICAgcyA9IGEgKiBUIC8gTAogICAgICAgICovCiAgICAgICAgaWYgKHRvdGFsU3VwcGx5ID4gMCkgewogICAgICAgICAgICBzaGFyZXMgPSAoKGQwICsgZDEpICogdG90YWxTdXBwbHkpIC8gKHJlc2VydmUwICsgcmVzZXJ2ZTEpOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHNoYXJlcyA9IGQwICsgZDE7CiAgICAgICAgfQoKICAgICAgICByZXF1aXJlKHNoYXJlcyA+IDAsICJzaGFyZXMgPSAwIik7CiAgICAgICAgX21pbnQobXNnLnNlbmRlciwgc2hhcmVzKTsKCiAgICAgICAgX3VwZGF0ZShiYWwwLCBiYWwxKTsKICAgIH0KCiAgICBmdW5jdGlvbiByZW1vdmVMaXF1aWRpdHkodWludDI1NiBfc2hhcmVzKQogICAgICAgIGV4dGVybmFsCiAgICAgICAgcmV0dXJucyAodWludDI1NiBkMCwgdWludDI1NiBkMSkKICAgIHsKICAgICAgICAvKgogICAgICAgIGEgPSBhbW91bnQgb3V0CiAgICAgICAgTCA9IHRvdGFsIGxpcXVpZGl0eQogICAgICAgIHMgPSBzaGFyZXMKICAgICAgICBUID0gdG90YWwgc3VwcGx5CgogICAgICAgIGEgLyBMID0gcyAvIFQKCiAgICAgICAgYSA9IEwgKiBzIC8gVAogICAgICAgICAgPSAocmVzZXJ2ZTAgKyByZXNlcnZlMSkgKiBzIC8gVAogICAgICAgICovCiAgICAgICAgZDAgPSAocmVzZXJ2ZTAgKiBfc2hhcmVzKSAvIHRvdGFsU3VwcGx5OwogICAgICAgIGQxID0gKHJlc2VydmUxICogX3NoYXJlcykgLyB0b3RhbFN1cHBseTsKCiAgICAgICAgX2J1cm4obXNnLnNlbmRlciwgX3NoYXJlcyk7CiAgICAgICAgX3VwZGF0ZShyZXNlcnZlMCAtIGQwLCByZXNlcnZlMSAtIGQxKTsKCiAgICAgICAgaWYgKGQwID4gMCkgewogICAgICAgICAgICB0b2tlbjAudHJhbnNmZXIobXNnLnNlbmRlciwgZDApOwogICAgICAgIH0KICAgICAgICBpZiAoZDEgPiAwKSB7CiAgICAgICAgICAgIHRva2VuMS50cmFuc2Zlcihtc2cuc2VuZGVyLCBkMSk7CiAgICAgICAgfQogICAgfQp9CgppbnRlcmZhY2UgSUVSQzIwIHsKICAgIGZ1bmN0aW9uIHRvdGFsU3VwcGx5KCkgZXh0ZXJuYWwgdmlldyByZXR1cm5zICh1aW50MjU2KTsKICAgIGZ1bmN0aW9uIGJhbGFuY2VPZihhZGRyZXNzIGFjY291bnQpIGV4dGVybmFsIHZpZXcgcmV0dXJucyAodWludDI1Nik7CiAgICBmdW5jdGlvbiB0cmFuc2ZlcihhZGRyZXNzIHJlY2lwaWVudCwgdWludDI1NiBhbW91bnQpCiAgICAgICAgZXh0ZXJuYWwKICAgICAgICByZXR1cm5zIChib29sKTsKICAgIGZ1bmN0aW9uIGFsbG93YW5jZShhZGRyZXNzIG93bmVyLCBhZGRyZXNzIHNwZW5kZXIpCiAgICAgICAgZXh0ZXJuYWwKICAgICAgICB2aWV3CiAgICAgICAgcmV0dXJucyAodWludDI1Nik7CiAgICBmdW5jdGlvbiBhcHByb3ZlKGFkZHJlc3Mgc3BlbmRlciwgdWludDI1NiBhbW91bnQpIGV4dGVybmFsIHJldHVybnMgKGJvb2wpOwogICAgZnVuY3Rpb24gdHJhbnNmZXJGcm9tKGFkZHJlc3Mgc2VuZGVyLCBhZGRyZXNzIHJlY2lwaWVudCwgdWludDI1NiBhbW91bnQpCiAgICAgICAgZXh0ZXJuYWwKICAgICAgICByZXR1cm5zIChib29sKTsKfQo="}],pb=`Constant sum AMM X + Y = K
Constant sum AMM X + Y = K
Tokens trade one to one.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
@@ -6023,7 +6023,7 @@ IERC20 constant PAIR Uniswap V2 Flash Swap Example
+
`,Lb=({prev:s,next:a})=>r.jsx(A,{version:Jb,title:zb,description:Db,cyfrinLink:Eb,html:Tb,prev:s,next:a,codes:Qb}),Ub="0.8.26",_b="Uniswap V2 Flash Swap",Ob="Uniswap V2 flash swap",Pb="",$b=[{fileName:"UniswapV2FlashSwap.sol",code:"Ly8gU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IE1JVApwcmFnbWEgc29saWRpdHkgXjAuOC4yNjsKCmludGVyZmFjZSBJVW5pc3dhcFYyQ2FsbGVlIHsKICAgIGZ1bmN0aW9uIHVuaXN3YXBWM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TREMgPSAweEEwYjg2OTkxYzYyMThiMzZjMWQxOUQ0YTJlOUViMGNFMzYwNmVCNDg7Cgpjb250cmFjdCBVbmlzd2FwVjJGbGFzaFN3YXBUZXN0IGlzIFRlc3QgewogICAgSVdFVEggcHJpdmF0ZSB3ZXRoID0gSVdFVEgoV0VUSCk7CgogICAgVW5pc3dhcFYyRmxhc2hTd2FwIHByaXZhdGUgdW5pID0gbmV3IFVuaXN3YXBWMkZsYXNoU3dhcCgpOwoKICAgIGZ1bmN0aW9uIHNldFVwKCkgcHVibGljIHt9CgogICAgZnVuY3Rpb24gdGVzdEZsYXNoU3dhcCgpIHB1YmxpYyB7CiAgICAgICAgd2V0aC5kZXBvc2l0e3ZhbHVlOiAxZTE4fSgpOwogICAgICAgIC8vIEFwcHJvdmUgZmxhc2ggc3dhcCBmZWUKICAgICAgICB3ZXRoLmFwcHJvdmUoYWRkcmVzcyh1bmkpLCAxZTE4KTsKCiAgICAgICAgdWludDI1NiBhbW91bnRUb0JvcnJvdyA9IDEwICogMWUxODsKICAgICAgICB1bmkuZmxhc2hTd2FwKGFtb3VudFRvQm9ycm93KTsKCiAgICAgICAgYXNzZXJ0R3QodW5pLmFtb3VudFRvUmVwYXkoKSwgYW1vdW50VG9Cb3Jyb3cpOwogICAgfQp9Cg=="}],qb=`// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
@@ -6161,7 +6161,7 @@ IERC20 constant PAIR Foundry
-`,sw=({prev:s,next:a})=>r.jsx(A,{version:Lb,title:_b,description:Ob,cyfrinLink:Pb,html:qb,prev:s,next:a,codes:$b}),aw="0.8.26",nw="Uniswap V2 Optimal One Sided Supply",lw="Uniswap V2 Optimal One Sided Supply",pw="",ew=[{fileName:"Optimal.sol",code:"Ly8gU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IE1JVApwcmFnbWEgc29saWRpdHkgXjAuOC4yNjsKCmNvbnRyYWN0IFRlc3RVbmlzd2FwT3B0aW1hbE9uZVNpZGVkU3VwcGx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pOwoKICAgIGZ1bmN0aW9uIHRyYW5zZmVyRnJvbShhZGRyZXNzIHNlbmRlciwgYWRkcmVzcyByZWNpcGllbnQsIHVpbnQyNTYgYW1vdW50KQogICAgICAgIGV4dGVybmFsCiAgICAgICAgcmV0dXJucyAoYm9vbCk7Cn0K"}],cw=`Optimal One Sided Supply
+`,sw=({prev:s,next:a})=>r.jsx(A,{version:Ub,title:_b,description:Ob,cyfrinLink:Pb,html:qb,prev:s,next:a,codes:$b}),aw="0.8.26",nw="Uniswap V2 Optimal One Sided Supply",lw="Uniswap V2 Optimal One Sided Supply",pw="",ew=[{fileName:"Optimal.sol",code:"Ly8gU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IE1JVApwcmFnbWEgc29saWRpdHkgXjAuOC4yNjsKCmNvbnRyYWN0IFRlc3RVbmlzd2FwT3B0aW1hbE9uZVNpZGVkU3VwcGx5IHsKICAgIGFkZHJlc3MgcHJpdmF0ZSBjb25zdGFudCBGQUNUT1JZID0KICAgICAgICAweDVDNjliRWU3MDFlZjgxNGEyQjZhM0VERDRCMTY1MkNCOWNjNWFBNmY7CiAgICBhZGRyZXNzIHByaXZhdGUgY29uc3RhbnQgUk9VVEVSID0gMHg3YTI1MGQ1NjMwQjRjRjUzOTczOWRGMkM1ZEFjYjRjNjU5RjI0ODhEOwogICAgYWRkcmVzcyBwcml2YXRlIGNvbnN0YW50IFdFVEggPSAweEMwMmFhQTM5YjIyM0ZFOEQwQTBlNUM0RjI3ZUFEOTA4M0M3NTZDYzI7CgogICAgZnVuY3Rpb24gc3FydCh1aW50MjU2IHkpIHByaXZhdGUgcHVyZSByZXR1cm5zICh1aW50MjU2IHopIHsKICAgICAgICBpZiAoeSA+IDMpIHsKICAgICAgICAgICAgeiA9IHk7CiAgICAgICAgICAgIHVpbnQyNTYgeCA9IHkgLyAyICsgMTsKICAgICAgICAgICAgd2hpbGUgKHggPCB6KSB7CiAgICAgICAgICAgICAgICB6ID0geDsKICAgICAgICAgICAgICAgI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gKHVpbnQyNTYpOwoKICAgIGZ1bmN0aW9uIGJhbGFuY2VPZihhZGRyZXNzIGFjY291bnQpIGV4dGVybmFsIHZpZXcgcmV0dXJucyAodWludDI1Nik7CgogICAgZnVuY3Rpb24gdHJhbnNmZXIoYWRkcmVzcyByZWNpcGllbnQsIHVpbnQyNTYgYW1vdW50KQogICAgICAgIGV4dGVybmFsCiAgICAgICAgcmV0dXJucyAoYm9vbCk7CgogICAgZnVuY3Rpb24gYWxsb3dhbmNlKGFkZHJlc3Mgb3duZXIsIGFkZHJlc3Mgc3BlbmRlcikKICAgICAgICBleHRlcm5hbAogICAgICAgIHZpZXcKICAgICAgICByZXR1cm5zICh1aW50MjU2KTsKCiAgICBmdW5jdGlvbiBhcHByb3ZlKGFkZHJlc3Mgc3BlbmRlciwgdWludDI1NiBhbW91bnQpIGV4dGVybmFsIHJldHVybnMgKGJvb2wpOwoKICAgIGZ1bmN0aW9uIHRyYW5zZmVyRnJvbShhZGRyZXNzIHNlbmRlciwgYWRkcmVzcyByZWNpcGllbnQsIHVpbnQyNTYgYW1vdW50KQogICAgICAgIGV4dGVybmFsCiAgICAgICAgcmV0dXJucyAoYm9vbCk7Cn0K"}],cw=`Optimal One Sided Supply
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
@@ -7372,7 +7372,7 @@ IERC20 constant PAIR address indexed owner, address indexed spender, uint256 amount
);
}
-
`,zw=({prev:s,next:a})=>r.jsx(A,{version:Kw,title:Fw,description:Mw,cyfrinLink:Sw,html:Jw,prev:s,next:a,codes:xw}),Dw="0.8.26",Ew="Delegatecall",Qw="Example of how to use delegatecall in Solidity",Tw="https://www.cyfrin.io/glossary/delegatecall-solidity-code-example",Uw=[{fileName:"Delegatecall.sol",code:"Ly8gU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IE1JVApwcmFnbWEgc29saWRpdHkgXjAuOC4yNjsKCi8vIE5PVEU6IERlcGxveSB0aGlzIGNvbnRyYWN0IGZpcnN0CmNvbnRyYWN0IEIgewogICAgLy8gTk9URTogc3RvcmFnZSBsYXlvdXQgbXVzdCBiZSB0aGUgc2FtZSBhcyBjb250cmFjdCBBCiAgICB1aW50MjU2IHB1YmxpYyBudW07CiAgICBhZGRyZXNzIHB1YmxpYyBzZW5kZXI7CiAgICB1aW50MjU2IHB1YmxpYyB2YWx1ZTsKCiAgICBmdW5jdGlvbiBzZXRWYXJzKHVpbnQyNTYgX251bSkgcHVibGljIHBheWFibGUgewogICAgICAgIG51bSA9IF9udW07CiAgICAgICAgc2VuZGVyID0gbXNnLnNlbmRlcjsKICAgICAgICB2YWx1ZSA9IG1zZy52YWx1ZTsKICAgIH0KfQoKY29udHJhY3QgQSB7CiAgICB1aW50MjU2IHB1YmxpYyBudW07CiAgICBhZGRyZXNzIHB1YmxpYyBzZW5kZXI7CiAgICB1aW50MjU2IHB1YmxpYyB2YWx1ZTsKCiAgICBmdW5jdGlvbiBzZXRWYXJzKGFkZHJlc3MgX2NvbnRyYWN0LCB1aW50MjU2IF9udW0pIHB1YmxpYyBwYXlhYmxlIHsKICAgICAgICAvLyBBJ3Mgc3RvcmFnZSBpcyBzZXQsIEIgaXMgbm90IG1vZGlmaWVkLgogICAgICAgIChib29sIHN1Y2Nlc3MsIGJ5dGVzIG1lbW9yeSBkYXRhKSA9IF9jb250cmFjdC5kZWxlZ2F0ZWNhbGwoCiAgICAgICAgICAgIGFiaS5lbmNvZGVXaXRoU2lnbmF0dXJlKCJzZXRWYXJzKHVpbnQyNTYpIiwgX251bSkKICAgICAgICApOwogICAgfQp9Cg=="}],Lw=`delegatecall
is a low level function similar to call
.
delegatecall
is a low level function similar to call
.
When contract A
executes delegatecall
to contract B
, B
's code is executed
with contract A
's storage, msg.sender
and msg.value
.
// SPDX-License-Identifier: MIT
@@ -7404,7 +7404,7 @@ IERC20 constant PAIR Solidity supports enums and they are useful to model choice and keep track of state.
+
`,_w=({prev:s,next:a})=>r.jsx(A,{version:Dw,title:Ew,description:Qw,cyfrinLink:Tw,html:Uw,prev:s,next:a,codes:Lw}),Ow="0.8.26",Pw="Enum",$w="Example of enums in Solidity",qw="https://www.cyfrin.io/glossary/enum-solidity-code-example",sk=[{fileName:"Enum.sol",code:"Ly8gU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IE1JVApwcmFnbWEgc29saWRpdHkgXjAuOC4yNjsKCmNvbnRyYWN0IEVudW0gewogICAgLy8gRW51bSByZXByZXNlbnRpbmcgc2hpcHBpbmcgc3RhdHVzCiAgICBlbnVtIFN0YXR1cyB7CiAgICAgICAgUGVuZGluZywKICAgICAgICBTaGlwcGVkLAogICAgICAgIEFjY2VwdGVkLAogICAgICAgIFJlamVjdGVkLAogICAgICAgIENhbmNlbGVkCiAgICB9CgogICAgLy8gRGVmYXVsdCB2YWx1ZSBpcyB0aGUgZmlyc3QgZWxlbWVudCBsaXN0ZWQgaW4KICAgIC8vIGRlZmluaXRpb24gb2YgdGhlIHR5cGUsIGluIHRoaXMgY2FzZSAiUGVuZGluZyIKICAgIFN0YXR1cyBwdWJsaWMgc3RhdHVzOwoKICAgIC8vIFJldHVybnMgdWludAogICAgLy8gUGVuZGluZyAgLSAwCiAgICAvLyBTaGlwcGVkICAtIDEKICAgIC8vIEFjY2VwdGVkIC0gMgogICAgLy8gUmVqZWN0ZWQgLSAzCiAgICAvLyBDYW5jZWxlZCAtIDQKICAgIGZ1bmN0aW9uIGdldCgpIHB1YmxpYyB2aWV3IHJldHVybnMgKFN0YXR1cykgewogICAgICAgIHJldHVybiBzdGF0dXM7CiAgICB9CgogICAgLy8gVXBkYXRlIHN0YXR1cyBieSBwYXNzaW5nIHVpbnQgaW50byBpbnB1dAogICAgZnVuY3Rpb24gc2V0KFN0YXR1cyBfc3RhdHVzKSBwdWJsaWMgewogICAgICAgIHN0YXR1cyA9IF9zdGF0dXM7CiAgICB9CgogICAgLy8gWW91IGNhbiB1cGRhdGUgdG8gYSBzcGVjaWZpYyBlbnVtIGxpa2UgdGhpcwogICAgZnVuY3Rpb24gY2FuY2VsKCkgcHVibGljIHsKICAgICAgICBzdGF0dXMgPSBTdGF0dXMuQ2FuY2VsZWQ7CiAgICB9CgogICAgLy8gZGVsZXRlIHJlc2V0cyB0aGUgZW51bSB0byBpdHMgZmlyc3QgdmFsdWUsIDAKICAgIGZ1bmN0aW9uIHJlc2V0KCkgcHVibGljIHsKICAgICAgICBkZWxldGUgc3RhdHVzOwogICAgfQp9Cg=="},{fileName:"EnumDeclaration.sol",code:"Ly8gU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IE1JVApwcmFnbWEgc29saWRpdHkgXjAuOC4yNjsKLy8gVGhpcyBpcyBzYXZlZCAnRW51bURlY2xhcmF0aW9uLnNvbCcKCmVudW0gU3RhdHVzIHsKICAgIFBlbmRpbmcsCiAgICBTaGlwcGVkLAogICAgQWNjZXB0ZWQsCiAgICBSZWplY3RlZCwKICAgIENhbmNlbGVkCn0K"},{fileName:"EnumImport.sol",code:"Ly8gU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IE1JVApwcmFnbWEgc29saWRpdHkgXjAuOC4yNjsKCmltcG9ydCAiLi9FbnVtRGVjbGFyYXRpb24uc29sIjsKCmNvbnRyYWN0IEVudW0gewogICAgU3RhdHVzIHB1YmxpYyBzdGF0dXM7Cn0K"}],ak=`Solidity supports enums and they are useful to model choice and keep track of state.
Enums can be declared outside of a contract.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
@@ -7684,7 +7684,7 @@ assertion probably means that there is a bug.
Events cannot be used in view
or pure
functions, as they alter the state of the blockchain by storing logs.
Be mindful of the gas cost associated with emitting events, especially when indexing parameters, as it can impact the overall gas consumption of your contract.
-`,Yk=({prev:s,next:a})=>r.jsx(A,{version:Zk,title:Wk,description:Gk,cyfrinLink:Bk,html:Vk,prev:s,next:a,codes:fk}),Xk="0.8.26",Rk="EVM Memory Layout in Solidity",vk="Example of EVM memory in Solidity",Nk="",Hk=[{fileName:"YulMem.sol",code:"Ly8gU1BEWC1MaWNlbnNl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YXJ0aW5nIGZyb20gMHg4MAogICAgICAgICAgICB4IDo9IG1sb2FkKDB4ODApCiAgICAgICAgICAgIC8vIGxvYWQgMzIgYnl0ZXMgc3RhcnRpbmcgZnJvbSAweGEwICgweDgwICsgMzIgPSAweGEwKQogICAgICAgICAgICB5IDo9IG1sb2FkKDB4YTApCiAgICAgICAgICAgIC8vIGxvYWQgMzIgYnl0ZXMgc3RhcnRpbmcgZnJvbSAweGMwICgweGEwICsgMzIgPSAweGMwKQogICAgICAgICAgICB6IDo9IG1sb2FkKDB4YzApCiAgICAgICAgfQogICAgfQoKICAgIGZ1bmN0aW9uIHRlc3Rfd3JpdGUoKQogICAgICAgIHB1YmxpYwogICAgICAgIHB1cmUKICAgICAgICByZXR1cm5zIChieXRlczMyIGZyZWVfbWVtX3B0ciwgdWludDI1NiB4LCB1aW50MjU2IHksIHVpbnQyNTYgeikKICAgIHsKICAgICAgICAvLyBBbGxvY2F0ZXMgbWVtb3J5IDB4ODAgdG8gMHhkZiB0byBQb2ludAogICAgICAgIC8vIEZyZWUgbWVtb3J5IHBvaW50ZXIgPSAweGRmICsgMSA9IDB4ZTAKICAgICAgICBQb2ludCBtZW1vcnkgcDsKCiAgICAgICAgLy8gV3JpdGUKICAgICAgICBhc3NlbWJseSB7CiAgICAgICAgICAgIC8vIHN0b3JlIHRvIDB4ODAKICAgICAgICAgICAgbXN0b3JlKHAsIDExKQogICAgICAgICAgICAvLyBzdG9yZSB0byAweGEwCiAgICAgICAgICAgIG1zdG9yZShhZGQocCwgMHgyMCksIDIyKQogICAgICAgICAgICAvLyBzdG9yZSB0byAweGMwCiAgICAgICAgICAgIG1zdG9yZShhZGQocCwgMHg0MCksIDMzKQogICAgICAgICAgICAvLyAweGUwCiAgICAgICAgICAgIGZyZWVfbWVtX3B0ciA6PSBtbG9hZCgweDQwKQogICAgICAgIH0KCiAgICAgICAgeCA9IHAueDsKICAgICAgICB5ID0gcC55OwogICAgICAgIHogPSBwLno7CiAgICB9Cn0KCmNvbnRyYWN0IE1lbUZpeGVkQXJyYXkgewogICAgZnVuY3Rpb24gdGVzdF9yZWFkKCkKICAgICAgICBwdWJsaWMKICAgICAgICBwdXJlCiAgICAgICAgcmV0dXJucyAodWludDI1NiBhMCwgdWludDI1NiBhMSwgdWludDI1NiBhMikKICAgIHsKICAgICAgICAvLyBhcnIgaXMgbG9hZGVkIHRvIG1lbW9yeSBzdGFydGluZyBhdCAweDgwCiAgICAgICAgLy8gRWFjaCBhcnJheSBlbGVtZW50IGlzIHN0b3JlZCBhcyAzMiBieXRlcwogICAgICAgIHVpbnQzMlszXSBtZW1vcnkgYXJyID0gW3VpbnQzMigxKSwgdWludDMyKDIpLCB1aW50MzIoMyldOwoKICAgICAgICBhc3NlbWJseSB7CiAgICAgICAgICAgIGEwIDo9IG1sb2FkKDB4ODApCiAgICAgICAgICAgIGExIDo9IG1sb2FkKDB4YTApCiAgICAgICAgICAgIGEyIDo9IG1sb2FkKDB4YzApCiAgICAgICAgfQogICAgfQoKICAgIGZ1bmN0aW9uIHRlc3Rfd3JpdGUoKQogICAgICAgIHB1YmxpYwogICAgICAgIHB1cmUKICAgICAgICByZXR1cm5zICh1aW50MjU2IGEwLCB1aW50MjU2IGExLCB1aW50MjU2IGEyKQogICAgewogICAgICAgIHVpbnQzMlszXSBtZW1vcnkgYXJyOwoKICAgICAgICBhc3NlbWJseSB7CiAgICAgICAgICAgIC8vIDB4ODAKICAgICAgICAgICAgbXN0b3JlKGFyciwgMTEpCiAgICAgICAgICAgIC8vIDB4YTAKICAgICAgICAgICAgbXN0b3JlKGFkZChhcnIsIDB4MjApLCAyMikKICAgICAgICAgICAgLy8gMHhjMAogICAgICAgICAgICBtc3RvcmUoYWRkKGFyciwgMHg0MCksIDMzKQogICAgICAgIH0KCiAgICAgICAgYTAgPSBhcnJbMF07CiAgICAgICAgYTEgPSBhcnJbMV07CiAgICAgICAgYTIgPSBhcnJbMl07CiAgICB9Cn0KCmNvbnRyYWN0IE1lbUR5bmFtaWNBcnJheSB7CiAgICBmdW5jdGlvbiB0ZXN0X3JlYWQoKQogICAgICAgIHB1YmxpYwogICAgICAgIHB1cmUKICAgICAgICByZXR1cm5zIChieXRlczMyIHAsIHVpbnQyNTYgbGVuLCB1aW50MjU2IGEwLCB1aW50MjU2IGExLCB1aW50MjU2IGEyKQogICAgewogICAgICAgIHVpbnQyNTZbXSBtZW1vcnkgYXJyID0gbmV3IHVpbnQyNTZbXSg1KTsKICAgICAgICBhcnJbMF0gPSB1aW50MjU2KDExKTsKICAgICAgICBhcnJbMV0gPSB1aW50MjU2KDIyKTsKICAgICAgICBhcnJbMl0gPSB1aW50MjU2KDMzKTsKICAgICAgICBhcnJbM10gPSB1aW50MjU2KDQ0KTsKICAgICAgICBhcnJbNF0gPSB1aW50MjU2KDU1KTsKCiAgICAgICAgYXNzZW1ibHkgewogICAgICAgICAgICBwIDo9IGFycgogICAgICAgICAgICAvLyAweDgwCiAgICAgICAgICAgIGxlbiA6PSBtbG9hZChhcnIpCiAgICAgICAgICAgIC8vIDB4YTAKICAgICAgICAgICAgYTAgOj0gbWxvYWQoYWRkKGFyciwgMHgyMCkpCiAgICAgICAgICAgIC8vIDB4YzAKICAgICAgICAgICAgYTEgOj0gbWxvYWQoYWRkKGFyciwgMHg0MCkpCiAgICAgICAgICAgIC8vIDB4ZTAKICAgICAgICAgICAgYTIgOj0gbWxvYWQoYWRkKGFyciwgMHg2MCkpCiAgICAgICAgfQogICAgfQoKICAgIGZ1bmN0aW9uIHRlc3Rfd3JpdGUoKSBwdWJsaWMgcHVyZSByZXR1cm5zIChieXRlczMyIHAsIHVpbnQyNTZbXSBtZW1vcnkpIHsKICAgICAgICB1aW50MjU2W10gbWVtb3J5IGFyciA9IG5ldyB1aW50MjU2W10oMCk7CgogICAgICAgIGFzc2VtYmx5IHsKICAgICAgICAgICAgcCA6PSBhcnIKICAgICAgICAgICAgLy8gU3RvcmUgbGVuZ3RoIG9mIGFycgogICAgICAgICAgICBtc3RvcmUoYXJyLCAzKQogICAgICAgICAgICAvLyBTdG9yZSAxLCAyLCAzCiAgICAgICAgICAgIG1zdG9yZShhZGQoYXJyLCAweDIwKSwgMTEpCiAgICAgICAgICAgIG1zdG9yZShhZGQoYXJyLCAweDQwKSwgMjIpCiAgICAgICAgICAgIG1zdG9yZShhZGQoYXJyLCAweDYwKSwgMzMpCiAgICAgICAgICAgIC8vIFVwZGF0ZSBmcmVlIG1lbW9yeSBwb2ludGVyCiAgICAgICAgICAgIG1zdG9yZSgweDQwLCBhZGQoYXJyLCAweDgwKSkKICAgICAgICB9CgogICAgICAgIC8vIERhdGEgd2lsbCBiZSBBQkkgZW5jb2RlZCB3aGVuIGFyciBpcyByZXR1cm5lZCB0byBjYWxsZXIKICAgICAgICByZXR1cm4gKHAsIGFycik7CiAgICB9Cn0KCmNvbnRyYWN0IE1lbUludGVybmFsRnVuY1JldHVybiB7CiAgICBmdW5jdGlvbiBpbnRlcm5hbF9mdW5jX3JldHVybl92YWwoKSBwcml2YXRlIHB1cmUgcmV0dXJucyAodWludDI1NikgewogICAgICAgIHJldHVybiB1aW50MjU2KDB4YWJhYmFiKTsKICAgIH0KCiAgICBmdW5jdGlvbiB0ZXN0X3ZhbCgpIHB1YmxpYyBwdXJlIHsKICAgICAgICAvLyAweGFiYWJhYiB3aWxsIGJlIHN0b3JlZCBpbiB0b3Agb2YgdGhlIHN0YWNrCiAgICAgICAgaW50ZXJuYWxfZnVuY19yZXR1cm5fdmFsKCk7CiAgICB9CgogICAgZnVuY3Rpb24gaW50ZXJuYWxfZnVuY19yZXR1cm5fbWVtKCkKICAgICAgICBwcml2YXRlCiAgICAgICAgcHVyZQogICAgICAgIHJldHVybnMgKGJ5dGVzMzJbXSBtZW1vcnkpCiAgICB7CiAgICAgICAgYnl0ZXMzMltdIG1lbW9yeSBhcnIgPSBuZXcgYnl0ZXMzMltdKDMpOwogICAgICAgIGFyclswXSA9IGJ5dGVzMzIodWludDI1NigweGFhYSkpOwogICAgICAgIGFyclsxXSA9IG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FnZQogICAgICAgICAgICAvLyA9IDB4MDQgKyAweDIwICsgMHgyMCArIDB4MjAKICAgICAgICAgICAgLy8gPSAweDY0CiAgICAgICAgICAgIHJldmVydChwLCAweDY0KQogICAgICAgIH0KICAgIH0KfQoKY29udHJhY3QgTWVtS2VjY2FrIHsKICAgIGZ1bmN0aW9uIHRlc3Rfa2VjY2FrKCkgcHVibGljIHB1cmUgcmV0dXJucyAoYnl0ZXMzMikgewogICAgICAgIC8vIGtlY2NhazI1NihzdGFydCwgbGVuKSAtIEtlY2NhazI1NiBmcm9tIGRhdGEgaW4gbWVtb3J5IGZyb20gc3RhcnQgdG8gc3RhcnQgKyBsZW4KICAgICAgICBhc3NlbWJseSB7CiAgICAgICAgICAgIG1zdG9yZSgweDgwLCAxKQogICAgICAgICAgICBtc3RvcmUoMHhhMCwgMikKCiAgICAgICAgICAgIGxldCBoIDo9IGtlY2NhazI1NigweDgwLCAweDQwKQogICAgICAgICAgICBtc3RvcmUoMHhjMCwgaCkKCiAgICAgICAgICAgIHJldHVybigweGMwLCAweDIwKQogICAgICAgIH0KICAgIH0KCiAgICBmdW5jdGlvbiBrZWNjYWsoKSBwdWJsaWMgcHVyZSByZXR1cm5zIChieXRlczMyKSB7CiAgICAgICAgcmV0dXJuIGtlY2NhazI1NihhYmkuZW5jb2RlUGFja2VkKHVpbnQyNTYoMSksIHVpbnQyNTYoMikpKTsKICAgIH0KfQoKY29udHJhY3QgVGFyZ2V0IHsKICAgIGZ1bmN0aW9uIHJldHVybl91aW50MjU2KHVpbnQyNTYgeCkgcHVibGljIHB1cmUgcmV0dXJucyAodWludDI1NikgewogICAgICAgIHJldHVybiB4OwogICAgfQoKICAgIGZ1bmN0aW9uIHJldHVybl9ieXRlcyh1aW50MjU2IG4pIHB1YmxpYyBwdXJlIHJldHVybnMgKGJ5dGVzIG1lbW9yeSkgewogICAgICAgIGJ5dGVzIG1lbW9yeSBvdXQgPSBuZXcgYnl0ZXMobik7CiAgICAgICAgZm9yICh1aW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CwgYWRkKG91dCwgYWRkKDB4MjAsIHJldHVybl9kYXRhX3NpemUpKSkKICAgICAgICB9CiAgICB9Cn0KCmNvbnRyYWN0IENvdW50ZXIgewogICAgdWludDI1NiBwdWJsaWMgY291bnQ7CgogICAgZnVuY3Rpb24gaW5jKCkgcHVibGljIHJldHVybnMgKHVpbnQyNTYpIHsKICAgICAgICBjb3VudCArPSAxOwogICAgICAgIHJldHVybiBjb3VudDsKICAgIH0KfQoKY29udHJhY3QgWXVsQ2FsbCB7CiAgICBmdW5jdGlvbiB0ZXN0X2NhbGwoYWRkcmVzcyBhLCBieXRlcyBtZW1vcnkgZGF0YSkKICAgICAgICBwdWJsaWMKICAgICAgICBwYXlhYmxlCiAgICAgICAgcmV0dXJucyAoYnl0ZXMgbWVtb3J5IG91dCkKICAgIHsKICAgICAgICBhc3NlbWJseSB7CiAgICAgICAgICAgIC8vIDB4ODAKICAgICAgICAgICAgbGV0IGRhdGFfcHRyIDo9IGRhdGEKICAgICAgICAgICAgLy8gMHg2MAogICAgICAgICAgICBsZXQgb3V0X3B0ciA6PSBvdXQKCiAgICAgICAgICAgIGxldCBkYXRhX3NpemUgOj0gbWxvYWQoZGF0YSkKICAgICAgICAgICAgbGV0IGRhdGFfc3RhcnQgOj0gYWRkKGRhdGEsIDB4MjApCiAgICAgICAgICAgIGxldCBvayA6PSBjYWxsKGdhcygpLCBhLCBjYWxsdmFsdWUoKSwgZGF0YV9zdGFydCwgZGF0YV9zaXplLCAwLCAwKQoKICAgICAgICAgICAgaWYgaXN6ZXJvKG9rKSB7IHJldmVydCgwLCAwKSB9CgogICAgICAgICAgICBsZXQgcmV0dXJuX2RhdGFfc2l6ZSA6PSByZXR1cm5kYXRhc2l6ZSgpCiAgICAgICAgICAgIC8vIFN0b3JlIGxlbmd0aCBvZiByZXR1cm4gZGF0YSB0byBvdXQKICAgICAgICAgICAgbXN0b3JlKG91dCwgcmV0dXJuX2RhdGFfc2l6ZSkKICAgICAgICAgICAgLy8gQ29weS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,next:a})=>r.jsx(A,{version:Zk,title:Wk,description:Gk,cyfrinLink:Bk,html:Vk,prev:s,next:a,codes:fk}),Xk="0.8.26",Rk="EVM Memory Layout in Solidity",vk="Example of EVM memory in Solidity",Nk="",Hk=[{fileName:"YulMem.sol",code:"Ly8gU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IE1JVApwcmFnbWEgc29saWRpdHkgMC44LjI2OwoKLy8gTWVtb3J5IGxheW91dAovLyBhcnJheSBvZiBsZW5ndGggMioqMjU2ICgzMiBieXRlcyksIGVhY2ggZWxlbWVudCBzdG9yZXMgMSBieXRlICgweDAwIHRvIDB4ZmYpCi8vIGluZGV4ICAgICAwICAgIDEgICAgMiAgIC4uLiAgIDB4ZmZmLi4uZmZmID0gMioqMjU2IC0gMQovLyBtZW1vcnkgfCAwMCB8IDAwIHwgMDAgfCAuLi4gfCAwMCB8CgovLyBSZXNlcnZlZCBzbG90cwovLyAweDAwIC0gMHgzZiAoNjQgYnl0ZXMpOiBzY3JhdGNoIHNwYWNlIGZvciBoYXNoaW5nIG1ldGhvZHMKLy8gMHg0MCAtIDB4NWYgKDMyIGJ5dGVzKTogZnJlZSBtZW1vcnkgcG9pbnRlciAtIHBvaW50ZXIgdG8gbmV4dCBhdmFpbGFibGUgbG9jYXRpb24gaW4gbWVtb3J5IHRvIHN0b3JlIGRhdGEKLy8gMHg2MCAtIDB4N2YgKDMyIGJ5dGVzKTogemVybyBzbG90IC0gdXNlZCBhcyBpbml0aWFsIHZhbHVlIGZvciBkeW5hbWljIG1lbW9yeSBhcnJheXMgYW5kIHNob3VsZCBuZXZlciBiZSB3cml0dGVuIHRvCgovLyBGcmVlIG1lbW9yeSBwb2ludGVyICgweDQwKQovLyAweDgwID0gRnJlZSBtZW1vcnkgcG9pbnRlciBpbml0aWFsbHkgcG9pbnRzIGhlcmUKY29udHJhY3QgTWVtQmFzaWMgewogICAgLy8gbXN0b3JlKHAsIHYpID0gc3RvcmUgMzIgYnl0ZXMgdG8gbWV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MAogICAgICAgIC8vIDB4ODAgPSBpbml0aWFsIGZyZWUgbWVtb3J5CiAgICAgICAgUG9pbnQgbWVtb3J5IHAgPSBQb2ludCgxLCAyLCAzKTsKCiAgICAgICAgYXNzZW1ibHkgewogICAgICAgICAgICAvLyBsb2FkIDMyIGJ5dGVzIHN0YXJ0aW5nIGZyb20gMHg4MAogICAgICAgICAgICB4IDo9IG1sb2FkKDB4ODApCiAgICAgICAgICAgIC8vIGxvYWQgMzIgYnl0ZXMgc3RhcnRpbmcgZnJvbSAweGEwICgweDgwICsgMzIgPSAweGEwKQogICAgICAgICAgICB5IDo9IG1sb2FkKDB4YTApCiAgICAgICAgICAgIC8vIGxvYWQgMzIgYnl0ZXMgc3RhcnRpbmcgZnJvbSAweGMwICgweGEwICsgMzIgPSAweGMwKQogICAgICAgICAgICB6IDo9IG1sb2FkKDB4YzApCiAgICAgICAgfQogICAgfQoKICAgIGZ1bmN0aW9uIHRlc3Rfd3JpdGUoKQogICAgICAgIHB1YmxpYwogICAgICAgIHB1cmUKICAgICAgICByZXR1cm5zIChieXRlczMyIGZyZWVfbWVtX3B0ciwgdWludDI1NiB4LCB1aW50MjU2IHksIHVpbnQyNTYgeikKICAgIHsKICAgICAgICAvLyBBbGxvY2F0ZXMgbWVtb3J5IDB4ODAgdG8gMHhkZiB0byBQb2ludAogICAgICAgIC8vIEZyZWUgbWVtb3J5IHBvaW50ZXIgPSAweGRmICsgMSA9IDB4ZTAKICAgICAgICBQb2ludCBtZW1vcnkgcDsKCiAgICAgICAgLy8gV3JpdGUKICAgICAgICBhc3NlbWJseSB7CiAgICAgICAgICAgIC8vIHN0b3JlIHRvIDB4ODAKICAgICAgICAgICAgbXN0b3JlKHAsIDExKQogICAgICAgICAgICAvLyBzdG9yZSB0byAweGEwCiAgICAgICAgICAgIG1zdG9yZShhZGQocCwgMHgyMCksIDIyKQogICAgICAgICAgICAvLyBzdG9yZSB0byAweGMwCiAgICAgICAgICAgIG1zdG9yZShhZGQocCwgMHg0MCksIDMzKQogICAgICAgICAgICAvLyAweGUwCiAgICAgICAgICAgIGZyZWVfbWVtX3B0ciA6PSBtbG9hZCgweDQwKQogICAgICAgIH0KCiAgICAgICAgeCA9IHAueDsKICAgICAgICB5ID0gcC55OwogICAgICAgIHogPSBwLno7CiAgICB9Cn0KCmNvbnRyYWN0IE1lbUZpeGVkQXJyYXkgewogICAgZnVuY3Rpb24gdGVzdF9yZWFkKCkKICAgICAgICBwdWJsaWMKICAgICAgICBwdXJlCiAgICAgICAgcmV0dXJucyAodWludDI1NiBhMCwgdWludDI1NiBhMSwgdWludDI1NiBhMikKICAgIHsKICAgICAgICAvLyBhcnIgaXMgbG9hZGVkIHRvIG1lbW9yeSBzdGFydGluZyBhdCAweDgwCiAgICAgICAgLy8gRWFjaCBhcnJheSBlbGVtZW50IGlzIHN0b3JlZCBhcyAzMiBieXRlcwogICAgICAgIHVpbnQzMlszXSBtZW1vcnkgYXJyID0gW3VpbnQzMigxKSwgdWludDMyKDIpLCB1aW50MzIoMyldOwoKICAgICAgICBhc3NlbWJseSB7CiAgICAgICAgICAgIGEwIDo9IG1sb2FkKDB4ODApCiAgICAgICAgICAgIGExIDo9IG1sb2FkKDB4YTApCiAgICAgICAgICAgIGEyIDo9IG1sb2FkKDB4YzApCiAgICAgICAgfQogICAgfQoKICAgIGZ1bmN0aW9uIHRlc3Rfd3JpdGUoKQogICAgICAgIHB1YmxpYwogICAgICAgIHB1cmUKICAgICAgICByZXR1cm5zICh1aW50MjU2IGEwLCB1aW50MjU2IGExLCB1aW50MjU2IGEyKQogICAgewogICAgICAgIHVpbnQzMlszXSBtZW1vcnkgYXJyOwoKICAgICAgICBhc3NlbWJseSB7CiAgICAgICAgICAgIC8vIDB4ODAKICAgICAgICAgICAgbXN0b3JlKGFyciwgMTEpCiAgICAgICAgICAgIC8vIDB4YTAKICAgICAgICAgICAgbXN0b3JlKGFkZChhcnIsIDB4MjApLCAyMikKICAgICAgICAgICAgLy8gMHhjMAogICAgICAgICAgICBtc3RvcmUoYWRkKGFyciwgMHg0MCksIDMzKQogICAgICAgIH0KCiAgICAgICAgYTAgPSBhcnJbMF07CiAgICAgICAgYTEgPSBhcnJbMV07CiAgICAgICAgYTIgPSBhcnJbMl07CiAgICB9Cn0KCmNvbnRyYWN0IE1lbUR5bmFtaWNBcnJheSB7CiAgICBmdW5jdGlvbiB0ZXN0X3JlYWQoKQogICAgICAgIHB1YmxpYwogICAgICAgIHB1cmUKICAgICAgICByZXR1cm5zIChieXRlczMyIHAsIHVpbnQyNTYgbGVuLCB1aW50MjU2IGEwLCB1aW50MjU2IGExLCB1aW50MjU2IGEyKQogICAgewogICAgICAgIHVpbnQyNTZbXSBtZW1vcnkgYXJyID0gbmV3IHVpbnQyNTZbXSg1KTsKICAgICAgICBhcnJbMF0gPSB1aW50MjU2KDExKTsKICAgICAgICBhcnJbMV0gPSB1aW50MjU2KDIyKTsKICAgICAgICBhcnJbMl0gPSB1aW50MjU2KDMzKTsKICAgICAgICBhcnJbM10gPSB1aW50MjU2KDQ0KTsKICAgICAgICBhcnJbNF0gPSB1aW50MjU2KDU1KTsKCiAgICAgICAgYXNzZW1ibHkgewogICAgICAgICAgICBwIDo9IGFycgogICAgICAgICAgICAvLyAweDgwCiAgICAgICAgICAgIGxlbiA6PSBtbG9hZChhcnIpCiAgICAgICAgICAgIC8vIDB4YTAKICAgICAgICAgICAgYTAgOj0gbWxvYWQoYWRkKGFyciwgMHgyMCkpCiAgICAgICAgICAgIC8vIDB4YzAKICAgICAgICAgICAgYTEgOj0gbWxvYWQoYWRkKGFyciwgMHg0MCkpCiAgICAgICAgICAgIC8vIDB4ZTAKICAgICAgICAgICAgYTIgOj0gbWxvYWQoYWRkKGFyciwgMHg2MCkpCiAgICAgICAgfQogICAgfQoKICAgIGZ1bmN0aW9uIHRlc3Rfd3JpdGUoKSBwdWJsaWMgcHVyZSByZXR1cm5zIChieXRlczMyIHAsIHVpbnQyNTZbXSBtZW1vcnkpIHsKICAgICAgICB1aW50MjU2W10gbWVtb3J5IGFyciA9IG5ldyB1aW50MjU2W10oMCk7CgogICAgICAgIGFzc2VtYmx5IHsKICAgICAgICAgICAgcCA6PSBhcnIKICAgICAgICAgICAgLy8gU3RvcmUgbGVuZ3RoIG9mIGFycgogICAgICAgICAgICBtc3RvcmUoYXJyLCAzKQogICAgICAgICAgICAvLyBTdG9yZSAxLCAyLCAzCiAgICAgICAgICAgIG1zdG9yZShhZGQoYXJyLCAweDIwKSwgMTEpCiAgICAgICAgICAgIG1zdG9yZShhZGQoYXJyLCAweDQwKSwgMjIpCiAgICAgICAgICAgIG1zdG9yZShhZGQoYXJyLCAweDYwKSwgMzMpCiAgICAgICAgICAgIC8vIFVwZGF0ZSBmcmVlIG1lbW9yeSBwb2ludGVyCiAgICAgICAgICAgIG1zdG9yZSgweDQwLCBhZGQoYXJyLCAweDgwKSkKICAgICAgICB9CgogICAgICAgIC8vIERhdGEgd2lsbCBiZSBBQkkgZW5jb2RlZCB3aGVuIGFyciBpcyByZXR1cm5lZCB0byBjYWxsZXIKICAgICAgICByZXR1cm4gKHAsIGFycik7CiAgICB9Cn0KCmNvbnRyYWN0IE1lbUludGVybmFsRnVuY1JldHVybiB7CiAgICBmdW5jdGlvbiBpbnRlcm5hbF9mdW5jX3JldHVybl92YWwoKSBwcml2YXRlIHB1cmUgcmV0dXJucyAodWludDI1NikgewogICAgICAgIHJldHVybiB1aW50MjU2KDB4YWJhYmFiKTsKICAgIH0KCiAgICBmdW5jdGlvbiB0ZXN0X3ZhbCgpIHB1YmxpYyBwdXJlIHsKICAgICAgICAvLyAweGFiYWJhYiB3aWxsIGJlIHN0b3JlZCBpbiB0b3Agb2YgdGhlIHN0YWNrCiAgICAgICAgaW50ZXJuYWxfZnVuY19yZXR1cm5fdmFsKCk7CiAgICB9CgogICAgZnVuY3Rpb24gaW50ZXJuYWxfZnVuY19yZXR1cm5fbWVtKCkKICAgICAgICBwcml2YXRlCiAgICAgICAgcHVyZQogICAgICAgIHJldHVybnMgKGJ5dGVzMzJbXSBtZW1vcnkpCiAgICB7CiAgICAgICAgYnl0ZXMzMltdIG1lbW9yeSBhcnIgPSBuZXcgYnl0ZXMzMltdKDMpOwogICAgICAgIGFyclswXSA9IGJ5dGVzMzIodWludDI1NigweGFhYSkpOwogICAgICAgIGFyclsxXSA9IGJ5dGVzMzIodWludDI1NigweGJiYikpOwogICAgICAgIGFyclsyXSA9IGJ5dGVzMzIodWludDI1NigweGNjYykpOwogICAgICAgIHJldHVybiBhcnI7CiAgICB9CgogICAgZnVuY3Rpb24gdGVzdF9tZW0oKQogICAgICAgIHB1YmxpYwogICAgICAgIHB1cmUKICAgICAgICByZXR1cm5zICh1aW50MjU2IGxlbiwgYnl0ZXMzMiBhMCwgYnl0ZXMzMiBhMSwgYnl0ZXMzMiBhMikKICAgIHsKICAgICAgICAvLyBTdG9yZXMgMHg4MCB0byB0b3Agb2YgdGhlIHN0YWNrCiAgICAgICAgLy8gMHg4MCA9IG1lbW9yeSBwb2ludGVyIHRvIGJlZ2lubmluZyBvZiBhcnIKICAgICAgICBpbnRlcm5hbF9mdW5jX3JldHVybl9tZW0oKTsKICAgICAgICAvLyBSZWFkIGRhdGEgZnJvbSBhcnIsIGluaXRpYWxpemVkIGluIGludGVybmFsX2Z1bmNfcmV0dXJuX21lbSwgdXNpbmcgYXNzZW1ibHkKICAgICAgICBhc3NlbWJseSB7CiAgICAgICAgICAgIGxlbiA6PSBtbG9hZCgweDgwKQogICAgICAgICAgICBhMCA6PSBtbG9hZCgweGEwKQogICAgICAgICAgICBhMSA6PSBtbG9hZCgweGMwKQogICAgICAgICAgICBhMiA6PSBtbG9hZCgweGUwKQogICAgICAgIH0KICAgIH0KfQoKY29udHJhY3QgQUJJRW5jb2RlIHsKICAgIC8vIGpzIGNvZGUgdG8gc3BsaXQgc3RyaW5nIGludG8gY2h1bmtzIG9mIGxlbmd0aCA2NAogICAgLy8gc3RyLm1hdGNoKC8uezEsNjR9L2cpCgogICAgLy8gVmFsdWUgdHl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AgICAgIG1zdG9yZSgweGEwLCAyMikKICAgICAgICAgICAgcmV0dXJuKDB4ODAsIDB4NDApCiAgICAgICAgfQogICAgfQoKICAgIGZ1bmN0aW9uIHRlc3RfcmV0dXJuX2R5bl9hcnIoKSBwdWJsaWMgcHVyZSByZXR1cm5zICh1aW50MjU2W10gbWVtb3J5KSB7CiAgICAgICAgLy8gQUJJIGVuY29kZSB1aW50MjU2W10gYXJyYXkgd2l0aCAzIGVsZW1lbnRzIDExLCAyMiBhbmQgMzMKICAgICAgICBhc3NlbWJseSB7CiAgICAgICAgICAgIC8vIG9mZnNldAogICAgICAgICAgICBtc3RvcmUoMHg4MCwgMHgyMCkKICAgICAgICAgICAgLy8gbGVuZ3RoCiAgICAgICAgICAgIG1zdG9yZShhZGQoMHg4MCwgMHgyMCksIDMpCiAgICAgICAgICAgIC8vIGFycmF5IGVsZW1lbnRzCiAgICAgICAgICAgIG1zdG9yZShhZGQoMHg4MCwgMHg0MCksIDExKQogICAgICAgICAgICBtc3RvcmUoYWRkKDB4ODAsIDB4NjApLCAyMikKICAgICAgICAgICAgbXN0b3JlKGFkZCgweDgwLCAweDgwKSwgMzMpCiAgICAgICAgICAgIC8vIE5vIG5lZWQgdG8gdXBkYXRlIGZyZWUgbWVtb3J5IHBvaW50ZXIgLSBmdW5jdGlvbiBleGVjdXRpb24gZW5kcyBoZXJlCiAgICAgICAgICAgIHJldHVybigweDgwLCBtdWwoNSwgMHgyMCkpCiAgICAgICAgfQogICAgfQoKICAgIGZ1bmN0aW9uIHRlc3RfcmV0dXJuKCkgcHVibGljIHB1cmUgcmV0dXJucyAodWludDI1NiwgdWludDI1NikgewogICAgICAgIC8vIFJldHVybnMgKDExLCAyMikKICAgICAgICB0ZXN0X3JldHVybl92YWxzKCk7CiAgICAgICAgLy8gVGhpcyBjb2RlIHdpbGwgbmV2ZXIgZXhlY3V0ZQogICAgICAgIHJldHVybiAoMzMzLCA0NDQpOwogICAgfQp9Cgpjb250cmFjdCBNZW1SZX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b3J5CiAgICAgICAgICAgIGNhbGxkYXRhY29weShwLCBkYXRhLm9mZnNldCwgZGF0YS5sZW5ndGgpCiAgICAgICAgICAgIC8vIFVwZGF0ZSBmcmVlIG1lbW9yeSBwb2ludGVyCiAgICAgICAgICAgIG1zdG9yZSgweDQwLCBhZGQocCwgZGF0YS5sZW5ndGgpKQoKICAgICAgICAgICAgbGV0IG9rIDo9IHN0YXRpY2NhbGwoZ2FzKCksIGFkZHIsIHAsIGRhdGEubGVuZ3RoLCAwLCAwKQoKICAgICAgICAgICAgaWYgaXN6ZXJvKG9rKSB7IHJldmVydCgwLCAwKSB9CgogICAgICAgICAgICAvLyByZXR1cm5fZGF0YV9zaXplID0gMzIgIGZvciBjYWxsaW5nIFRhcmdldC5yZXR1cm5fdWludDI1NiAtPiB1aW50MjU2CiAgICAgICAgICAgIC8vICAgICAgICAgICAgICAgICAgPSA5NiAgZm9yIGNhbGxpbmcgVGFyZ2V0LnJldHVybl9ieXRlcyAtPiBieXRlc1tdICgzMiBvZmZzZXQsIDMyIGxlbmd0aCwgMyBieXRlcyBwYWRkZWQgdG8gMzIpCiAgICAgICAgICAgIC8vICAgICAgICAgICAgICAgICAgPSAxNjAgZm9yIGNhbGxpbmcgVGFyZ2V0LnJldHVybl91aW50MjU2X2FyciAtPiB1aW50MjU2W10gKDMyIG9mZnNldCwgMzIgbGVuZ3RoLCAzMiB4IDMgZWxlbWVudHMpCiAgICAgICAgICAgIHJldHVybl9kYXRhX3NpemUgOj0gcmV0dXJuZGF0YXNpemUoKQogICAgICAgICAgICAvLyBTdG9yZSBsZW5ndGggb2YgcmV0dXJuIGRhdGEgdG8gb3V0CiAgICAgICAgICAgIC8vIHBvaW50ZXIgdG8gb3V0ID0gMHg2MCAoemVybyBzbG90KQogICAgICAgICAgICBtc3RvcmUob3V0LCByZXR1cm5fZGF0YV9zaXplKQogICAgICAgICAgICAvLyBDb3B5IHJldHVybiBkYXRhIHRvIG91dAogICAgICAgICAgICByZXR1cm5kYXRhY29weShhZGQob3V0LCAweDIwKSwgMCwgcmV0dXJuX2RhdGFfc2l6ZSkKICAgICAgICAgICAgLy8gVXBkYXRlIGZyZWUgbWVtb3J5IHBvaW50ZXIKICAgICAgICAgICAgbXN0b3JlKDB4NDAsIGFkZChvdXQsIGFkZCgweDIwLCByZXR1cm5fZGF0YV9zaXplKSkpCiAgICAgICAgfQogICAgfQp9Cgpjb250cmFjdCBDb3VudGVyIHsKICAgIHVpbnQyNTYgcHVibGljIGNvdW50OwoKICAgIGZ1bmN0aW9uIGluYygpIHB1YmxpYyByZXR1cm5zICh1aW50MjU2KSB7CiAgICAgICAgY291bnQgKz0gMTsKICAgICAgICByZXR1cm4gY291bnQ7CiAgICB9Cn0KCmNvbnRyYWN0IFl1bENhbGwgewogICAgZnVuY3Rpb24gdGVzdF9jYWxsKGFkZHJlc3MgYSwgYnl0ZXMgbWVtb3J5IGRhdGEpCiAgICAgICAgcHVibGljCiAgICAgICAgcGF5YWJsZQogICAgICAgIHJldHVybnMgKGJ5dGVzIG1lbW9yeSBvdXQpCiAgICB7CiAgICAgICAgYXNzZW1ibHkgewogICAgICAgICAgICAvLyAweDgwCiAgICAgICAgICAgIGxldCBkYXRhX3B0ciA6PSBkYXRhCiAgICAgICAgICAgIC8vIDB4NjAKICAgICAgICAgICAgbGV0IG91dF9wdHIgOj0gb3V0CgogICAgICAgICAgICBsZXQgZGF0YV9zaXplIDo9IG1sb2FkKGRhdGEpCiAgICAgICAgICAgIGxldCBkYXRhX3N0YXJ0IDo9IGFkZChkYXRhLCAweDIwKQogICAgICAgICAgICBsZXQgb2sgOj0gY2FsbChnYXMoKSwgYSwgY2FsbHZhbHVlKCksIGRhdGFfc3RhcnQsIGRhdGFfc2l6ZSwgMCwgMCkKCiAgICAgICAgICAgIGlmIGlzemVybyhvaykgeyByZXZlcnQoMCwgMCkgfQoKICAgICAgICAgICAgbGV0IHJldHVybl9kYXRhX3NpemUgOj0gcmV0dXJuZGF0YXNpemUoKQogICAgICAgICAgICAvLyBTdG9yZSBsZW5ndGggb2YgcmV0dXJuIGRhdGEgdG8gb3V0CiAgICAgICAgICAgIG1zdG9yZShvdXQsIHJldHVybl9kYXRhX3NpemUpCiAgICAgICAgICAgIC8vIENvcHkgcmV0dXJuIGRhdGEgdG8gb3V0CiAgICAgICAgICAgIHJldHVybmRhdGFjb3B5KGFkZChvdXQsIDB4MjApLCAwLCByZXR1cm5fZGF0YV9zaXplKQogICAgICAgICAgICAvLyBVcGRhdGUgZnJlZSBtZW1vcnkgcG9pbnRlcgogICAgICAgICAgICBtc3RvcmUoMHg0MCwgYWRkKG91dCwgYWRkKDB4MjAsIHJldHVybl9kYXRhX3NpemUpKSkKICAgICAgICB9CiAgICB9CgogICAgZnVuY3Rpb24gdGVzdF9pbmMoYWRkcmVzcyBjb3VudGVyKSBwdWJsaWMgcmV0dXJucyAodWludDI1NiBjb3VudCkgewogICAgICAgIGJ5dGVzIG1lbW9yeSByZXMgPSB0ZXN0X2NhbGwoY291bnRlciwgYWJpLmVuY29kZUNhbGwoQ291bnRlci5pbmMsICgpKSk7CiAgICAgICAgY291bnQgPSBhYmkuZGVjb2RlKHJlcywgKHVpbnQyNTYpKTsKICAgIH0KfQoKLy8gTWVtb3J5IGV4cGFuc2lvbiBnYXMgY29zdAovLyBHYXMgY29zdCBpcyBxdWFkcmF0aWMgdG8gbWVtb3J5IGFsbG9jYXRpb24uCmNvbnRyYWN0IE1lbUV4cCB7CiAgICBmdW5jdGlvbiBhbGxvY19tZW0odWludDI1NiBuKSBleHRlcm5hbCB2aWV3IHJldHVybnMgKHVpbnQyNTYpIHsKICAgICAgICB1aW50MjU2IGdhc19zdGFydCA9IGdhc2xlZnQoKTsKICAgICAgICB1aW50MjU2W10gbWVtb3J5IGFyciA9IG5ldyB1aW50MjU2W10obik7CiAgICAgICAgdWludDI1NiBnYXNfZW5kID0gZ2FzbGVmdCgpOwogICAgICAgIHJldHVybiBnYXNfc3RhcnQgLSBnYXNfZW5kOwogICAgfQp9C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gICAgMTcwMDAgfCA2NjY5NTcKLy8gICAgMTgwMDAgfCA3NDEzMzYKLy8gICAgMTkwMDAgfCA4MTk2MjEKLy8gICAgMjAwMDAgfCA5MDE4MTIK"}],Kk=`Examples of
- Reading and writing to memory with
assembly
- Memory layout in Solidity of different data types
@@ -7929,7 +7929,7 @@ assertion probably means that there is a bug.
return abi.encode(addr);
}
- // Fixed sized bytes -> zero padded on the righ side
+ // Fixed sized bytes -> zero padded on the right side
// 0xaabbccdd00000000000000000000000000000000000000000000000000000000
function encode_bytes4() public pure returns (bytes memory) {
bytes4 b4 = 0xaabbccdd;
@@ -8876,7 +8876,7 @@ assertion probably means that there is a bug.
}
}
}
-
`,Ek=({prev:s,next:a})=>r.jsx(A,{version:Mk,title:Sk,description:xk,cyfrinLink:Jk,html:Dk,prev:s,next:a,codes:zk}),Qk="0.8.26",Tk="Fallback",Uk="Example of how to use fallback in Solidity",Lk="https://www.cyfrin.io/glossary/fallback-solidity-code-example",_k=[{fileName:"Fallback.sol",code:"Ly8gU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IE1JVApwcmFnbWEgc29saWRpdHkgXjAuOC4yNjsKCmNvbnRyYWN0IEZhbGxiYWNrIHsKICAgIGV2ZW50IExvZyhzdHJpbmcgZnVuYywgdWludDI1NiBnYXMpOwoKICAgIC8vIEZhbGxiYWNrIGZ1bmN0aW9uIG11c3QgYmUgZGVjbGFyZWQgYXMgZXh0ZXJuYWwuCiAgICBmYWxsYmFjaygpIGV4dGVybmFsIHBheWFibGUgewogICAgICAgIC8vIHNlbmQgLyB0cmFuc2ZlciAoZm9yd2FyZHMgMjMwMCBnYXMgdG8gdGhpcyBmYWxsYmFjayBmdW5jdGlvbikKICAgICAgICAvLyBjYWxsIChmb3J3YXJkcyBhbGwgb2YgdGhlIGdhcykKICAgICAgICBlbWl0IExvZygiZmFsbGJhY2siLCBnYXNsZWZ0KCkpOwogICAgfQoKICAgIC8vIFJlY2VpdmUgaXMgYSB2YXJpYW50IG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RlcyBtZW1vcnkpIHsKICAgICAgICByZXR1cm4KICAgICAgICAgICAgKGFiaS5lbmNvZGVDYWxsKENvdW50ZXIuZ2V0LCAoKSksIGFiaS5lbmNvZGVDYWxsKENvdW50ZXIuaW5jLCAoKSkpOwogICAgfQp9Cg=="}],Ok=`fallback
is a special function that is executed either when
fallback
is a special function that is executed either when
receive()
does not exist or msg.data
is not emptyHere is a simple contract that you can get, increment and decrement the count stored in this contract.
+`,Pk=({prev:s,next:a})=>r.jsx(A,{version:Qk,title:Tk,description:Lk,cyfrinLink:Uk,html:Ok,prev:s,next:a,codes:_k}),$k="0.8.26",qk="First Application",s0="Example of smart contract in Solidity",a0="",n0=[{fileName:"Counter.sol",code:"Ly8gU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IE1JVApwcmFnbWEgc29saWRpdHkgXjAuOC4yNjsKCmNvbnRyYWN0IENvdW50ZXIgewogICAgdWludDI1NiBwdWJsaWMgY291bnQ7CgogICAgLy8gRnVuY3Rpb24gdG8gZ2V0IHRoZSBjdXJyZW50IGNvdW50CiAgICBmdW5jdGlvbiBnZXQoKSBwdWJsaWMgdmlldyByZXR1cm5zICh1aW50MjU2KSB7CiAgICAgICAgcmV0dXJuIGNvdW50OwogICAgfQoKICAgIC8vIEZ1bmN0aW9uIHRvIGluY3JlbWVudCBjb3VudCBieSAxCiAgICBmdW5jdGlvbiBpbmMoKSBwdWJsaWMgewogICAgICAgIGNvdW50ICs9IDE7CiAgICB9CgogICAgLy8gRnVuY3Rpb24gdG8gZGVjcmVtZW50IGNvdW50IGJ5IDEKICAgIGZ1bmN0aW9uIGRlYygpIHB1YmxpYyB7CiAgICAgICAgLy8gVGhpcyBmdW5jdGlvbiB3aWxsIGZhaWwgaWYgY291bnQgPSAwCiAgICAgICAgY291bnQgLT0gMTsKICAgIH0KfQo="}],l0=`Here is a simple contract that you can get, increment and decrement the count stored in this contract.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
@@ -9266,7 +9266,7 @@ assertion probably means that there is a bug.
console.log("res", res);
}
}
-
`,T0=({prev:s,next:a})=>r.jsx(A,{version:x0,title:J0,description:z0,cyfrinLink:D0,html:Q0,prev:s,next:a,codes:E0}),U0="0.8.26",L0="Foundry Send",_0="Foundry send",O0="",P0=[{fileName:"SendTest.sol",code:"Ly8gU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IE1JVApwcmFnbWEgc29saWRpdHkgMC44LjI2OwoKaW1wb3J0ICJmb3JnZS1zdGQvVGVzdC5zb2wiOwoKLy8gRXhhbXBsZXMgb2YgZGVhbCBhbmQgaG9heAovLyBkZWFsKGFkZHJlc3MsIHVpbnQpIC0gU2V0IEVUSCBiYWxhbmNlIG9mIGFkZHJlc3MKLy8gZGVhbChhZGRyZXNzLCBhZGRyZXNzLCB1aW50MjU2KSAtIFNldHMgRVJDMjAgdG9rZW4gYmFsYW5jZSAod29ya3MgZm9yIG1vc3QgdG9rZW5zKQovLyBob2F4KGFkZHJlc3MsIHVpbnQpIC0gZGVhbCArIHByYW5rCgpjb250cmFjdCBFUkMyMCB7CiAgICB1aW50MjU2IHB1YmxpYyB0b3RhbFN1cHBseTsKICAgIG1hcHBpbmcoYWRkcmVzcyA9PiB1aW50MjU2KSBwdWJsaWMgYmFsYW5jZU9mOwp9Cgpjb250cmFjdCBTZW5kVGVzdCBpcyBUZXN0IHsKICAgIEVSQzIwIHRva2VuID0gbmV3IEVSQzIwKCk7CgogICAgZnVuY3Rpb24gdGVzdFNlbmRFdGgoKSBwdWJsaWMgewogICAgICAgIC8vIFNldCBFVEggYmFsYW5jZQogICAgICAgIGRlYWwoYWRkcmVzcygxKSwgMTAwKTsKICAgICAgICBhc3NlcnRFcShhZGRyZXNzKDEpLmJhbGFuY2UsIDEwMCk7CgogICAgICAgIC8vIFNldCBFUkMyMCBiYWxhbmNlCiAgICAgICAgZGVhbChhZGRyZXNzKHRva2VuKSwgYWRkcmVzcygxKSwgMTApOwogICAgICAgIGFzc2VydEVxKHRva2VuLmJhbGFuY2VPZihhZGRyZXNzKDEpKSwgMTApOwogICAgfQp9Cg=="}],$0=`// SPDX-License-Identifier: MIT
+
`,T0=({prev:s,next:a})=>r.jsx(A,{version:x0,title:J0,description:z0,cyfrinLink:D0,html:Q0,prev:s,next:a,codes:E0}),L0="0.8.26",U0="Foundry Send",_0="Foundry send",O0="",P0=[{fileName:"SendTest.sol",code:"Ly8gU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IE1JVApwcmFnbWEgc29saWRpdHkgMC44LjI2OwoKaW1wb3J0ICJmb3JnZS1zdGQvVGVzdC5zb2wiOwoKLy8gRXhhbXBsZXMgb2YgZGVhbCBhbmQgaG9heAovLyBkZWFsKGFkZHJlc3MsIHVpbnQpIC0gU2V0IEVUSCBiYWxhbmNlIG9mIGFkZHJlc3MKLy8gZGVhbChhZGRyZXNzLCBhZGRyZXNzLCB1aW50MjU2KSAtIFNldHMgRVJDMjAgdG9rZW4gYmFsYW5jZSAod29ya3MgZm9yIG1vc3QgdG9rZW5zKQovLyBob2F4KGFkZHJlc3MsIHVpbnQpIC0gZGVhbCArIHByYW5rCgpjb250cmFjdCBFUkMyMCB7CiAgICB1aW50MjU2IHB1YmxpYyB0b3RhbFN1cHBseTsKICAgIG1hcHBpbmcoYWRkcmVzcyA9PiB1aW50MjU2KSBwdWJsaWMgYmFsYW5jZU9mOwp9Cgpjb250cmFjdCBTZW5kVGVzdCBpcyBUZXN0IHsKICAgIEVSQzIwIHRva2VuID0gbmV3IEVSQzIwKCk7CgogICAgZnVuY3Rpb24gdGVzdFNlbmRFdGgoKSBwdWJsaWMgewogICAgICAgIC8vIFNldCBFVEggYmFsYW5jZQogICAgICAgIGRlYWwoYWRkcmVzcygxKSwgMTAwKTsKICAgICAgICBhc3NlcnRFcShhZGRyZXNzKDEpLmJhbGFuY2UsIDEwMCk7CgogICAgICAgIC8vIFNldCBFUkMyMCBiYWxhbmNlCiAgICAgICAgZGVhbChhZGRyZXNzKHRva2VuKSwgYWRkcmVzcygxKSwgMTApOwogICAgICAgIGFzc2VydEVxKHRva2VuLmJhbGFuY2VPZihhZGRyZXNzKDEpKSwgMTApOwogICAgfQp9Cg=="}],$0=`// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
import "forge-std/Test.sol";
@@ -9294,7 +9294,7 @@ assertion probably means that there is a bug.
assertEq(token.balanceOf(address(1)), 10);
}
}
-
`,q0=({prev:s,next:a})=>r.jsx(A,{version:U0,title:L0,description:_0,cyfrinLink:O0,html:$0,prev:s,next:a,codes:P0}),sZ="0.8.26",aZ="Foundry Sign",nZ="Foundry sign",lZ="",pZ=[{fileName:"SignTest.sol",code:"Ly8gU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IE1JVApwcmFnbWEgc29saWRpdHkgMC44LjI2OwoKaW1wb3J0ICJmb3JnZS1zdGQvVGVzdC5zb2wiOwoKY29udHJhY3QgU2lnblRlc3QgaXMgVGVzdCB7CiAgICAvLyBwcml2YXRlIGtleSA9IDEyMwogICAgLy8gcHVibGljIGtleSA9IHZtLmFkZHIocHJpdmF0ZSBrZXkpCiAgICAvLyBtZXNzYWdlID0gInNlY3JldCBtZXNzYWdlIgogICAgLy8gbWVzc2FnZSBoYXNoID0ga2VjY2FrMjU2KG1lc3NhZ2UpCiAgICAvLyB2bS5zaWduKHByaXZhdGUga2V5LCBtZXNzYWdlIGhhc2gpCiAgICBmdW5jdGlvbiB0ZXN0U2lnbmF0dXJlKCkgcHVibGljIHsKICAgICAgICB1aW50MjU2IHByaXZhdGVLZXkgPSAxMjM7CiAgICAgICAgLy8gQ29tcHV0ZXMgdGhlIGFkZHJlc3MgZm9yIGEgZ2l2ZW4gcHJpdmF0ZSBrZXkuCiAgICAgICAgYWRkcmVzcyBhbGljZSA9IHZtLmFkZHIocHJpdmF0ZUtleSk7CgogICAgICAgIC8vIFRlc3QgdmFsaWQgc2lnbmF0dXJlCiAgICAgICAgYnl0ZXMzMiBtZXNzYWdlSGFzaCA9IGtlY2NhazI1NigiU2lnbmVkIGJ5IEFsaWNlIik7CgogICAgICAgICh1aW50OCB2LCBieXRlczMyIHIsIGJ5dGVzMzIgcykgPSB2bS5zaWduKHByaXZhdGVLZXksIG1lc3NhZ2VIYXNoKTsKICAgICAgICBhZGRyZXNzIHNpZ25lciA9IGVjcmVjb3ZlcihtZXNzYWdlSGFzaCwgdiwgciwgcyk7CgogICAgICAgIGFzc2VydEVxKHNpZ25lciwgYWxpY2UpOwoKICAgICAgICAvLyBUZXN0IGludmFsaWQgbWVzc2FnZQogICAgICAgIGJ5dGVzMzIgaW52YWxpZEhhc2ggPSBrZWNjYWsyNTYoIk5vdCBzaWduZWQgYnkgQWxpY2UiKTsKICAgICAgICBzaWduZXIgPSBlY3JlY292ZXIoaW52YWxpZEhhc2gsIHYsIHIsIHMpOwoKICAgICAgICBhc3NlcnRUcnVlKHNpZ25lciAhPSBhbGljZSk7CiAgICB9Cn0K"}],eZ=`// SPDX-License-Identifier: MIT
+
`,q0=({prev:s,next:a})=>r.jsx(A,{version:L0,title:U0,description:_0,cyfrinLink:O0,html:$0,prev:s,next:a,codes:P0}),sZ="0.8.26",aZ="Foundry Sign",nZ="Foundry sign",lZ="",pZ=[{fileName:"SignTest.sol",code:"Ly8gU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IE1JVApwcmFnbWEgc29saWRpdHkgMC44LjI2OwoKaW1wb3J0ICJmb3JnZS1zdGQvVGVzdC5zb2wiOwoKY29udHJhY3QgU2lnblRlc3QgaXMgVGVzdCB7CiAgICAvLyBwcml2YXRlIGtleSA9IDEyMwogICAgLy8gcHVibGljIGtleSA9IHZtLmFkZHIocHJpdmF0ZSBrZXkpCiAgICAvLyBtZXNzYWdlID0gInNlY3JldCBtZXNzYWdlIgogICAgLy8gbWVzc2FnZSBoYXNoID0ga2VjY2FrMjU2KG1lc3NhZ2UpCiAgICAvLyB2bS5zaWduKHByaXZhdGUga2V5LCBtZXNzYWdlIGhhc2gpCiAgICBmdW5jdGlvbiB0ZXN0U2lnbmF0dXJlKCkgcHVibGljIHsKICAgICAgICB1aW50MjU2IHByaXZhdGVLZXkgPSAxMjM7CiAgICAgICAgLy8gQ29tcHV0ZXMgdGhlIGFkZHJlc3MgZm9yIGEgZ2l2ZW4gcHJpdmF0ZSBrZXkuCiAgICAgICAgYWRkcmVzcyBhbGljZSA9IHZtLmFkZHIocHJpdmF0ZUtleSk7CgogICAgICAgIC8vIFRlc3QgdmFsaWQgc2lnbmF0dXJlCiAgICAgICAgYnl0ZXMzMiBtZXNzYWdlSGFzaCA9IGtlY2NhazI1NigiU2lnbmVkIGJ5IEFsaWNlIik7CgogICAgICAgICh1aW50OCB2LCBieXRlczMyIHIsIGJ5dGVzMzIgcykgPSB2bS5zaWduKHByaXZhdGVLZXksIG1lc3NhZ2VIYXNoKTsKICAgICAgICBhZGRyZXNzIHNpZ25lciA9IGVjcmVjb3ZlcihtZXNzYWdlSGFzaCwgdiwgciwgcyk7CgogICAgICAgIGFzc2VydEVxKHNpZ25lciwgYWxpY2UpOwoKICAgICAgICAvLyBUZXN0IGludmFsaWQgbWVzc2FnZQogICAgICAgIGJ5dGVzMzIgaW52YWxpZEhhc2ggPSBrZWNjYWsyNTYoIk5vdCBzaWduZWQgYnkgQWxpY2UiKTsKICAgICAgICBzaWduZXIgPSBlY3JlY292ZXIoaW52YWxpZEhhc2gsIHYsIHIsIHMpOwoKICAgICAgICBhc3NlcnRUcnVlKHNpZ25lciAhPSBhbGljZSk7CiAgICB9Cn0K"}],eZ=`// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
import "forge-std/Test.sol";
@@ -9558,7 +9558,7 @@ assertion probably means that there is a bug.
}
}
}
-
`,JZ=({prev:s,next:a})=>r.jsx(A,{version:HZ,title:KZ,description:FZ,cyfrinLink:MZ,html:xZ,prev:s,next:a,codes:SZ}),zZ="0.8.26",DZ="Gas Saving Techniques",EZ="Some gas saving techniques",QZ="https://www.cyfrin.io/glossary/gas-saving-techniques-solidity-code-example",TZ=[{fileName:"GasGolf.s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wdGltaXplZAogICAgLy8gWzEsIDIsIDMsIDQsIDUsIDEwMF0KICAgIGZ1bmN0aW9uIHN1bUlmRXZlbkFuZExlc3NUaGFuOTkodWludDI1NltdIGNhbGxkYXRhIG51bXMpIGV4dGVybmFsIHsKICAgICAgICB1aW50MjU2IF90b3RhbCA9IHRvdGFsOwogICAgICAgIHVpbnQyNTYgbGVuID0gbnVtcy5sZW5ndGg7CgogICAgICAgIGZvciAodWludDI1NiBpID0gMDsgaSA8IGxlbjspIHsKICAgICAgICAgICAgdWludDI1NiBudW0gPSBudW1zW2ldOwogICAgICAgICAgICBpZiAobnVtICUgMiA9PSAwICYmIG51bSA8IDk5KSB7CiAgICAgICAgICAgICAgICBfdG90YWwgKz0gbnVtOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHVuY2hlY2tlZCB7CiAgICAgICAgICAgICAgICArK2k7CiAgICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIHRvdGFsID0gX3RvdGFsOwogICAgfQp9Cg=="}],UZ=`Some gas saving techniques.
+`,JZ=({prev:s,next:a})=>r.jsx(A,{version:HZ,title:KZ,description:FZ,cyfrinLink:MZ,html:xZ,prev:s,next:a,codes:SZ}),zZ="0.8.26",DZ="Gas Saving Techniques",EZ="Some gas saving techniques",QZ="https://www.cyfrin.io/glossary/gas-saving-techniques-solidity-code-example",TZ=[{fileName:"GasGolf.sol",code:"Ly8gU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IE1JVApwcmFnbWEgc29saWRpdHkgXjAuOC4yNjsKCi8vIGdhcyBnb2xmCmNvbnRyYWN0IEdhc0dvbGYgewogICAgLy8gc3RhcnQgLSA1MDkwOCBnYXMKICAgIC8vIHVzZSBjYWxsZGF0YSAtIDQ5MTYzIGdhcwogICAgLy8gbG9hZCBzdGF0ZSB2YXJpYWJsZXMgdG8gbWVtb3J5IC0gNDg5NTIgZ2FzCiAgICAvLyBzaG9ydCBjaXJjdWl0IC0gNDg2MzQgZ2FzCiAgICAvLyBsb29wIGluY3JlbWVudHMgLSA0ODI0NCBnYXMKICAgIC8vIGNhY2hlIGFycmF5IGxlbmd0aCAtIDQ4MjA5IGdhcwogICAgLy8gbG9hZCBhcnJheSBlbGVtZW50cyB0byBtZW1vcnkgLSA0ODA0NyBnYXMKICAgIC8vIHVuY2hlY2sgaSBvdmVyZmxvdy91bmRlcmZsb3cgLSA0NzMwOSBnYXMKCiAgICB1aW50MjU2IHB1YmxpYyB0b3RhbDsKCiAgICAvLyBzdGFydCAtIG5vdCBnYXMgb3B0aW1pemVkCiAgICAvLyBmdW5jdGlvbiBzdW1JZkV2ZW5BbmRMZXNzVGhhbjk5KHVpbnRbXSBtZW1vcnkgbnVtcykgZXh0ZXJuYWwgewogICAgLy8gICAgIGZvciAodWludCBpID0gMDsgaSA8IG51bXMubGVuZ3RoOyBpICs9IDEpIHsKICAgIC8vICAgICAgICAgYm9vbCBpc0V2ZW4gPSBudW1zW2ldICUgMiA9PSAwOwogICAgLy8gICAgICAgICBib29sIGlzTGVzc1RoYW45OSA9IG51bXNbaV0gPCA5OTsKICAgIC8vICAgICAgICAgaWYgKGlzRXZlbiAmJiBpc0xlc3NUaGFuOTkpIHsKICAgIC8vICAgICAgICAgICAgIHRvdGFsICs9IG51bXNbaV07CiAgICAvLyAgICAgICAgIH0KICAgIC8vICAgICB9CiAgICAvLyB9CgogICAgLy8gZ2FzIG9wdGltaXplZAogICAgLy8gWzEsIDIsIDMsIDQsIDUsIDEwMF0KICAgIGZ1bmN0aW9uIHN1bUlmRXZlbkFuZExlc3NUaGFuOTkodWludDI1NltdIGNhbGxkYXRhIG51bXMpIGV4dGVybmFsIHsKICAgICAgICB1aW50MjU2IF90b3RhbCA9IHRvdGFsOwogICAgICAgIHVpbnQyNTYgbGVuID0gbnVtcy5sZW5ndGg7CgogICAgICAgIGZvciAodWludDI1NiBpID0gMDsgaSA8IGxlbjspIHsKICAgICAgICAgICAgdWludDI1NiBudW0gPSBudW1zW2ldOwogICAgICAgICAgICBpZiAobnVtICUgMiA9PSAwICYmIG51bSA8IDk5KSB7CiAgICAgICAgICAgICAgICBfdG90YWwgKz0gbnVtOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHVuY2hlY2tlZCB7CiAgICAgICAgICAgICAgICArK2k7CiAgICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIHRvdGFsID0gX3RvdGFsOwogICAgfQp9Cg=="}],LZ=`Some gas saving techniques.
memory
with calldata
All data on a smart contract can be read.
Let's see how we can read private
data. In the process you will learn how Solidity stores state variables.
// SPDX-License-Identifier: MIT
@@ -10060,7 +10060,7 @@ Ether sent from KingOfEther before the new king is set.
require(sent, "Failed to send Ether");
}
}
-
`,VW=({prev:s,next:a})=>r.jsx(A,{version:kW,title:ZW,description:WW,cyfrinLink:GW,html:fW,prev:s,next:a,codes:BW}),YW="0.8.26",XW="Deploy Different Contracts at the Same Address",RW="An example of a Solidity contract vulnerable to deploy different contracts at the same address",vW="",NW=[{fileName:"TornadoHack.sol",code:"Ly8gU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IE1JVApwcmFnbWEgc29saWRpdHkgXjAuOC4yNjsKCi8qCkNhbGxlZCBieSBBbGljZQowLiBEZXBsb3kgREFPCgpDYWxsZWQgYnkgQXR0YWNrZXIKMS4gRGVwbG95IERlcGxveWVyRGVwbG95ZXIKMi4gQ2FsbCBEZXBsb3llckRlcGxveWVyLmRlcGxveSgpCjMuIENhbGwgRGVwbG95ZXIuZGVwbG95UHJvcG9zYWwoKQoKQ2FsbGVkIGJ5IEFsaWNlCjQuIEdldCBEQU8gYXBwcm92YWwgb2YgUHJvcG9zYWwKCkNhbGxlZCBieSBBdHRhY2tlcgo1LiBEZWxldGUgUHJvcG9zYWwgYW5kIERlcGxveWVyCjYuIFJlLWRlcGxveSBEZXBsb3llcgo3LiBDYWxsIERlcGxveWVyLmRlcGxveUF0dGFjaygpCjguIENhbGwgREFPLmV4ZWN1dGUKOS4gQ2hlY2sgREFPLm93bmVyIGlzIGF0dG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VuY29kZSh1aW50MjU2KDEyMykpKTsKICAgICAgICBhZGRyZXNzIGFkZHIgPSBhZGRyZXNzKG5ldyBEZXBsb3llcntzYWx0OiBzYWx0fSgpKTsKICAgICAgICBlbWl0IExvZyhhZGRyKTsKICAgIH0KfQoKY29udHJhY3QgRGVwbG95ZXIgewogICAgZXZlbnQgTG9nKGFkZHJlc3MgYWRkcik7CgogICAgZnVuY3Rpb24gZGVwbG95UHJvcG9zYWwoKSBleHRlcm5hbCB7CiAgICAgICAgYWRkcmVzcyBhZGRyID0gYWRkcmVzcyhuZXcgUHJvcG9zYWwoKSk7CiAgICAgICAgZW1pdCBMb2coYWRkcik7CiAgICB9CgogICAgZnVuY3Rpb24gZGVwbG95QXR0YWNrKCkgZXh0ZXJuYWwgewogICAgICAgIGFkZHJlc3MgYWRkciA9IGFkZHJlc3MobmV3IEF0dGFjaygpKTsKICAgICAgICBlbWl0IExvZyhhZGRyKTsKICAgIH0KCiAgICBmdW5jdGlvbiBraWxsKCkgZXh0ZXJuYWwgewogICAgICAgIHNlbGZkZXN0cnVjdChwYXlhYmxlKGFkZHJlc3MoMCkpKTsKICAgIH0KfQo="}],HW=`Contract address deployed with create
is computed in the following way.
Contract address deployed with create
is computed in the following way.
contract address = last 20 bytes of sha3(rlp_encode(sender, nonce))
where sender
is the address of the deployer and nonce
is the number of transactions sent by sender
.
Hence it is possible to deploy different contracts at the same address if we can somehow reset the nonce
.
Transactions take some time before they are mined. An attacker can watch the transaction pool and send a transaction, have it included in a block before the original transaction. This mechanism can be abused to re-order transactions to the attacker's advantage.
@@ -10339,7 +10339,7 @@ before the original. commit.commitTime < block.timestamp, "Cannot reveal in the same block" ); - require(!commit.revealed, "Already commited and revealed"); + require(!commit.revealed, "Already committed and revealed"); bytes32 solutionHash = keccak256(abi.encodePacked(msg.sender, _solution, _secret)); @@ -10360,7 +10360,7 @@ before the original. } } } -`,DW=({prev:s,next:a})=>r.jsx(A,{version:FW,title:MW,description:SW,cyfrinLink:xW,html:zW,prev:s,next:a,codes:JW}),EW="0.8.26",QW="Hiding Malicious Code with External Contract",TW="An example of exploit where malicious code is hidden in an external contract in Solidity",UW="",LW=[{fileName:"ExternalContract.sol",code:"Ly8gU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IE1JVApwcmFnbWEgc29saWRpdHkgXjAuOC4yNjsKCi8qCkxldCdzIHNheSBBbGljZSBjYW4gc2VlIHRoZSBjb2RlIG9mIEZvbyBhbmQgQmFyIGJ1dCBub3QgTWFsLgpJdCBpcyBvYnZpb3VzIHRvIEFsaWNlIHRoYXQgRm9vLmNhbGxCYXIoKSBleGVjdXRlcyB0aGUgY29kZSBpbnNpZGUgQmFyLmxvZygpLgpIb3dldmVyIEV2ZSBkZXBsb3lzIEZvbyB3aXRoIHRoZSBhZGRyZXNzIG9mIE1hbCwgc28gdGhhdCBjYWxsaW5nIEZvby5jYWxsQmFyKCkKd2lsbCBhY3R1YWxseSBleGVjdXRlIHRoZSBjb2RlIGF0IE1hbC4KKi8KCi8qCjEuIEV2ZSBkZXBsb3lzIE1hbAoyLiBFdmUgZGVwbG95cyBGb28gd2l0aCB0aGUgYWRkcmVzcyBvZiBNYWwKMy4gQWxpY2UgY2FsbHMgRm9vLmNhbGxCYXIoKSBhZnRlciByZWFkaW5nIHRoZSBjb2RlIGFuZCBqdWRnaW5nIHRoYXQgaXQgaXMKICAgc2FmZSB0byBjYWxsLgo0LiBBbHRob3VnaCBBbGljZSBleHBlY3RlZCBCYXIubG9nKCkgdG8gYmUgZXhlY3V0ZSwgTWFsLmxvZygpIHdhcyBleGVjdXRlZC4KKi8KCmNvbnRyYWN0IEZvbyB7CiAgICBCYXIgYmFyOwoKICAgIGNvbnN0cnVjdG9yKGFkZHJlc3MgX2JhcikgewogICAgICAgIGJhciA9IEJhcihfYmFyKTsKICAgIH0KCiAgICBmdW5jdGlvbiBjYWxsQmFyKCkgcHVibGljIHsKICAgICAgICBiYXIubG9nKCk7CiAgICB9Cn0KCmNvbnRyYWN0IEJhciB7CiAgICBldmVudCBMb2coc3RyaW5nIG1lc3NhZ2UpOwoKICAgIGZ1bmN0aW9uIGxvZygpIHB1YmxpYyB7CiAgICAgICAgZW1pdCBMb2coIkJhciB3YXMgY2FsbGVkIik7CiAgICB9Cn0KCi8vIFRoaXMgY29kZSBpcyBoaWRkZW4gaW4gYSBzZXBhcmF0ZSBmaWxlCmNvbnRyYWN0IE1hbCB7CiAgICBldmVudCBMb2coc3RyaW5nIG1lc3NhZ2UpOwoKICAgIC8vIGZ1bmN0aW9uICgpIGV4dGVybmFsIHsKICAgIC8vICAgICBlbWl0IExvZygiTWFsIHdhcyBjYWxsZWQiKTsKICAgIC8vIH0KCiAgICAvLyBBY3R1YWxseSB3ZSBjYW4gZXhlY3V0ZSB0aGUgc2FtZSBleHBsb2l0IGV2ZW4gaWYgdGhpcyBmdW5jdGlvbiBkb2VzCiAgICAvLyBub3QgZXhpc3QgYnkgdXNpbmcgdGhlIGZhbGxiYWNrCiAgICBmdW5jdGlvbiBsb2coKSBwdWJsaWMgewogICAgICAgIGVtaXQgTG9nKCJNYWwgd2FzIGNhbGxlZCIpOwogICAgfQp9Cg=="}],_W=`In Solidity any address can be casted into specific contract, even if the contract at the address is not the one being casted.
This can be exploited to hide malicious code. Let's see how.
@@ -10427,7 +10427,7 @@ external contract can be reviewed constructor() public { bar = new Bar(); } -`,OW=({prev:s,next:a})=>r.jsx(A,{version:EW,title:QW,description:TW,cyfrinLink:UW,html:_W,prev:s,next:a,codes:LW}),PW="0.8.26",$W="Honeypot",qW="An example of honeypot in Solidity",s2="",a2=[{fileName:"HoneyPot.sol",code:"Ly8gU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IE1JVApwcmFnbWEgc29saWRpdHkgXjAuOC4yNjsKCi8qCkJhbmsgaXMgYSBjb250cmFjdCB0aGF0IGNhbGxzIExvZ2dlciB0byBsb2cgZXZlbnRzLgpCYW5rLndpdGhkcmF3KCkgaXMgdnVsbmVyYWJsZSB0byB0aGUgc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ogICAgfQoKICAgIC8vIEZ1bmN0aW9uIHRvIGNvbXBhcmUgc3RyaW5ncyB1c2luZyBrZWNjYWsyNTYKICAgIGZ1bmN0aW9uIGVxdWFsKHN0cmluZyBtZW1vcnkgX2EsIHN0cmluZyBtZW1vcnkgX2IpCiAgICAgICAgcHVibGljCiAgICAgICAgcHVyZQogICAgICAgIHJldHVybnMgKGJvb2wpCiAgICB7CiAgICAgICAgcmV0dXJuIGtlY2NhazI1NihhYmkuZW5jb2RlKF9hKSkgPT0ga2VjY2FrMjU2KGFiaS5lbmNvZGUoX2IpKTsKICAgIH0KfQo="}],n2=`A honeypot is a trap to catch hackers.
+`,OW=({prev:s,next:a})=>r.jsx(A,{version:EW,title:QW,description:TW,cyfrinLink:LW,html:_W,prev:s,next:a,codes:UW}),PW="0.8.26",$W="Honeypot",qW="An example of honeypot in Solidity",s2="",a2=[{fileName:"HoneyPot.sol",code:"Ly8gU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IE1JVApwcmFnbWEgc29saWRpdHkgXjAuOC4yNjsKCi8qCkJhbmsgaXMgYSBjb250cmFjdCB0aGF0IGNhbGxzIExvZ2dlciB0byBsb2cgZXZlbnRzLgpCYW5rLndpdGhkcmF3KCkgaXMgdnVsbmVyYWJsZSB0byB0aGUgcmVlbnRyYW5jeSBhdHRhY2suClNvIGEgaGFja2VyIHRyaWVzIHRvIGRyYWluIEV0aGVyIGZyb20gQmFuay4KQnV0IGFjdHVhbGx5IHRoZSByZWVudHJhY3kgZXhwbG9pdCBpcyBhIGJhaXQgZm9yIGhhY2tlcnMuCkJ5IGRlcGxveWluZyBCYW5rIHdpdGggSG9uZXlQb3QgaW4gcGxhY2Ugb2YgdGhlIExvZ2dlciwgdGhpcyBjb250cmFjdCBiZWNvbWVzCmEgdHJhcCBmb3IgaGFja2Vycy4gTGV0J3Mgc2VlIGhvdy4KCjEuIEFsaWNlIGRlcGxveXMgSG9uZXlQb3QKMi4gQWxpY2UgZGVwbG95cyBCYW5rI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mFuay53aXRoZHJhdygxIGV0aGVyKTsKICAgICAgICB9CiAgICB9CgogICAgZnVuY3Rpb24gYXR0YWNrKCkgcHVibGljIHBheWFibGUgewogICAgICAgIGJhbmsuZGVwb3NpdHt2YWx1ZTogMSBldGhlcn0oKTsKICAgICAgICBiYW5rLndpdGhkcmF3KDEgZXRoZXIpOwogICAgfQoKICAgIGZ1bmN0aW9uIGdldEJhbGFuY2UoKSBwdWJsaWMgdmlldyByZXR1cm5zICh1aW50MjU2KSB7CiAgICAgICAgcmV0dXJuIGFkZHJlc3ModGhpcykuYmFsYW5jZTsKICAgIH0KfQoKLy8gTGV0J3Mgc2F5IHRoaXMgY29kZSBpcyBpbiBhIHNlcGFyYXRlIGZpbGUgc28gdGhhdCBvdGhlcnMgY2Fubm90IHJlYWQgaXQuCmNvbnRyYWN0IEhvbmV5UG90IHsKICAgIGZ1bmN0aW9uIGxvZyhhZGRyZXNzIF9jYWxsZXIsIHVpbnQyNTYgX2Ftb3VudCwgc3RyaW5nIG1lbW9yeSBfYWN0aW9uKQogICAgICAgIHB1YmxpYwogICAgewogICAgICAgIGlmIChlcXVhbChfYWN0aW9uLCAiV2l0aGRyYXciKSkgewogICAgICAgICAgICByZXZlcnQoIkl0J3MgYSB0cmFwIik7CiAgICAgICAgfQogICAgfQoKICAgIC8vIEZ1bmN0aW9uIHRvIGNvbXBhcmUgc3RyaW5ncyB1c2luZyBrZWNjYWsyNTYKICAgIGZ1bmN0aW9uIGVxdWFsKHN0cmluZyBtZW1vcnkgX2EsIHN0cmluZyBtZW1vcnkgX2IpCiAgICAgICAgcHVibGljCiAgICAgICAgcHVyZQogICAgICAgIHJldHVybnMgKGJvb2wpCiAgICB7CiAgICAgICAgcmV0dXJuIGtlY2NhazI1NihhYmkuZW5jb2RlKF9hKSkgPT0ga2VjY2FrMjU2KGFiaS5lbmNvZGUoX2IpKTsKICAgIH0KfQo="}],n2=`A honeypot is a trap to catch hackers.
Combining two exploits, reentrancy and hiding malicious code, we can build a contract
that will catch malicious users.
@@ -10533,7 +10533,7 @@ Logger.log() calls HoneyPot.log() and reverts. Transaction fails. return keccak256(abi.encode(_a)) == keccak256(abi.encode(_b)); } } -`,l2=({prev:s,next:a})=>r.jsx(A,{version:PW,title:$W,description:qW,cyfrinLink:s2,html:n2,prev:s,next:a,codes:a2}),p2="0.8.26",e2="Arithmetic Overflow and Underflow",c2="An example of hacking Solidity with arithmetic overflow / underflow",t2="",o2=[{fileName:"Overflow.sol",code:"Ly8gU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IE1JVApwcmFnbWEgc29saWRpdHkgXjAuNy42OwoKLy8gVGhpcyBjb250cmFjdCBpcyBkZXNpZ25lZCB0byBhY3QgYXMgYSB0aW1lIHZhdWx0LgovLyBVc2VyIGNhbiBkZXBvc2l0IGludG8gdGhpcyBjb250cmFjdCBidXQgY2Fubm90IHdpdGhkcmF3IGZvciBhdGxlYXN0IGEgd2Vlay4KLy8gVXNlciBjYW4gYWxzbyBleHRlbmQgdGhlIHdhaXQgdGltZSBiZXlvbmQgdGhlIDEgd2VlayB3YWl0aW5nIHBlcmlvZC4KCi8qCjEuIERlcGxveSBUaW1lTG9jawoyLiBEZXBsb3kgQXR0YWNrIHdpdGggYWRkcmVzcyBvZiBUaW1lTG9jawozLiBDYWxsIEF0dGFjay5hdHRhY2sgc2VuZGluZyAxIGV0aGVyLiBZb3Ugd2lsbCBpbW1lZGlhdGVseSBiZSBhYmxlIHRvCiAgIHdpdGhkcmF3IHlvdXIgZXRoZXIuCgpXaGF0IGhhcHBlbmVkPwpBdHRhY2sgY2F1c2VkIHRoZSBUaW1lTG9jay5sb2NrVGltZSB0byBvdmVyZmxvdyBhbmQgd2FzIGFibGUgdG8gd2l0aGRyYXcKYmVmb3JlIHRoZSAxIHdlZWsgd2FpdGluZyBwZXJpb2QuCiovCgpjb250cmFjdCBUaW1lTG9jayB7CiAgICBtYXBwaW5nKGFkZHJlc3MgPT4gdWludDI1NikgcHVibGljIGJhbGFuY2V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9jayk7CiAgICB9CgogICAgZmFsbGJhY2soKSBleHRlcm5hbCBwYXlhYmxlIHt9CgogICAgZnVuY3Rpb24gYXR0YWNrKCkgcHVibGljIHBheWFibGUgewogICAgICAgIHRpbWVMb2NrLmRlcG9zaXR7dmFsdWU6IG1zZy52YWx1ZX0oKTsKICAgICAgICAvKgogICAgICAgIGlmIHQgPSBjdXJyZW50IGxvY2sgdGltZSB0aGVuIHdlIG5lZWQgdG8gZmluZCB4IHN1Y2ggdGhhdAogICAgICAgIHggKyB0ID0gMioqMjU2ID0gMAogICAgICAgIHNvIHggPSAtdAogICAgICAgIDIqKjI1NiA9IHR5cGUodWludCkubWF4ICsgMQogICAgICAgIHNvIHggPSB0eXBlKHVpbnQpLm1heCArIDEgLSB0CiAgICAgICAgKi8KICAgICAgICB0aW1lTG9jay5pbmNyZWFzZUxvY2tUaW1lKAogICAgICAgICAgICB0eXBlKHVpbnQyNTYpLm1heCArIDEgLSB0aW1lTG9jay5sb2NrVGltZShhZGRyZXNzKHRoaXMpKQogICAgICAgICk7CiAgICAgICAgdGltZUxvY2sud2l0aGRyYXcoKTsKICAgIH0KfQo="}],r2=`Integers in Solidity overflow / underflow without any errors
Vault shares can be inflated by donating ERC20 token to the vault.
Attacker can exploit this behavior to steal other user's deposits.
Most ERC20 have the permit
function to approve a spender if a valid signature is provided.
However WETH
does not. Surprisingly, when permit
is called on WETH
, the function call will execute without any errors.
This is because the fallback
inside WETH
is execute when permit
is called.
You can interact with other contracts by declaring an Interface
.
You can interact with other contracts by declaring an Interface
.
Interface
Libraries are similar to contracts, but you can't declare any state variable and +`,sB=({prev:s,next:a})=>r.jsx(A,{version:UG,title:_G,description:OG,cyfrinLink:PG,html:qG,prev:s,next:a,codes:$G}),aB="0.8.26",nB="Library",lB="Example of how to write and use libraries in your Solidity code",pB="https://www.cyfrin.io/glossary/library-solidity-code-example",eB=[{fileName:"Library.sol",code:"Ly8gU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IE1JVApw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XB0eSBhcnJheSIpOwogICAgICAgIGFycltpbmRleF0gPSBhcnJbYXJyLmxlbmd0aCAtIDFdOwogICAgICAgIGFyci5wb3AoKTsKICAgIH0KfQoKY29udHJhY3QgVGVzdEFycmF5IHsKICAgIHVzaW5nIEFycmF5IGZvciB1aW50MjU2W107CgogICAgdWludDI1NltdIHB1YmxpYyBhcnI7CgogICAgZnVuY3Rpb24gdGVzdEFycmF5UmVtb3ZlKCkgcHVibGljIHsKICAgICAgICBmb3IgKHVpbnQyNTYgaSA9IDA7IGkgPCAzOyBpKyspIHsKICAgICAgICAgICAgYXJyLnB1c2goaSk7CiAgICAgICAgfQoKICAgICAgICBhcnIucmVtb3ZlKDEpOwoKICAgICAgICBhc3NlcnQoYXJyLmxlbmd0aCA9PSAyKTsKICAgICAgICBhc3NlcnQoYXJyWzBdID09IDApOwogICAgICAgIGFzc2VydChhcnJbMV0gPT0gMik7CiAgICB9Cn0K"}],cB=`
Libraries are similar to contracts, but you can't declare any state variable and you can't send ether.
A library is embedded into the contract if all library functions are internal.
Otherwise the library must be deployed and then linked before the contract is deployed.
@@ -12105,7 +12105,7 @@ you can't send ether. int256 public defaultInt; // 0 address public defaultAddr; // 0x0000000000000000000000000000000000000000 } -`,zB=({prev:s,next:a})=>r.jsx(A,{version:KB,title:FB,description:MB,cyfrinLink:SB,html:JB,prev:s,next:a,codes:xB}),DB="0.8.26",EB="Sending Ether (transfer, send, call)",QB="An example of sending Ether in Solidity",TB="https://www.cyfrin.io/glossary/sending-ether-transfer-send-call-solidity-code-example",UB=[{fileName:"SendingEther.sol",code:"Ly8gU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IE1JVApwcmFnbWEgc29saWRpdHkgXjAuOC4yNjsKCmNvbnRyYWN0IFJlY2VpdmVFdGhlciB7CiAgICAvKgogICAgV2hpY2ggZnVuY3Rpb24gaXMgY2FsbGVkLCBmYWxsYmFjaygpIG9yIHJlY2VpdmUoKT8KCiAgICAgICAgICAgc2VuZCBFdGhl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nIHN1Y2Nlc3Mgb3IgZmFpbHVyZS4KICAgICAgICAvLyBUaGlzIGZ1bmN0aW9uIGlzIG5vdCByZWNvbW1lbmRlZCBmb3Igc2VuZGluZyBFdGhlci4KICAgICAgICBib29sIHNlbnQgPSBfdG8uc2VuZChtc2cudmFsdWUpOwogICAgICAgIHJlcXVpcmUoc2VudCwgIkZhaWxlZCB0byBzZW5kIEV0aGVyIik7CiAgICB9CgogICAgZnVuY3Rpb24gc2VuZFZpYUNhbGwoYWRkcmVzcyBwYXlhYmxlIF90bykgcHVibGljIHBheWFibGUgewogICAgICAgIC8vIENhbGwgcmV0dXJucyBhIGJvb2xlYW4gdmFsdWUgaW5kaWNhdGluZyBzdWNjZXNzIG9yIGZhaWx1cmUuCiAgICAgICAgLy8gVGhpcyBpcyB0aGUgY3VycmVudCByZWNvbW1lbmRlZCBtZXRob2QgdG8gdXNlLgogICAgICAgIChib29sIHNlbnQsIGJ5dGVzIG1lbW9yeSBkYXRhKSA9IF90by5jYWxse3ZhbHVlOiBtc2cudmFsdWV9KCIiKTsKICAgICAgICByZXF1aXJlKHNlbnQsICJGYWlsZWQgdG8gc2VuZCBFdGhlciIpOwogICAgfQp9Cg=="}],LB=`You can send Ether to other contracts by
transfer
(2300 gas, throws error)Unlike functions, state variables cannot be overridden by re-declaring it +`,_B=({prev:s,next:a})=>r.jsx(A,{version:DB,title:EB,description:QB,cyfrinLink:TB,html:UB,prev:s,next:a,codes:LB}),OB="0.8.26",PB="Shadowing Inherited State Variables",$B="An example of shadowing state variables by inheritance",qB="https://www.cyfrin.io/glossary/shadowing-inherited-state-variables-solidity-code-example",sf=[{fileName:"Shadow.sol",code:"Ly8gU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IE1JVApwcmFnbWEgc29saWRpdHkgXjAuOC4yNjsKCmNvbnRyYWN0IEEgewogICAgc3RyaW5nIHB1YmxpYyBuYW1lID0gIkNvbnRyYWN0IEEiOwoKICAgIGZ1bmN0aW9uIGdldE5hbWUoKSBwdWJsaWMgdmlldyByZXR1cm5zIChzdHJpbmcgbWVtb3J5KSB7CiAgICAgICAgcmV0dXJuIG5hbWU7CiAgICB9Cn0KCi8vIFNoYWRvd2luZyBpcyBkaXNhbGxvd2VkIGluIFNvbGlkaXR5IDAuNgovLyBUaGlzIHdpbGwgbm90IGNvbXBpbGUKLy8gY29udHJhY3QgQiBpcyBBIHsKLy8gICAgIHN0cmluZyBwdWJsaWMgbmFtZSA9ICJDb250cmFjdCBCIjsKLy8gfQoKY29udHJhY3QgQyBpcyBBIHsKICAgIC8vIFRoaXMgaXMgdGhlIGNvcnJlY3Qgd2F5IHRvIG92ZXJyaWRlIGluaGVyaXRlZCBzdGF0ZSB2YXJpYWJsZXMuCiAgICBjb25zdHJ1Y3RvcigpIHsKICAgICAgICBuYW1lID0gIkNvbnRyYWN0IEMiOwogICAgfQoKICAgIC8vIEMuZ2V0TmFtZSByZXR1cm5zICJDb250cmFjdCBDIgp9Cg=="}],af=`
Unlike functions, state variables cannot be overridden by re-declaring it in the child contract.
Let's learn how to correctly override inherited state variables.
// SPDX-License-Identifier: MIT
@@ -12720,7 +12720,7 @@ echidna EchidnaTestTimeAndCaller.sol --contract EchidnaTestTimeAndCaller
msg.sender.call(b);
}
}
-
`,Qf=({prev:s,next:a})=>r.jsx(A,{version:Sf,title:xf,description:Jf,cyfrinLink:zf,html:Ef,prev:s,next:a,codes:Df}),Tf="0.8.26",Uf="Try Catch",Lf="An example of try / catch in Solidity",_f="https://www.cyfrin.io/glossary/try-catch-solidity-code-example",Of=[{fileName:"TryCatch.sol",code:"Ly8gU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IE1JVApwcmFnbWEgc29saWRpdHkgXjAuOC4yNjsKCi8vIEV4dGVybmFsIGNvbnRyYWN0IHVzZWQgZm9yIHRyeSAvIGNhdGNoIGV4YW1wbGVzCmNvbnRyYWN0IEZvbyB7CiAgICBhZGRyZXNzIHB1YmxpYyBvd25lcjsKCiAgICBjb25zdHJ1Y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ZW1vcnkgcmVhc29uKSB7CiAgICAgICAgICAgIC8vIGNhdGNoIGZhaWxpbmcgYXNzZXJ0KCkKICAgICAgICAgICAgZW1pdCBMb2dCeXRlcyhyZWFzb24pOwogICAgICAgIH0KICAgIH0KfQo="}],Pf=`try / catch
can only catch errors from external function calls and contract creation.
try / catch
can only catch errors from external function calls and contract creation.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
@@ -12779,7 +12779,7 @@ echidna EchidnaTestTimeAndCaller.sol --contract EchidnaTestTimeAndCaller
}
}
}
-
`,$f=({prev:s,next:a})=>r.jsx(A,{version:Tf,title:Uf,description:Lf,cyfrinLink:_f,html:Pf,prev:s,next:a,codes:Of}),qf="0.8.26",sV="Unchecked Math",aV="An example of unchecked math in Solidity",nV="https://www.cyfrin.io/glossary/unchecked-math-solidity-code-example",lV=[{fileName:"UncheckedMath.sol",code:"Ly8gU1BEWC1MaWNlbnNlLUlkZW50aWZpZXI6IE1JVApwcmFnbWEgc29saWRpdHkgXjAuOC4yNjsKCmNvbnRyYWN0IFVuY2hlY2tlZE1hdGggewogICAgZnVuY3Rpb24gYWRkKHVpbnQyNTYgeCwgdWludDI1NiB5KSBleHRlcm5hbCBwdXJlIHJldHVybnMgKHVpbnQyNTYpIHsKICAgICAgICAvLyAyMjI5MSBnYXMKICAgICAgICAvLyByZXR1cm4geCArIHk7CgogICAgICAgIC8vIDIyMTAzIGdhcwogICAgICAgIHVuY2hlY2tlZCB7CiAgICAgICAgICAgIHJldHVybiB4ICsgeTsKICAgICAgICB9CiAgICB9CgogICAgZnVuY3Rpb24gc3ViKHVpbnQyNTYgeCwgdWludDI1NiB5KSBleHRlcm5hbCBwdXJlIHJldHVybnMgKHVpbnQyNTYpIHsKICAgICAgICAvLyAyMjMyOSBnYXMKICAgICAgICAvLyByZXR1cm4geCAtIHk7CgogICAgICAgIC8vIDIyMTQ3IGdhcwogICAgICAgIHVuY2hlY2tlZCB7CiAgICAgICAgICAgIHJldHVybiB4IC0geTsKICAgICAgICB9CiAgICB9CgogICAgZnVuY3Rpb24gc3VtT2ZDdWJlcyh1aW50MjU2IHgsIHVpbnQyNTYgeSkgZXh0ZXJuYWwgcHVyZSByZXR1cm5zICh1aW50MjU2KSB7CiAgICAgICAgLy8gV3JhcCBjb21wbGV4IG1hdGggbG9naWMgaW5zaWRlIHVuY2hlY2tlZAogICAgICAgIHVuY2hlY2tlZCB7CiAgICAgICAgICAgIHVpbnQyNTYgeDMgPSB4ICogeCAqIHg7CiAgICAgICAgICAgIHVpbnQyNTYgeTMgPSB5ICogeSAqIHk7CgogICAgICAgICAgICByZXR1cm4geDMgKyB5MzsKICAgICAgICB9CiAgICB9Cn0K"}],pV=`Overflow and underflow of numbers in Solidity 0.8 throw an error. This can be disabled by using unchecked
.
Overflow and underflow of numbers in Solidity 0.8 throw an error. This can be disabled by using unchecked
.
Disabling overflow / underflow check saves gas.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
@@ -13026,4 +13026,4 @@ echidna EchidnaTestTimeAndCaller.sol --contract EchidnaTestTimeAndCaller
return internalFunc();
}
}
-
`,vV=({prev:s,next:a})=>r.jsx(A,{version:BV,title:fV,description:VV,cyfrinLink:YV,html:RV,prev:s,next:a,codes:XV}),NV=({size:s,className:a=""})=>r.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,stroke:"currentColor",width:s,height:s,className:a,children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M21 21l-5.197-5.197m0 0A7.5 7.5 0 105.196 5.196a7.5 7.5 0 0010.607 10.607z"})}),HV="_component_efeb7_1",KV="_icon_efeb7_8",FV="_input_efeb7_12",Ie={component:HV,icon:KV,input:FV},MV=({value:s,onChange:a})=>{function n(l){a(l.target.value)}return r.jsxs("div",{className:Ie.component,children:[r.jsx(NV,{size:18,className:Ie.icon}),r.jsx("input",{className:Ie.input,placeholder:"Search",value:s,onChange:n})]})};var SV="Expected a function",Xo=NaN,xV="[object Symbol]",JV=/^\s+|\s+$/g,zV=/^[-+]0x[0-9a-f]+$/i,DV=/^0b[01]+$/i,EV=/^0o[0-7]+$/i,QV=parseInt,TV=typeof Il=="object"&&Il&&Il.Object===Object&&Il,UV=typeof self=="object"&&self&&self.Object===Object&&self,LV=TV||UV||Function("return this")(),_V=Object.prototype,OV=_V.toString,PV=Math.max,$V=Math.min,de=function(){return LV.Date.now()};function qV(s,a,n){var l,p,e,c,t,o,i=0,I=!1,d=!1,j=!0;if(typeof s!="function")throw new TypeError(SV);a=Ro(a)||0,gc(n)&&(I=!!n.leading,d="maxWait"in n,e=d?PV(Ro(n.maxWait)||0,a):e,j="trailing"in n?!!n.trailing:j);function u(k){var B=l,Y=p;return l=p=void 0,i=k,c=s.apply(Y,B),c}function m(k){return i=k,t=setTimeout(h,a),I?u(k):c}function b(k){var B=k-o,Y=k-i,x=a-B;return d?$V(x,e-Y):x}function G(k){var B=k-o,Y=k-i;return o===void 0||B>=a||B<0||d&&Y>=e}function h(){var k=de();if(G(k))return g(k);t=setTimeout(h,b(k))}function g(k){return t=void 0,j&&l?u(k):(l=p=void 0,c)}function C(){t!==void 0&&clearTimeout(t),i=0,l=o=p=t=void 0}function y(){return t===void 0?c:g(de())}function Z(){var k=de(),B=G(k);if(l=arguments,p=this,o=k,B){if(t===void 0)return m(o);if(d)return t=setTimeout(h,a),u(o)}return t===void 0&&(t=setTimeout(h,a)),c}return Z.cancel=C,Z.flush=y,Z}function gc(s){var a=typeof s;return!!s&&(a=="object"||a=="function")}function s1(s){return!!s&&typeof s=="object"}function a1(s){return typeof s=="symbol"||s1(s)&&OV.call(s)==xV}function Ro(s){if(typeof s=="number")return s;if(a1(s))return Xo;if(gc(s)){var a=typeof s.valueOf=="function"?s.valueOf():s;s=gc(a)?a+"":a}if(typeof s!="string")return s===0?s:+s;s=s.replace(JV,"");var n=DV.test(s);return n||EV.test(s)?QV(s.slice(2),n?2:8):zV.test(s)?Xo:+s}var n1=qV;const l1=Fo(n1),p1={leading:!1,trailing:!0};function e1(s,a,n){return W.useCallback(l1(s,a,p1),n)}function c1(s,a){let n=s;for(let l=0;l