diff --git a/.gitmodules b/.gitmodules index 445344c3f204..8235eb40e89a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,8 @@ [submodule "contracts"] path = contracts url = https://github.com/matter-labs/era-contracts.git + +[submodule "era-contracts-lambda"] +path = era-contracts-lambda +url = https://github.com/lambdaclass/era-contracts.git +branch = validium_mode diff --git a/Cargo.lock b/Cargo.lock index 85e6167f7793..6f303de826ce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1521,6 +1521,16 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +[[package]] +name = "colored" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbf2150cce219b664a8a70df7a1f933836724b503f8a413af9365b4dcc4d90b8" +dependencies = [ + "lazy_static", + "windows-sys 0.48.0", +] + [[package]] name = "combine" version = "4.6.6" @@ -5840,7 +5850,7 @@ checksum = "8bdf592881d821b83d471f8af290226c8d51402259e9bb5be7f9f8bdebbb11ac" dependencies = [ "bytes", "heck 0.4.1", - "itertools 0.10.5", + "itertools 0.11.0", "log", "multimap", "once_cell", @@ -5861,7 +5871,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "265baba7fabd416cf5078179f7d2cbeca4ce7a9041111900675ea7c4cb8a4c32" dependencies = [ "anyhow", - "itertools 0.10.5", + "itertools 0.11.0", "proc-macro2 1.0.69", "quote 1.0.33", "syn 2.0.38", @@ -8580,6 +8590,19 @@ dependencies = [ "serde", ] +[[package]] +name = "validium_mode_example" +version = "0.1.0" +dependencies = [ + "colored", + "ethers", + "hex", + "loadnext", + "tokio", + "zksync-web3-rs", + "zksync_web3_decl", +] + [[package]] name = "valuable" version = "0.1.0" @@ -9870,16 +9893,6 @@ dependencies = [ "zksync_web3_decl", ] -[[package]] -name = "zksync_full_stack" -version = "0.1.0" -dependencies = [ - "ethers", - "hex", - "tokio", - "zksync-web3-rs", -] - [[package]] name = "zksync_health_check" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 14dd6da44edc..dda250c1e5d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,7 +50,7 @@ members = [ "sdk/zksync-rs", # Validium Example - "zksync_full_stack", + "validium_mode_example", ] resolver = "2" diff --git a/core/lib/multivm/src/versions/vm_latest/old_vm/utils.rs b/core/lib/multivm/src/versions/vm_latest/old_vm/utils.rs index 1dbe82a81d4f..3e7d3e55c659 100644 --- a/core/lib/multivm/src/versions/vm_latest/old_vm/utils.rs +++ b/core/lib/multivm/src/versions/vm_latest/old_vm/utils.rs @@ -7,7 +7,6 @@ use zk_evm_1_4_0::{ }, }; use zksync_state::WriteStorage; -use zksync_system_constants::L1_GAS_PER_PUBDATA_BYTE; use zksync_types::{Address, U256}; use crate::vm_latest::{ @@ -96,12 +95,6 @@ pub(crate) fn precompile_calls_count_after_timestamp( sorted_timestamps.len() - sorted_timestamps.partition_point(|t| *t < from_timestamp) } -pub(crate) fn eth_price_per_pubdata_byte(l1_gas_price: u64) -> u64 { - // This value will typically be a lot less than u64 - // unless the gas price on L1 goes beyond tens of millions of gwei - l1_gas_price * (L1_GAS_PER_PUBDATA_BYTE as u64) -} - pub(crate) fn vm_may_have_ended_inner( vm: &ZkSyncVmState, ) -> Option { diff --git a/core/lib/multivm/src/versions/vm_latest/tracers/refunds.rs b/core/lib/multivm/src/versions/vm_latest/tracers/refunds.rs index e852fba1dac8..4769ea99fd20 100644 --- a/core/lib/multivm/src/versions/vm_latest/tracers/refunds.rs +++ b/core/lib/multivm/src/versions/vm_latest/tracers/refunds.rs @@ -23,10 +23,7 @@ use crate::{ vm_latest::{ bootloader_state::BootloaderState, constants::{BOOTLOADER_HEAP_PAGE, OPERATOR_REFUNDS_OFFSET, TX_GAS_LIMIT_OFFSET}, - old_vm::{ - events::merge_events, history_recorder::HistoryMode, memory::SimpleMemory, - utils::eth_price_per_pubdata_byte, - }, + old_vm::{events::merge_events, history_recorder::HistoryMode, memory::SimpleMemory}, tracers::{ traits::VmTracer, utils::{ @@ -34,6 +31,7 @@ use crate::{ }, }, types::internals::ZkSyncVmState, + utils::fee::eth_price_per_pubdata_byte, }, }; diff --git a/core/lib/multivm/src/versions/vm_latest/utils/fee.rs b/core/lib/multivm/src/versions/vm_latest/utils/fee.rs index 23b744a348f7..0575abbf8bd4 100644 --- a/core/lib/multivm/src/versions/vm_latest/utils/fee.rs +++ b/core/lib/multivm/src/versions/vm_latest/utils/fee.rs @@ -1,8 +1,14 @@ //! Utility functions for vm -use zksync_system_constants::MAX_GAS_PER_PUBDATA_BYTE; +use zksync_system_constants::{L1_GAS_PER_PUBDATA_BYTE, MAX_GAS_PER_PUBDATA_BYTE}; use zksync_utils::ceil_div; -use crate::vm_latest::old_vm::utils::eth_price_per_pubdata_byte; +pub(crate) fn eth_price_per_pubdata_byte(l1_gas_price: u64) -> u64 { + // This value will typically be a lot less than u64 + // unless the gas price on L1 goes beyond tens of millions of gwei + // TODO: make this check only once + let validium_mode = std::env::var("ETH_SENDER_SENDER_VALIDIUM_MODE") == Ok("true".to_string()); + l1_gas_price * (L1_GAS_PER_PUBDATA_BYTE as u64) * (!validium_mode as u64) +} /// Calculates the amount of gas required to publish one byte of pubdata pub fn base_fee_to_gas_per_pubdata(l1_gas_price: u64, base_fee: u64) -> u64 { diff --git a/core/lib/types/src/commitment.rs b/core/lib/types/src/commitment.rs index 3c4ec610d280..c75043aacf55 100644 --- a/core/lib/types/src/commitment.rs +++ b/core/lib/types/src/commitment.rs @@ -224,14 +224,14 @@ impl L1BatchWithMetadata { pub fn construct_pubdata(&self, validium_mode: bool) -> Vec { let mut res: Vec = vec![]; - // Process and Pack Logs - res.extend((self.header.l2_to_l1_logs.len() as u32).to_be_bytes()); - for l2_to_l1_log in &self.header.l2_to_l1_logs { - res.extend(l2_to_l1_log.0.to_bytes()); - } - - // We do not want to publish L2->L1 msgs, bytecodes, and state diffs in validium mode. + // We do not want to publish L2-L1 logs, L2->L1 msgs, bytecodes, and state diffs in validium mode. if !validium_mode { + // Process and Pack Logs + res.extend((self.header.l2_to_l1_logs.len() as u32).to_be_bytes()); + for l2_to_l1_log in &self.header.l2_to_l1_logs { + res.extend(l2_to_l1_log.0.to_bytes()); + } + // Process and Pack Msgs res.extend((self.header.l2_to_l1_messages.len() as u32).to_be_bytes()); for msg in &self.header.l2_to_l1_messages { diff --git a/era-contracts-lambda b/era-contracts-lambda new file mode 160000 index 000000000000..648773e74da0 --- /dev/null +++ b/era-contracts-lambda @@ -0,0 +1 @@ +Subproject commit 648773e74da012c5234b7270eed0e171fd684b78 diff --git a/validium.md b/validium.md deleted file mode 100644 index 7a4cd1b436a5..000000000000 --- a/validium.md +++ /dev/null @@ -1,100 +0,0 @@ -## Validium - -In order to start the node as a validium: - -- Make sure `zk` has been built and then run `zk init --validium-mode`. This will set up the Ethereum node with the - validium contracts, and also define an env var which the server will pick up in order to run as a validium node -- Start the server (`zk server`) -- Execute transactions. For testing, `cargo run --release --bin zksync_full_stack` inits a wallet, deploys a contract - and executes a tx -- Query the node for the tx hash (output of the zksync_full_stack binary): - -``` -curl -X POST -H 'content-type: application/json' 127.0.0.1:3050 -d '{"jsonrpc": "2.0", "id": 1, "method": "zks_getTransactionDetails", "params": ["0xa1ae38705aa3f3e65ec9f2ce2692aaff6e531d56031998d33ac3e015bf676680"]}' | jq - - -{ - "jsonrpc": "2.0", - "result": { - "isL1Originated": false, - "status": "verified", - "fee": "0x1c72f149e000", - "gasPerPubdata": "0xc350", - "initiatorAddress": "0x36615cf349d7f6344891b1e7ca7c72883f5dc049", - "receivedAt": "2023-11-02T18:00:02.808Z", - "ethCommitTxHash": "0xf2daa7aeba7ded2c4dcb1ceb7892c6fa34ef57fec3a175f8593d313bf2c5d314", - "ethProveTxHash": "0x7b9385ac38937207ea54403e0dbefdd9000a33b01b61d777c134057863272b6c", - "ethExecuteTxHash": null - }, - "id": 1 -} -``` - -Not all the eth-related transaction hashes might be displayed depending on how much time passes between sending the tx -and querying the node, since the transactions are bundled into batches which get entered into the batch pipeline - -- query the geth node with the `ethCommitTxHash` (remember to use your hash and not the one in the example below) - -``` -curl -X POST -H 'content-type: application/json' 127.0.0.1:8545 -d '{"jsonrpc": "2.0", "id": 1, "method": "eth_getTransactionByHash", "params": ["0xf2daa7aeba7ded2c4dcb1ceb7892c6fa34ef57fec3a175f8593d313bf2c5d314"]}' | jq - -{ - "jsonrpc": "2.0", - "id": 1, - "result": { - "blockHash": "0x67cf02bcb7752d71df784c5c1e21b860e78a8a2963c18833d5c6240eb141b4e3", - "blockNumber": "0x1d3b6", - "from": "0xde03a0b5963f75f1c8485b355ff6d30f3093bde7", - "gas": "0x3d0900", - "gasPrice": "0x3b9aca07", - "maxFeePerGas": "0x3b9aca0a", - "maxPriorityFeePerGas": "0x3b9aca00", - "hash": "0xf2daa7aeba7ded2c4dcb1ceb7892c6fa34ef57fec3a175f8593d313bf2c5d314", - "input": "0x701f58c500000000000000000000000000000000000000000000000000000000000000035a75c9fdb0ef4c97c74e433ac053b9afec3ad23563063b23890091324539c126000000000000000000000000000000000000000000000000000000000000005f0000000000000000000000000000000000000000000000000000000000000000c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a4706c86889f42762dc2a4d547d5daab9982825dba1944ea75d19c5b72a6f8816c0a000000000000000000000000000000000000000000000000000000006543e10ec341dfc85d9f9402a6d16d2b863e1c30ac8cc8853ac2c024feb960c7c121d51b0000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000006543e12600000000000000000000000000000000000000000000000000000000000000621cd68c6b5e0da5ab1354bd7523bb510155acf5ed85c2aa199b28695f90f7633a0000000000000000000000000000000000000000000000000000000000000000c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a4707fb8d37f4ce4c9fdd84f5965ec76dd3ccb89e049f92cf155bc2ddc71bfad8c5b470af434b6d50228459d0ed2e371f237933c9f3f4c3e1c1417e4b3d3fcd2b4b6000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000003e0000000000000000000000000000000000000000000000000000000000000026800000000000000000000000000000000000000000000800b00000000000000000000000000000000000000000000000000000000000000045a75c9fdb0ef4c97c74e433ac053b9afec3ad23563063b23890091324539c12600000001000000000000000000000000000000000000800b00000000000000000000000000000000000000000000000000000000000000030000000000000000000000006543e1260000000000000000000000006543e1270001000100000000000000000000000000000000000080010000000000000000000000000000000000000000000000000000000000000005c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470000100010000000000000000000000000000000000008001000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000001000100000000000000000000000000000000000080080000000000000000000000000000000000000000000000000000000000000000fef7bd9f889811e59e4076a0174087135f080177302763019adaf531257e3a8700010001000000000000000000000000000000000000800800000000000000000000000000000000000000000000000000000000000000011c204342a59bae89d48807f747a363671740f0615de30530e12e8bbfc450ece000010001000000000000000000000000000000000000800800000000000000000000000000000000000000000000000000000000000000022b4fd9c63abc805a3c11cbc1264eb6c9bcdec326c3f8b41eb92d4b2ffef611c2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0000000000000000010203090000000000000000000000000000000000000000", - "nonce": "0x38", - "to": "0x06b7877ba1a9bb15e5ae1aaac8c651969106a57a", - "transactionIndex": "0x0", - "value": "0x0", - "type": "0x2", - "accessList": [], - "chainId": "0x9", - "v": "0x0", - "r": "0x9f038380597cdc035e60916dd9bbd20d0b1a02f32eac7def479cf1f24633b100", - "s": "0x79c004b4b18d7132f980c501bc14804e6bd78cccc76a8e5fff6631b1403c832c" - } -} -``` - -if the same process is followed for a non-validium node, there is more data in the input field (see after the `01020309` -sub-array which was put in place for detecting these changes): - -``` -curl -X POST -H 'content-type: application/json' 127.0.0.1:8545 -d '{"jsonrpc": "2.0", "id": 1, "method": "eth_getTransactionByHash", "params": ["0xf2daa7aeba7ded2c4dcb1ceb7892c6fa34ef57fec3a175f8593d313bf2c5d314"]}' | jq - - -{ - "jsonrpc": "2.0", - "id": 1, - "result": { - "blockHash": "0x2dc87056f8c8b7eba3f122da43bc8db0672492aa5915f944b4842b4ab57f21f8", - "blockNumber": "0x1d628", - "from": "0xde03a0b5963f75f1c8485b355ff6d30f3093bde7", - "gas": "0x3d0900", - "gasPrice": "0x3b9aca07", - "maxFeePerGas": "0x3b9aca0a", - "maxPriorityFeePerGas": "0x3b9aca00", - "hash": "0xf2daa7aeba7ded2c4dcb1ceb7892c6fa34ef57fec3a175f8593d313bf2c5d314", - "input": "0x701f58c50000000000000000000000000000000000000000000000000000000000000003abcc4c7388651eb753807814b2c5fce3c85d7501cf89dad6e5669df9c5ede5c8000000000000000000000000000000000000000000000000000000000000005e0000000000000000000000000000000000000000000000000000000000000000c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a4706c86889f42762dc2a4d547d5daab9982825dba1944ea75d19c5b72a6f8816c0a000000000000000000000000000000000000000000000000000000006543e38b2da007083449852aa93d1b2e48cf237dafe6d11eeee14dca1a2abb3525526b100000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000006543e3a3000000000000000000000000000000000000000000000000000000000000006122173cd9a05bc38fb465363fd6aed57d93141f8bfdbc75d19ea48f2af3beb52d0000000000000000000000000000000000000000000000000000000000000000c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a4706294138c217f7427db7f8e19c4d6bc144331827e856e379016e8b66cf9fc05e6470af434b6d50228459d0ed2e371f237933c9f3f4c3e1c1417e4b3d3fcd2b4b6000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000003e0000000000000000000000000000000000000000000000000000000000000026800000000000000000000000000000000000000000000800b0000000000000000000000000000000000000000000000000000000000000004abcc4c7388651eb753807814b2c5fce3c85d7501cf89dad6e5669df9c5ede5c800000001000000000000000000000000000000000000800b00000000000000000000000000000000000000000000000000000000000000030000000000000000000000006543e3a30000000000000000000000006543e3a40001000100000000000000000000000000000000000080010000000000000000000000000000000000000000000000000000000000000005c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470000100010000000000000000000000000000000000008001000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000001000100000000000000000000000000000000000080080000000000000000000000000000000000000000000000000000000000000000fef7bd9f889811e59e4076a0174087135f080177302763019adaf531257e3a870001000100000000000000000000000000000000000080080000000000000000000000000000000000000000000000000000000000000001dc5fdb827f4535cf6d6552a98d75494dae47466825a5f2a2c8b28b15bc0fcf7a0001000100000000000000000000000000000000000080080000000000000000000000000000000000000000000000000000000000000002e7748039ceb32bda1670b1a1520470e929f74b5ce1bf29df23258c0a5301e225000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000015b00000000000000000102030900000000010001460400032c1818e4770f08c05b28829d7d5f9d401d492c7432c166dfecf4af04238ea3230058d1d0f8a5baff47f324e7d9b05e62deb67355dd311d0e6a6bf9e7c41ecec108ca1bbc31cc849a8092a36f9a321e17412dee200b956038af1c2dc83430a0e8b00058203175654ae01a169ff0277c30e5d00fb332f32855bf6204abe9a7168d00f3cf368ce957aed709b985423cd3ba11615de01ecafa15eb9a11bc6cdef4f6327900abcc4c7388651eb753807814b2c5fce3c85d7501cf89dad6e5669df9c5ede5c800000058090100000030311c72f149e00000000053321c72f149e0000000003389010000000000000000000000000000001800000034890200000000000000000000000000000018000000378902000000000000000000000000000000180000005df20c9390fffffffffffffffffffffffffffffffffffffffffffffffffffffc0000000000", - "nonce": "0x49", - "to": "0x540c25479dd1f0250e336b3abb21485afa7d8aba", - "transactionIndex": "0x0", - "value": "0x0", - "type": "0x2", - "accessList": [], - "chainId": "0x9", - "v": "0x0", - "r": "0x69874fbaab6e00210cbdc03b15aab565eeb0c706e1845601d194e243e71bd618", - "s": "0xdab5e41a8cfbe73295f57e1bd1ac409170ba251eefc822b8e2c6936aaf3ed" - } -} -``` diff --git a/zksync_full_stack/.gitignore b/validium_mode_example/.gitignore similarity index 100% rename from zksync_full_stack/.gitignore rename to validium_mode_example/.gitignore diff --git a/validium_mode_example/BytesWriter.abi b/validium_mode_example/BytesWriter.abi new file mode 100644 index 000000000000..4ac2b64a62e8 --- /dev/null +++ b/validium_mode_example/BytesWriter.abi @@ -0,0 +1,39 @@ +[ + { + "inputs": [ + { + "internalType": "bytes", + "name": "_message", + "type": "bytes" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [], + "name": "readBytes", + "outputs": [ + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes", + "name": "_message", + "type": "bytes" + } + ], + "name": "writeBytes", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/validium_mode_example/BytesWriter.bin b/validium_mode_example/BytesWriter.bin new file mode 100644 index 000000000000..979b0f1ee733 --- /dev/null +++ b/validium_mode_example/BytesWriter.bin @@ -0,0 +1 @@ +00050000000000020000008003000039000000400030043f0000000003010019000000600330027000000073033001970000000102200190000000960000c13d000000040230008c000001600000413d000000000201043b000000e0022002700000007a0420009c0000014e0000613d0000007b0220009c000001600000c13d0000000002000416000000000202004b000001600000c13d000000040230008a000000200220008c000001600000413d0000000402100370000000000502043b000000770250009c000001600000213d00000023025000390000007f04000041000000000632004b000000000600001900000000060480190000007f02200197000000000702004b00000000040080190000007f0220009c000000000406c019000000000204004b000001600000c13d0000000406500039000000000261034f000000000402043b000000770240009c0000009c0000213d000000bf07400039000000200200008a000000000727016f000000770870009c0000009c0000213d000000400070043f000000800040043f00000000054500190000002405500039000000000335004b000001600000213d0000002003600039000000000131034f0000001f0340018f0000000505400272000000440000613d00000000060000190000000507600210000000000871034f000000000808043b000000a00770003900000000008704350000000106600039000000000756004b0000003c0000413d000000000603004b000000530000613d0000000505500210000000000151034f0000000303300210000000a005500039000000000605043300000000063601cf000000000636022f000000000101043b0000010003300089000000000131022f00000000013101cf000000000161019f0000000000150435000000a0014000390000000000010435000000800100043d000000770310009c0000009c0000213d000000000400041a000000010340019000000001054002700000007f0350018f000000000305c0190000001f0530008c00000000050000190000000105002039000000000454013f00000001044001900000015c0000c13d000000200430008c000000750000413d0000001f0410003900000005044002700000007c054000410000007c04000041000000200610008c000000000405801900000000000004350000001f0330003900000005033002700000007c03300041000000000534004b000000750000813d000000000004041b0000000104400039000000000534004b000000710000413d0000001f0310008c0000019f0000a13d0000000003210170000000a0040000390000007c020000410000000000000435000000890000613d0000007c0200004100000020060000390000000004000019000000000506001900000080065000390000000006060433000000000062041b000000200650003900000001022000390000002004400039000000000734004b0000007f0000413d000000a004500039000000000313004b000000930000813d0000000303100210000000f80330018f000000010500008a000000000335022f000000000353013f0000000004040433000000000334016f000000000032041b00000001020000390000000103100210000001a90000013d0000000002000416000000000202004b000001600000c13d0000007402300041000000750220009c000000a20000213d000000800100004100000000001004350000004101000039000000040010043f0000008101000041000001c9000104300000009f023000390000007602200197000000400020043f0000001f0230018f0000000504300272000000b10000613d00000000050000190000000506500210000000000761034f000000000707043b000000800660003900000000007604350000000105500039000000000645004b000000a90000413d000000000502004b000000c00000613d0000000504400210000000000141034f00000003022002100000008004400039000000000504043300000000052501cf000000000525022f000000000101043b0000010002200089000000000121022f00000000012101cf000000000151019f0000000000140435000000200130008c000001600000413d000000800400043d000000770140009c000001600000213d00000080033000390000009f01400039000000000131004b000001600000813d00000080024000390000000001020433000000770510009c0000009c0000213d0000003f05100039000000200900008a000000000595016f000000400800043d0000000005580019000000000685004b00000000060000190000000106004039000000770750009c0000009c0000213d00000001066001900000009c0000c13d000000400050043f00000000061804360000000004140019000000a004400039000000000334004b000001600000213d000000000301004b000000e90000613d000000000300001900000000046300190000002003300039000000000523001900000000050504330000000000540435000000000413004b000000e20000413d000000000116001900000000000104350000000004080433000000770140009c0000009c0000213d000000000100041a000000010210019000000001011002700000007f0310018f000000000301c0190000001f0130008c00000000010000190000000101002039000000010110018f000000000112004b0000015c0000c13d000000200130008c0000011f0000413d000100000003001d000300000004001d000000000000043500000073010000410000000002000414000000730320009c0000000002018019000000c00120021000000078011001c70000801002000039000500000008001d000400000009001d000200000006001d01c701c20000040f0000000206000029000000040900002900000005080000290000000102200190000001600000613d00000003040000290000001f024000390000000502200270000000200340008c0000000002004019000000000301043b00000001010000290000001f01100039000000050110027000000000011300190000000002230019000000000312004b0000011f0000813d000000000002041b0000000102200039000000000312004b0000011b0000413d0000001f0140008c000001b10000a13d000300000004001d000000000000043500000073010000410000000002000414000000730320009c0000000002018019000000c00120021000000078011001c70000801002000039000500000008001d000400000009001d01c701c20000040f000000040300002900000005060000290000000102200190000001600000613d000000030700002900000000033701700000002002000039000000000101043b000001400000613d0000002002000039000000000400001900000000056200190000000005050433000000000051041b000000200220003900000001011000390000002004400039000000000534004b000001380000413d000000000373004b0000014b0000813d0000000303700210000000f80330018f000000010400008a000000000334022f000000000343013f00000000026200190000000002020433000000000232016f000000000021041b00000001010000390000000102700210000001bb0000013d0000000001000416000000000101004b000001600000c13d000000000100041a000000010310019000000001041002700000007f0240018f000000000204c0190000001f0420008c00000000040000190000000104002039000000000441013f0000000104400190000001620000613d0000008001000041000000000010043500000022010000390000009f0000013d0000000001000019000001c900010430000000800020043f000000000303004b000001750000613d000000a0010000390000000000000435000000000302004b000001810000613d0000007c0100004100000000040000190000000003040019000000000401041a000000a005300039000000000045043500000001011000390000002004300039000000000524004b0000016b0000413d000000c0013000390000017b0000013d000001000300008a000000000131016f000000a00010043f000000000102004b000000c001000039000000a0010060390000001f01100039000000200200008a000000000121016f0000007d021000410000007e0220009c0000009c0000413d000000400010043f00000020020000390000000003210436000000800200043d00000000002304350000004003100039000000000402004b000001910000613d00000000040000190000000005340019000000a006400039000000000606043300000000006504350000002004400039000000000524004b0000018a0000413d000000000332001900000000000304350000005f02200039000000200300008a000000000232016f0000007303000041000000730420009c0000000002038019000000730410009c000000000103801900000040011002100000006002200210000000000112019f000001c80001042e000000000201004b0000000002000019000001a30000613d000000a00200043d0000000303100210000000010400008a000000000334022f000000000343013f000000000332016f0000000102100210000000000123019f000000000010041b0000007301000041000000400200043d000000730320009c00000000020180190000004001200210000001c80001042e000000000104004b0000000001000019000001b50000613d00000000010604330000000302400210000000010300008a000000000223022f000000000232013f000000000221016f0000000101400210000000000112019f000000000010041b0000002001000039000001000010044300000120000004430000007901000041000001c80001042e000001c5002104230000000102000039000000000001042d0000000002000019000000000001042d000001c700000432000001c80001042e000001c9000104300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000009fffffffffffffffffffffffffffffffffffffffffffffffff000000000000007f00000000000000000000000000000000000000000000000000000001ffffffe0000000000000000000000000000000000000000000000000ffffffffffffffff0200000000000000000000000000000000000020000000000000000000000000000000020000000000000000000000000000004000000100000000000000000000000000000000000000000000000000000000000000000000000000d98b5568000000000000000000000000000000000000000000000000000000007932db75290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563ffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffffffffffffffffffffffffffffffffffff000000000000008080000000000000000000000000000000000000000000000000000000000000004e487b71000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024000000000000000000000000b6a433bc7df435258118f8b80ff5a7799eb18cd0bf3a38b685cb901f1d11d13f \ No newline at end of file diff --git a/validium_mode_example/BytesWriter.sol b/validium_mode_example/BytesWriter.sol new file mode 100644 index 000000000000..0327d2933728 --- /dev/null +++ b/validium_mode_example/BytesWriter.sol @@ -0,0 +1,27 @@ +//SPDX-License-Identifier: Unlicense +pragma solidity ^0.8.8; + +contract BytesWriter { + bytes private message; + + constructor(bytes memory _message) { + message = _message; + } + + function readBytes() public view returns (bytes memory) { + return message; + } + + function writeBytes(bytes memory _message) public { + message = _message; + } + + // event StringBytesLengthMessage(address sender, string inputString, uint256 bytesLength); + + // function getStringBytesLength(string memory str) external { + // bytes memory strBytes = bytes(str); + // uint256 length = strBytes.length; + + // emit StringBytesLengthMessage(msg.sender, str, length); + // } +} diff --git a/zksync_full_stack/Cargo.toml b/validium_mode_example/Cargo.toml similarity index 60% rename from zksync_full_stack/Cargo.toml rename to validium_mode_example/Cargo.toml index 29c7b1b22f0e..2ac5791c83e9 100644 --- a/zksync_full_stack/Cargo.toml +++ b/validium_mode_example/Cargo.toml @@ -1,12 +1,16 @@ [package] -name = "zksync_full_stack" +name = "validium_mode_example" version = "0.1.0" edition = "2021" +license = "MIT OR Apache-2.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] zksync-web3-rs = "*" +zksync_web3_decl = { path = "../core/lib/web3_decl" } +loadnext = { path = "../core/tests/loadnext" } ethers = "2.0.1" hex = "0.4.3" tokio = { version = "1", features = ["macros", "process"] } +colored = "2.0" diff --git a/validium_mode_example/Context.sol b/validium_mode_example/Context.sol new file mode 100644 index 000000000000..df4427b9ebda --- /dev/null +++ b/validium_mode_example/Context.sol @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: MIT + +pragma solidity >=0.8.0; + +/** + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract Context { + function _msgSender() internal view virtual returns (address) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes calldata) { + return msg.data; + } +} diff --git a/validium_mode_example/ERC20.abi b/validium_mode_example/ERC20.abi new file mode 100644 index 000000000000..b6148fda6515 --- /dev/null +++ b/validium_mode_example/ERC20.abi @@ -0,0 +1,416 @@ +[ + { + "inputs": [ + { + "internalType": "string", + "name": "name_", + "type": "string" + }, + { + "internalType": "string", + "name": "symbol_", + "type": "string" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "_afterTokenTransfer", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "_approve", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "_beforeTokenTransfer", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "_burn", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "_mint", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "_transfer", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "internalType": "address", + "name": "spender", + "type": "address" + } + ], + "name": "allowance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "approve", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "balanceOf", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "decimals", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "subtractedValue", + "type": "uint256" + } + ], + "name": "decreaseAllowance", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "addedValue", + "type": "uint256" + } + ], + "name": "increaseAllowance", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "name", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "symbol", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalSupply", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "transfer", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "transferFrom", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/validium_mode_example/ERC20.bin b/validium_mode_example/ERC20.bin new file mode 100644 index 000000000000..97fc9e067063 --- /dev/null +++ b/validium_mode_example/ERC20.bin @@ -0,0 +1 @@ +00010000000000020008000000000002000000000701034f00000000000703550000008001000039000000400010043f0000000001070019000000600110027000000152011001970000000102200190000000370000c13d000000040210008c0000038b0000413d000000000207043b000000e0022002700000015a0320009c000001230000a13d0000015b0320009c0000013a0000a13d0000015c0320009c000001660000a13d0000015d0320009c000001f00000613d0000015e0320009c000001b10000613d0000015f0220009c0000038b0000c13d0000000002000416000000000202004b0000038b0000c13d000000040110008a000000400110008c0000038b0000413d0000000401700370000000000101043b000001720210009c0000038b0000213d0000002402700370000000000302043b000001720230009c0000038b0000213d00000000001004350000000101000039000000200010043f0000004002000039000800000002001d0000000001000019000700000003001d054405240000040f00000007020000290000000000200435000000200010043f00000000010000190000000802000029000002a40000013d0000000002000416000000000202004b0000038b0000c13d0000015302100041000001540220009c000000430000213d000001850100004100000000001004350000004101000039000000040010043f000001860100004100000546000104300000009f021000390000015502200197000000400020043f0000001f0210018f0000000503100272000000520000613d00000000040000190000000505400210000000000657034f000000000606043b000000800550003900000000006504350000000104400039000000000534004b0000004a0000413d000000000402004b000000610000613d0000000503300210000000000437034f00000003022002100000008003300039000000000503043300000000052501cf000000000525022f000000000404043b0000010002200089000000000424022f00000000022401cf000000000252019f0000000000230435000000400210008c0000038b0000413d000000800500043d000001560250009c0000038b0000213d00000080021000390000009f03500039000000000323004b0000038b0000813d00000080045000390000000003040433000001560630009c0000003d0000213d0000003f06300039000000200900008a000000000696016f000000400a00043d00000000066a00190000000007a6004b00000000070000190000000107004039000001560860009c0000003d0000213d00000001077001900000003d0000c13d000000400060043f000000000b3a04360000000005350019000000a005500039000000000525004b0000038b0000213d000000000503004b0000008a0000613d000000000500001900000020055000390000000006a50019000000000745001900000000070704330000000000760435000000000635004b000000830000413d00000000033b00190000000000030435000000a00400043d000001560340009c0000038b0000213d0000001f034000390000015705000041000000000113004b000000000100001900000000010580190000015703300197000000000603004b0000000005008019000001570330009c000000000501c019000000000105004b0000038b0000c13d00000080034000390000000001030433000001560510009c0000003d0000213d0000003f05100039000000000595016f000000400800043d0000000005580019000000000685004b00000000060000190000000106004039000001560750009c0000003d0000213d00000001066001900000003d0000c13d000000400050043f0000000005180436000800000005001d0000000004140019000000a004400039000000000224004b0000038b0000213d00040000000b001d00070000000a001d000500000009001d000000000201004b000000be0000613d000000000200001900000020022000390000000004820019000000000532001900000000050504330000000000540435000000000412004b000000b70000413d0000000801100029000000000001043500000007010000290000000001010433000600000001001d000001560110009c0000003d0000213d000100000008001d0000000301000039000300000001001d000000000101041a000000010210019000000001011002700000007f0310018f000000000301c019000200000003001d0000001f0130008c00000000010000190000000101002039000000010110018f000000000112004b000002870000c13d0000000201000029000000200110008c000000f40000413d0000000301000029000000000010043500000152010000410000000002000414000001520320009c0000000002018019000000c00120021000000158011001c700008010020000390544053f0000040f00000001022001900000038b0000613d00000006030000290000001f023000390000000502200270000000200330008c0000000002004019000000000301043b00000002010000290000001f01100039000000050110027000000000011300190000000002230019000000000312004b000000f40000813d000000000002041b0000000102200039000000000312004b000000f00000413d00000006010000290000001f0110008c000003910000a13d0000000301000029000000000010043500000152010000410000000002000414000001520320009c0000000002018019000000c00120021000000158011001c700008010020000390544053f0000040f0000000102200190000000050200002900000007060000290000038b0000613d00000006032001800000002002000039000000000101043b000001130000613d0000002002000039000000000400001900000000056200190000000005050433000000000051041b000000200220003900000001011000390000002004400039000000000534004b0000010b0000413d000000060330006c0000011f0000813d00000006030000290000000303300210000000f80330018f000000010400008a000000000334022f000000000343013f00000007022000290000000002020433000000000232016f000000000021041b0000000601000029000000010110021000000001011001bf0000039e0000013d000001670320009c0000015a0000213d0000016d0320009c000001a40000213d000001700320009c000002070000613d000001710220009c0000038b0000c13d0000000002000416000000000202004b0000038b0000c13d000000040110008a000000400110008c0000038b0000413d0000000401700370000000000201043b000001720120009c0000038b0000213d0000002401700370000000000301043b0000000001000411054404ca0000040f000001fe0000013d000001620320009c000001ad0000213d000001650320009c000002200000613d000001660220009c0000038b0000c13d0000000002000416000000000202004b0000038b0000c13d000000040110008a000000400110008c0000038b0000413d0000000401700370000000000401043b000001720140009c0000038b0000213d0000002401700370000000000201043b000000000104004b000002ba0000c13d0000017801000041000000800010043f0000002001000039000000840010043f0000002101000039000000a40010043f0000018001000041000000c40010043f0000018101000041000000e40010043f00000182010000410000054600010430000001680320009c000001b60000213d0000016b0320009c000002380000613d0000016c0220009c0000038b0000c13d0000000002000416000000000202004b0000038b0000c13d0544042c0000040f054404460000040f000002900000013d000001600320009c000002780000613d000001610220009c0000038b0000c13d0000000002000416000000000202004b0000038b0000c13d000000040110008a000000400110008c0000038b0000413d0000000401700370000000000101043b000800000001001d000001720110009c0000038b0000213d0000002401700370000000000101043b000700000001001d0000000001000411000500000001001d00000000001004350000000101000039000600000001001d000000200010043f00000152030000410000000001000414000001520210009c0000000001038019000000c00110021000000175011001c700008010020000390544053f0000040f00000001022001900000038b0000613d000000000101043b00000008020000290000000000200435000000200010043f0000000001000414000001520210009c0000015201008041000000c00110021000000175011001c700008010020000390544053f0000040f00000001022001900000038b0000613d000000000101043b000000000101041a0000000703000029000000000231004b000003530000813d000000400100043d00000064021000390000017603000041000000000032043500000044021000390000017703000041000000000032043500000024021000390000002503000039000002d60000013d0000016e0320009c0000028b0000613d0000016f0120009c0000038b0000c13d0000000001000416000000000101004b0000038b0000c13d0000000201000039000002a50000013d000001630320009c000002960000613d000001640220009c0000038b0000c13d0000000002000416000000000202004b0000038b0000c13d0544042c0000040f000002900000013d000001690320009c000002a70000613d0000016a0220009c0000038b0000c13d0000000002000416000000000202004b0000038b0000c13d000000040110008a000000400110008c0000038b0000413d0000000401700370000000000101043b000800000001001d000001720110009c0000038b0000213d0000000001000411000500000001001d00000000001004350000000101000039000600000001001d000000200010043f00000152030000410000000001000414000001520210009c0000000001038019000000c00110021000000175011001c7000080100200003900070000000703530544053f0000040f000000070300035f00000001022001900000038b0000613d000000000101043b00000008020000290000000000200435000000200010043f0000002401300370000000000101043b000700000001001d0000000001000414000001520210009c0000015201008041000000c00110021000000175011001c700008010020000390544053f0000040f00000001022001900000038b0000613d000000000101043b000000000101041a0000000703100029000000000113004b000000000100001900000001010040390000000101100190000003540000613d000003000000013d0000000002000416000000000202004b0000038b0000c13d000000040110008a000000400110008c0000038b0000413d0000000401700370000000000201043b000001720120009c0000038b0000213d0000002401700370000000000301043b0000000001000411054404460000040f0000000101000039000000400200043d00000000001204350000015201000041000001520320009c0000000002018019000000400120021000000174011001c7000005450001042e0000000001000416000000000101004b0000038b0000c13d0000000303000039000000000203041a000000010420019000000001052002700000007f0650018f000000000605c0190000001f0560008c00000000050000190000000105002039000000000552013f0000000105500190000002870000c13d000000800060043f000000000404004b000002e20000c13d000001000300008a000000000232016f000000a00020043f000000000106004b000000c001000039000000a001006039000002f10000013d0000000002000416000000000202004b0000038b0000c13d000000040110008a000000400110008c0000038b0000413d0000000401700370000000000401043b000001720140009c0000038b0000213d0000002401700370000000000501043b000000000104004b000002f80000c13d0000017801000041000000800010043f0000002001000039000000840010043f0000001f01000039000000a40010043f0000018301000041000000c40010043f000001840100004100000546000104300000000002000416000000000202004b0000038b0000c13d000000040110008a000000600110008c0000038b0000413d0000000401700370000000000101043b000001720210009c0000038b0000213d0000002402700370000000000202043b000001720320009c0000038b0000213d0000004403700370000000000303043b000700000003001d000800000001001d054404460000040f000000080100002900000000001004350000000101000039000600000001001d000000200010043f00000152030000410000000001000414000001520210009c0000000001038019000000c00110021000000175011001c700008010020000390544053f0000040f00000001022001900000038b0000613d000000000101043b0000000002000411000500000002001d0000000000200435000000200010043f0000000001000414000001520210009c0000015201008041000000c00110021000000175011001c700008010020000390544053f0000040f000000080400002900000001022001900000038b0000613d000000000101043b000000000101041a0000000703000029000000000231004b0000038d0000813d000000400100043d00000064021000390000018703000041000000000032043500000044021000390000018803000041000000000032043500000024021000390000002803000039000002d60000013d0000000001000416000000000101004b0000038b0000c13d0000000403000039000000000203041a000000010420019000000001052002700000007f0650018f000000000605c0190000001f0560008c00000000050000190000000105002039000000000552013f0000000105500190000002b00000613d000001850100004100000000001004350000002201000039000000400000013d0000000002000416000000000202004b0000038b0000c13d0544042c0000040f054404ca0000040f0000015201000041000000400200043d000001520320009c00000000020180190000004001200210000005450001042e0000000002000416000000000202004b0000038b0000c13d000000040110008a000000200110008c0000038b0000413d0000000401700370000000000101043b000001720210009c0000038b0000213d0000000000100435000000200000043f00000040020000390000000001000019054405240000040f000000000101041a000002ad0000013d0000000001000416000000000101004b0000038b0000c13d0000000501000039000000000101041a000000ff0110018f000000800010043f0000017301000041000005450001042e000000800060043f000000000404004b000003040000c13d000001000300008a000000000232016f000000a00020043f000000000106004b000000c001000039000000a001006039000003130000013d000700000002001d0000000000400435000000200000043f00000152010000410000000002000414000001520320009c0000000002018019000000c00120021000000175011001c70000801002000039000800000004001d0544053f0000040f000000080300002900000001022001900000038b0000613d000000000101043b000000000201041a000000070120006c000003600000813d000000400100043d00000064021000390000017e03000041000000000032043500000044021000390000017f030000410000000000320435000000240210003900000022030000390000000000320435000001780200004100000000002104350000000402100039000000200300003900000000003204350000015202000041000001520310009c0000000001028019000000400110021000000179011001c700000546000104300000000000300435000000a001000039000000000206004b000003190000613d000001890200004100000000040000190000000003040019000000000402041a000000a005300039000000000045043500000001022000390000002004300039000000000564004b000002e80000413d000000c0013000390000001f01100039000000200200008a000000000121016f0000017b021000410000017c0220009c0000003d0000413d000003190000013d0000000201000039000000000301041a0000000002530019000000000332004b000000000300001900000001030040390000000103300190000003280000613d000001850100004100000000001004350000001101000039000000400000013d0000000000300435000000a001000039000000000206004b000003190000613d0000017a0200004100000000040000190000000003040019000000000402041a000000a005300039000000000045043500000001022000390000002004300039000000000564004b0000030a0000413d000000c0013000390000001f01100039000000200200008a000000000121016f0000017b021000410000017c0220009c0000003d0000413d000800000001001d000000400010043f0000008002000039054404160000040f000000080400002900000000014100490000015202000041000001520310009c0000000001028019000001520340009c000000000402801900000040024002100000006001100210000000000121019f000005450001042e000700000005001d000000000021041b0000000000400435000000200000043f00000152010000410000000002000414000001520320009c0000000002018019000000c00120021000000175011001c70000801002000039000800000004001d0544053f0000040f000000080600002900000001022001900000038b0000613d000000000101043b000000000301041a00000007040000290000000002430019000000000332004b000000000300001900000001030040390000000103300190000003000000c13d000000000021041b000000400100043d000000000041043500000152020000410000000003000414000001520430009c0000000003028019000001520410009c00000000010280190000004001100210000000c002300210000000000112019f00000158011001c70000800d0200003900000003030000390000017d040000410000000005000019000003880000013d000000000331004900000005010000290000000802000029054404ca0000040f000000400100043d000000060200002900000000002104350000015202000041000001520310009c0000000001028019000000400110021000000174011001c7000005450001042e000600000002001d0000000000300435000000200000043f00000152010000410000000002000414000001520320009c0000000002018019000000c00120021000000175011001c700008010020000390544053f0000040f000000080500002900000001022001900000038b0000613d00000007040000290000000602400069000000000101043b000000000021041b0000000201000039000000000201041a000000000342004b000003000000413d0000000002420049000000000021041b000000400100043d000000000041043500000152020000410000000003000414000001520430009c0000000003028019000001520410009c00000000010280190000004001100210000000c002300210000000000112019f00000158011001c70000800d0200003900000003030000390000017d0400004100000000060000190544053a0000040f0000000101200190000002900000c13d00000000010000190000054600010430000000000331004900000000010400190000000502000029000003560000013d000000060100006b0000000001000019000003960000613d0000000401000029000000000101043300000006040000290000000302400210000000010300008a000000000223022f000000000232013f000000000121016f0000000102400210000000000121019f0000000302000029000000000012041b00000001010000290000000001010433000700000001001d000001560110009c0000003d0000213d0000000401000039000600000001001d000000000101041a000000010210019000000001021002700000007f0320018f000000000302c019000400000003001d0000001f0230008c00000000020000190000000102002039000000000121013f0000000101100190000002870000c13d0000000401000029000000200110008c000003d30000413d0000000601000029000000000010043500000152010000410000000002000414000001520320009c0000000002018019000000c00120021000000158011001c700008010020000390544053f0000040f00000001022001900000038b0000613d00000007030000290000001f023000390000000502200270000000200330008c0000000002004019000000000301043b00000004010000290000001f01100039000000050110027000000000011300190000000002230019000000000312004b000003d30000813d000000000002041b0000000102200039000000000312004b000003cf0000413d00000007010000290000001f0110008c000004020000a13d0000000601000029000000000010043500000152010000410000000002000414000001520320009c0000000002018019000000c00120021000000158011001c700008010020000390544053f0000040f0000000102200190000000050200002900000001060000290000038b0000613d00000007032001800000002002000039000000000101043b000003f20000613d0000002002000039000000000400001900000000056200190000000005050433000000000051041b000000200220003900000001011000390000002004400039000000000534004b000003ea0000413d000000070330006c000003fe0000813d00000007030000290000000303300210000000f80330018f000000010400008a000000000334022f000000000343013f00000001022000290000000002020433000000000232016f000000000021041b0000000101000039000000070200002900000001022002100000040e0000013d000000070100006b0000000001000019000004070000613d0000000801000029000000000101043300000007040000290000000302400210000000010300008a000000000223022f000000000232013f000000000221016f0000000101400210000000000112019f0000000602000029000000000012041b0000002001000039000001000010044300000120000004430000015901000041000005450001042e00000020030000390000000004310436000000000302043300000000003404350000004001100039000000000403004b000004250000613d000000000400001900000000054100190000002004400039000000000624001900000000060604330000000000650435000000000534004b0000041e0000413d000000000231001900000000000204350000001f02300039000000200300008a000000000232016f0000000001210019000000000001042d000000040110008a00000157020000410000005f0310008c000000000300001900000000030220190000015701100197000000000401004b0000000002008019000001570110009c000000000203c019000000000102004b000004440000613d00000000030003670000000401300370000000000101043b000001720210009c000004440000213d0000002402300370000000000202043b000001720420009c000004440000213d0000004403300370000000000303043b000000000001042d00000000010000190000054600010430000400000000000200000172011001980000049b0000613d000400000003001d000201720020019c000004a50000613d000300000001001d0000000000100435000000200000043f00000152010000410000000002000414000001520320009c0000000002018019000000c00120021000000175011001c700008010020000390544053f0000040f0000000102200190000004990000613d000000000101043b000000000201041a000100000002001d000000040120006c000004af0000413d00000003010000290000000000100435000000200000043f00000152030000410000000001000414000001520210009c0000000001038019000000c00110021000000175011001c700008010020000390544053f0000040f0000000102200190000004990000613d0000000103000029000000040230006a000000000101043b000000000021041b000000020100002900000000001004350000000001000414000001520210009c0000015201008041000000c00110021000000175011001c700008010020000390544053f0000040f0000000102200190000004990000613d000000000101043b000000000301041a00000004040000290000000002430019000000000332004b000000000300001900000001030040390000000103300190000004c40000c13d000000000021041b000000400100043d000000000041043500000152020000410000000003000414000001520430009c0000000003028019000001520410009c00000000010280190000004001100210000000c002300210000000000112019f00000158011001c70000800d0200003900000003030000390000017d04000041000000030500002900000002060000290544053a0000040f0000000101200190000004990000613d000000000001042d00000000010000190000054600010430000000400100043d00000064021000390000018e03000041000000000032043500000044021000390000018f03000041000000000032043500000024021000390000002503000039000004b80000013d000000400100043d00000064021000390000018c03000041000000000032043500000044021000390000018d03000041000000000032043500000024021000390000002303000039000004b80000013d000000400100043d00000064021000390000018a03000041000000000032043500000044021000390000018b030000410000000000320435000000240210003900000026030000390000000000320435000001780200004100000000002104350000000402100039000000200300003900000000003204350000015202000041000001520310009c0000000001028019000000400110021000000179011001c70000054600010430000001850100004100000000001004350000001101000039000000040010043f0000018601000041000005460001043000030000000000020000017201100198000005050000613d000200000003001d000301720020019c0000050f0000613d000100000001001d00000000001004350000000101000039000000200010043f00000152030000410000000001000414000001520210009c0000000001038019000000c00110021000000175011001c700008010020000390544053f0000040f00000001022001900000000303000029000005030000613d000000000101043b0000000000300435000000200010043f0000000001000414000001520210009c0000015201008041000000c00110021000000175011001c700008010020000390544053f0000040f00000003060000290000000102200190000005030000613d000000000101043b0000000202000029000000000021041b000000400100043d000000000021043500000152020000410000000003000414000001520430009c0000000003028019000001520410009c00000000010280190000004001100210000000c002300210000000000112019f00000158011001c70000800d020000390000000303000039000001900400004100000001050000290544053a0000040f0000000101200190000005030000613d000000000001042d00000000010000190000054600010430000000400100043d00000064021000390000019303000041000000000032043500000044021000390000019403000041000000000032043500000024021000390000002403000039000005180000013d000000400100043d000000640210003900000191030000410000000000320435000000440210003900000192030000410000000000320435000000240210003900000022030000390000000000320435000001780200004100000000002104350000000402100039000000200300003900000000003204350000015202000041000001520310009c0000000001028019000000400110021000000179011001c700000546000104300000015203000041000001520410009c00000000010380190000004001100210000001520420009c00000000020380190000006002200210000000000112019f0000000002000414000001520420009c0000000002038019000000c002200210000000000112019f00000195011001c700008010020000390544053f0000040f0000000102200190000005380000613d000000000101043b000000000001042d000000000100001900000546000104300000053d002104210000000102000039000000000001042d0000000002000019000000000001042d00000542002104230000000102000039000000000001042d0000000002000019000000000001042d0000054400000432000005450001042e0000054600010430000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000009fffffffffffffffffffffffffffffffffffffffffffffffff000000000000007f00000000000000000000000000000000000000000000000000000001ffffffe0000000000000000000000000000000000000000000000000ffffffffffffffff800000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000200000000000000000000000000000000200000000000000000000000000000040000001000000000000000000000000000000000000000000000000000000000000000000000000004e6ec2460000000000000000000000000000000000000000000000000000000095d89b4000000000000000000000000000000000000000000000000000000000a9059cba00000000000000000000000000000000000000000000000000000000a9059cbb00000000000000000000000000000000000000000000000000000000cad3be8300000000000000000000000000000000000000000000000000000000dd62ed3e0000000000000000000000000000000000000000000000000000000095d89b4100000000000000000000000000000000000000000000000000000000a457c2d70000000000000000000000000000000000000000000000000000000070a082300000000000000000000000000000000000000000000000000000000070a08231000000000000000000000000000000000000000000000000000000008f811a1c000000000000000000000000000000000000000000000000000000004e6ec247000000000000000000000000000000000000000000000000000000006161eb180000000000000000000000000000000000000000000000000000000023b872dc00000000000000000000000000000000000000000000000000000000313ce56600000000000000000000000000000000000000000000000000000000313ce56700000000000000000000000000000000000000000000000000000000395093510000000000000000000000000000000000000000000000000000000023b872dd0000000000000000000000000000000000000000000000000000000030e0789e00000000000000000000000000000000000000000000000000000000104e81fe00000000000000000000000000000000000000000000000000000000104e81ff0000000000000000000000000000000000000000000000000000000018160ddd0000000000000000000000000000000000000000000000000000000006fdde0300000000000000000000000000000000000000000000000000000000095ea7b3000000000000000000000000ffffffffffffffffffffffffffffffffffffffff000000000000000000000000000000000000002000000080000000000000000000000000000000000000000000000000000000200000000000000000000000000200000000000000000000000000000000000040000000000000000000000000207a65726f00000000000000000000000000000000000000000000000000000045524332303a2064656372656173656420616c6c6f77616e63652062656c6f7708c379a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000840000000000000000000000008a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19bffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffffffffffffffffffffffffffffffffffff0000000000000080ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef636500000000000000000000000000000000000000000000000000000000000045524332303a206275726e20616d6f756e7420657863656564732062616c616e45524332303a206275726e2066726f6d20746865207a65726f206164647265737300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008400000080000000000000000045524332303a206d696e7420746f20746865207a65726f20616464726573730000000000000000000000000000000000000000640000008000000000000000004e487b710000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000240000000000000000000000006c6c6f77616e636500000000000000000000000000000000000000000000000045524332303a207472616e7366657220616d6f756e7420657863656564732061c2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b616c616e6365000000000000000000000000000000000000000000000000000045524332303a207472616e7366657220616d6f756e7420657863656564732062657373000000000000000000000000000000000000000000000000000000000045524332303a207472616e7366657220746f20746865207a65726f2061646472647265737300000000000000000000000000000000000000000000000000000045524332303a207472616e736665722066726f6d20746865207a65726f2061648c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925737300000000000000000000000000000000000000000000000000000000000045524332303a20617070726f766520746f20746865207a65726f206164647265726573730000000000000000000000000000000000000000000000000000000045524332303a20617070726f76652066726f6d20746865207a65726f206164640200000000000000000000000000000000000000000000000000000000000000f7b6a0ef06930cfb358d73424bfb79061f7dc9a44ad5004b52f294ee14c39e12 \ No newline at end of file diff --git a/validium_mode_example/ERC20.sol b/validium_mode_example/ERC20.sol new file mode 100644 index 000000000000..f3da1db61a4b --- /dev/null +++ b/validium_mode_example/ERC20.sol @@ -0,0 +1,368 @@ +// SPDX-License-Identifier: MIT + +pragma solidity >=0.8.0; + +import "./IERC20.sol"; +import "./IERC20Metadata.sol"; +import "./Context.sol"; + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin Contracts guidelines: functions revert + * instead returning `false` on failure. This behavior is nonetheless + * conventional and does not conflict with the expectations of ERC20 + * applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20 is Context, IERC20, IERC20Metadata { + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}. + * + * The default value of {decimals} is 18. To select a different value for + * {decimals} you should overload it. + * + * All two of these values are immutable: they can only be set once during + * construction. + */ + constructor(string memory name_, string memory symbol_) { + _name = name_; + _symbol = symbol_; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view virtual override returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view virtual override returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5.05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless this function is + * overridden; + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view virtual override returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view virtual override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view virtual override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + + uint256 currentAllowance = _allowances[sender][_msgSender()]; + require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); + unchecked { + _approve(sender, _msgSender(), currentAllowance - amount); + } + + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + uint256 currentAllowance = _allowances[_msgSender()][spender]; + require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); + unchecked { + _approve(_msgSender(), spender, currentAllowance - subtractedValue); + } + + return true; + } + + /** + * @dev Moves `amount` of tokens from `sender` to `recipient`. + * + * This internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) public /*internal*/ virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + uint256 senderBalance = _balances[sender]; + require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); + unchecked { + _balances[sender] = senderBalance - amount; + } + _balances[recipient] += amount; + + emit Transfer(sender, recipient, amount); + + _afterTokenTransfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + */ + function _mint(address account, uint256 amount) public /*internal*/ virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply += amount; + _balances[account] += amount; + emit Transfer(address(0), account, amount); + + _afterTokenTransfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) public /*internal*/ virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + uint256 accountBalance = _balances[account]; + require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); + unchecked { + _balances[account] = accountBalance - amount; + } + _totalSupply -= amount; + + emit Transfer(account, address(0), amount); + + _afterTokenTransfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) public /*internal*/ virtual { + require(owner != address(0), "ERC20: approve from the zero address"); + require(spender != address(0), "ERC20: approve to the zero address"); + + _allowances[owner][spender] = amount; + emit Approval(owner, spender, amount); + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) public /*internal*/ virtual {} + + /** + * @dev Hook that is called after any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * has been transferred to `to`. + * - when `from` is zero, `amount` tokens have been minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens have been burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _afterTokenTransfer( + address from, + address to, + uint256 amount + ) public /*internal*/ virtual {} + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } +} diff --git a/zksync_full_stack/Greeter.abi b/validium_mode_example/Greeter.abi similarity index 100% rename from zksync_full_stack/Greeter.abi rename to validium_mode_example/Greeter.abi diff --git a/zksync_full_stack/Greeter.bin b/validium_mode_example/Greeter.bin similarity index 100% rename from zksync_full_stack/Greeter.bin rename to validium_mode_example/Greeter.bin diff --git a/zksync_full_stack/Greeter.sol b/validium_mode_example/Greeter.sol similarity index 100% rename from zksync_full_stack/Greeter.sol rename to validium_mode_example/Greeter.sol diff --git a/validium_mode_example/IERC20.sol b/validium_mode_example/IERC20.sol new file mode 100644 index 000000000000..2693a9f9ba15 --- /dev/null +++ b/validium_mode_example/IERC20.sol @@ -0,0 +1,81 @@ +// SPDX-License-Identifier: MIT + +pragma solidity >=0.8.0; + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20 { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} diff --git a/validium_mode_example/IERC20Metadata.sol b/validium_mode_example/IERC20Metadata.sol new file mode 100644 index 000000000000..1846275af4b3 --- /dev/null +++ b/validium_mode_example/IERC20Metadata.sol @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: MIT + +pragma solidity >=0.8.0; + +import "./IERC20.sol"; + +/** + * @dev Interface for the optional metadata functions from the ERC20 standard. + * + * _Available since v4.1._ + */ +interface IERC20Metadata is IERC20 { + /** + * @dev Returns the name of the token. + */ + function name() external view returns (string memory); + + /** + * @dev Returns the symbol of the token. + */ + function symbol() external view returns (string memory); + + /** + * @dev Returns the decimals places of the token. + */ + function decimals() external view returns (uint8); +} diff --git a/validium_mode_example/README.md b/validium_mode_example/README.md new file mode 100644 index 000000000000..55e9cac9e952 --- /dev/null +++ b/validium_mode_example/README.md @@ -0,0 +1,72 @@ +## Validium example + +In order to start the node as a validium and run the example follow the next steps. + +### Run the server + +To run this example we need to run the server in validium mode. In the `zksync-era` directory, you can run the following +command: + +```sh +zk && zk clean --all && zk init --validium-mode && zk server +``` + +> [!IMPORTANT] Make sure that the flag `--validium-mode` is present when initilizing the server. + +This will set up the Ethereum node with the validium contracts, and also define an `env` var which the server will pick +up in order to run as a validium node. + +### Run the example + +In this example we're going to run some transactions. + +Once the server is running, run this command in other terminal: + +```sh +cargo run --release --bin zksync_full_stack +``` + +This test does the following: + +- Inits a wallet +- Deposits some funds into the wallet +- Deploys a sample ERC20 contract +- Query the contract for the token name and symbol +- Mint 100000 tokens into the address `CD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826` +- Transfer 1000 tokens from `CD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826` to `bBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB` + +### Logs and prints + +- For each transaction, we use the rpc client to query the transaction details and print them out. The following fields + are printed: + - `Transaction hash`: The hash of the transaction + - `Transaction gas used`: The gas used to perform this transaction. + - `L2 fee`: The total cost of this transaction. + +### Example output + +You will have an output similar to this one: + +``` +Deposit transaction hash: 0x77f378f1857ad7ff8c1041d2ce0f7f167587a90a19f9fd923c9ea91fbdf37650 +Deploy +Contract address: 0x4b5df730c2e6b28e17013a1485e5d9bc41efe021 +Transaction hash 0xe08786e302027040056555bdba6e0462fdee56768d982485d80f732043013bb5 +Transaction gas used 161163 +L2 fee: 40290750000000 + +Mint +Transaction hash 0x2f5b565959c8c5ffe320a364df27f4de451ed93ee6344a838f2212397da7fe5f +Transaction gas used 124046 +L2 fee: 31011500000000 +L1 max fee per gas: 1200000011 + +Transfer 1000 +Transaction hash 0x7cfadf74a5fa571ed9e2f1a115edc62f8db913d61d387177b7b07e2cb270af75 +Transaction gas used 125466 +L2 fee: 31366500000000 +L1 max fee per gas: 1000000010 +``` + +> [!NOTE] You can observe how the diferent fields evolve depending on the operation. The `transaction hash` is a +> changing field. diff --git a/validium_mode_example/src/main.rs b/validium_mode_example/src/main.rs new file mode 100644 index 000000000000..7c82fbf28206 --- /dev/null +++ b/validium_mode_example/src/main.rs @@ -0,0 +1,275 @@ +use std::{str::FromStr, time::Duration}; + +use colored::Colorize; +use ethers::{abi::Abi, providers::Http, utils::parse_units}; +use loadnext::config::LoadtestConfig; +use tokio::time::sleep; +use zksync_web3_decl::{ + jsonrpsee::http_client::HttpClientBuilder, + namespaces::{EthNamespaceClient, ZksNamespaceClient}, +}; +use zksync_web3_rs::{ + eip712::Eip712TransactionRequest, + providers::{Middleware, Provider}, + signers::{LocalWallet, Signer}, + zks_provider::ZKSProvider, + zks_wallet::{DeployRequest, DepositRequest}, + ZKSWallet, +}; + +static ERA_PROVIDER_URL: &str = "http://127.0.0.1:3050"; +static PRIVATE_KEY: &str = "7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110"; + +static CONTRACT_BIN: &str = include_str!("../ERC20.bin"); +static CONTRACT_ABI: &str = include_str!("../ERC20.abi"); + +static L1_URL: &str = "http://localhost:8545"; + +#[tokio::main(flavor = "current_thread")] +async fn main() { + let l1_provider = + Provider::::try_from(L1_URL).expect("Could not instantiate L1 Provider"); + let zk_wallet = { + let era_provider = Provider::try_from(ERA_PROVIDER_URL).unwrap(); + + let chain_id = era_provider.get_chainid().await.unwrap(); + let l2_wallet = LocalWallet::from_str(PRIVATE_KEY) + .unwrap() + .with_chain_id(chain_id.as_u64()); + ZKSWallet::new( + l2_wallet, + None, + Some(era_provider.clone()), + Some(l1_provider.clone()), + ) + .unwrap() + }; + + let config = LoadtestConfig::from_env() + .expect("Config parameters should be loaded from env or from default values"); + + let l1_rpc_client = HttpClientBuilder::default() + .build(config.l1_rpc_address) + .unwrap(); + let l2_rpc_client = HttpClientBuilder::default() + .build(config.l2_rpc_address) + .unwrap(); + + let deposit_transaction_hash = { + let amount = parse_units("11", "ether").unwrap(); + let request = DepositRequest::new(amount.into()); + zk_wallet + .deposit(&request) + .await + .expect("Failed to perform deposit transaction") + }; + println!(); + println!("Deposit transaction hash: {:?}", deposit_transaction_hash); + + // Deploy contract: + let contract_address = { + // Read both files from disk: + let abi = Abi::load(CONTRACT_ABI.as_bytes()).unwrap(); + let contract_bin = hex::decode(CONTRACT_BIN).unwrap().to_vec(); + + // DeployRequest sets the parameters for the constructor call and the deployment transaction. + let request = DeployRequest::with( + abi, + contract_bin, + vec!["ToniToken".to_owned(), "teth".to_owned()], + ) + .from(zk_wallet.l2_address()); + + // Send the deployment transaction and wait until we receive the contract address. + //let address = zk_wallet.deploy(&request).await.unwrap(); + + let eip712_request: Eip712TransactionRequest = request.clone().try_into().unwrap(); + println!("{}", "Deploy".bright_magenta()); + + let transaction_receipt = zk_wallet + .get_era_provider() + .unwrap() + .clone() + .send_transaction_eip712(&zk_wallet.l2_wallet, eip712_request) + .await + .unwrap() + .await + .unwrap() + .unwrap(); + + // println!("{:#?}", transaction_receipt); + let address = transaction_receipt.contract_address.unwrap(); + println!("Contract address: {:#?}", address); + + let transaction_hash_deploy = transaction_receipt.transaction_hash; + let transaction_hash_formatted_deploy = + format!("{:#?}", transaction_receipt.transaction_hash); + println!("Transaction hash {}", transaction_hash_formatted_deploy); + let transaction_gas_used_formatted_deploy = + format!("{:#?}", transaction_receipt.gas_used.unwrap()); + println!( + "Transaction gas used {}", + transaction_gas_used_formatted_deploy.cyan() + ); + let l2_transaction_deploy = { + loop { + let l2_transaction = l2_rpc_client + .get_transaction_details(transaction_hash_deploy) + .await + .unwrap() + .unwrap(); + + if l2_transaction.eth_commit_tx_hash.is_some() { + break l2_transaction.clone(); + } + + sleep(Duration::from_secs(1)).await; + } + }; + + let l2_tx_fee_formatted_deploy = format!("{:#?}", l2_transaction_deploy.fee); + println!("L2 fee: {}", l2_tx_fee_formatted_deploy.green()); + + address + }; + println!(); + + println!("{}", "Mint".bright_magenta()); + let receipt_mint = zk_wallet + .get_era_provider() + .unwrap() + .clone() + .send_eip712( + &zk_wallet.l2_wallet, + contract_address, + "_mint(address, uint256)", + Some( + [ + "CD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826".into(), + "100000".into(), + ] + .into(), + ), + None, + ) + .await + .unwrap() + .await + .unwrap() + .unwrap(); + + let transaction_hash_mint = receipt_mint.transaction_hash; + let transaction_hash_formatted_mint = format!("{:#?}", receipt_mint.transaction_hash); + println!("Transaction hash {}", transaction_hash_formatted_mint); + let transaction_gas_used_formatted_mint = format!("{:#?}", receipt_mint.gas_used.unwrap()); + println!( + "Transaction gas used {}", + transaction_gas_used_formatted_mint.cyan() + ); + let l2_transaction_mint = { + // println!("{}", "Getting l2 transaction details with rpc..."); + loop { + let l2_transaction = l2_rpc_client + .get_transaction_details(transaction_hash_mint) + .await + .unwrap() + .unwrap(); + + if l2_transaction.eth_commit_tx_hash.is_some() { + break l2_transaction.clone(); + } + + sleep(Duration::from_secs(1)).await; // Adjust the duration as needed + } + }; + + let l2_tx_fee_formatted_mint = format!("{:#?}", l2_transaction_mint.fee); + println!("L2 fee: {}", l2_tx_fee_formatted_mint.green()); + + let l1_transaction_transfer = l1_rpc_client + .get_transaction_by_hash(l2_transaction_mint.eth_commit_tx_hash.unwrap()) + .await + .unwrap() + .unwrap(); + + let l1_max_fee_per_gas_mint = l1_transaction_transfer.max_fee_per_gas.unwrap(); + let l1_max_fee_per_gas_formatted_mint = format!("{:#?}", l1_max_fee_per_gas_mint); + println!( + "L1 max fee per gas: {}", + l1_max_fee_per_gas_formatted_mint.cyan() + ); + println!(); + + let values: Vec<&str> = vec!["1000"]; + + for &value in &values { + println!("Transfer {}", value.bright_magenta()); + let receipt_transfer = zk_wallet + .get_era_provider() + .unwrap() + .clone() + .send_eip712( + &zk_wallet.l2_wallet, + contract_address, + "_transfer(address, address, uint256)", + Some( + [ + "CD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826".into(), + "bBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB".into(), + value.into(), + ] + .into(), + ), + None, + ) + .await + .unwrap() + .await + .unwrap() + .unwrap(); + + let transaction_hash_transfer = receipt_transfer.transaction_hash; + let transaction_hash_formatted_transfer = + format!("{:#?}", receipt_transfer.transaction_hash); + println!("Transaction hash {}", transaction_hash_formatted_transfer); + let transaction_gas_used_formatted_transfer = + format!("{:#?}", receipt_transfer.gas_used.unwrap()); + println!( + "Transaction gas used {}", + transaction_gas_used_formatted_transfer.cyan() + ); + let l2_transaction_transfer = { + // println!("{}", "Getting l2 transaction details with rpc..."); + loop { + let l2_transaction = l2_rpc_client + .get_transaction_details(transaction_hash_transfer) + .await + .unwrap() + .unwrap(); + + if l2_transaction.eth_commit_tx_hash.is_some() { + break l2_transaction.clone(); + } + + sleep(Duration::from_secs(1)).await; // Adjust the duration as needed + } + }; + + let l2_tx_fee_formatted_transfer = format!("{:#?}", l2_transaction_transfer.fee); + println!("L2 fee: {}", l2_tx_fee_formatted_transfer.green()); + + let l1_transaction_transfer = l1_rpc_client + .get_transaction_by_hash(l2_transaction_transfer.eth_commit_tx_hash.unwrap()) + .await + .unwrap() + .unwrap(); + + let l1_max_fee_per_gas_transfer = l1_transaction_transfer.max_fee_per_gas.unwrap(); + let l1_max_fee_per_gas_formatted_transfer = format!("{:#?}", l1_max_fee_per_gas_transfer); + println!( + "L1 max fee per gas: {}", + l1_max_fee_per_gas_formatted_transfer.cyan() + ); + println!(); + } +} diff --git a/zksync_full_stack/src/main.rs b/zksync_full_stack/src/main.rs deleted file mode 100644 index f6deb5d9e81f..000000000000 --- a/zksync_full_stack/src/main.rs +++ /dev/null @@ -1,116 +0,0 @@ -use std::str::FromStr; - -use ethers::{abi::Abi, providers::Http, utils::parse_units}; -use zksync_web3_rs::{ - providers::{Middleware, Provider}, - signers::{LocalWallet, Signer}, - zks_provider::ZKSProvider, - zks_wallet::{CallRequest, DeployRequest, DepositRequest}, - ZKSWallet, -}; - -static ERA_PROVIDER_URL: &str = "http://127.0.0.1:3050"; -static PRIVATE_KEY: &str = "7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110"; - -static CONTRACT_BIN: &str = include_str!("../Greeter.bin"); -static CONTRACT_ABI: &str = include_str!("../Greeter.abi"); - -static L1_URL: &str = "http://localhost:8545"; - -#[tokio::main(flavor = "current_thread")] -async fn main() { - let l1_provider = - Provider::::try_from(L1_URL).expect("Could not instantiate L1 Provider"); - let zk_wallet = { - let era_provider = Provider::try_from(ERA_PROVIDER_URL).unwrap(); - - let chain_id = era_provider.get_chainid().await.unwrap(); - let l2_wallet = LocalWallet::from_str(PRIVATE_KEY) - .unwrap() - .with_chain_id(chain_id.as_u64()); - ZKSWallet::new( - l2_wallet, - None, - Some(era_provider.clone()), - Some(l1_provider.clone()), - ) - .unwrap() - }; - - let deposit_transaction_hash = { - let amount = parse_units("11", "ether").unwrap(); - let request = DepositRequest::new(amount.into()); - zk_wallet - .deposit(&request) - .await - .expect("Failed to perform deposit transaction") - }; - - println!("Deposit transaction hash: {:?}", deposit_transaction_hash); - - // Deploy contract: - let contract_address = { - // Read both files from disk: - let abi = Abi::load(CONTRACT_ABI.as_bytes()).unwrap(); - let contract_bin = hex::decode(CONTRACT_BIN).unwrap().to_vec(); - - // DeployRequest sets the parameters for the constructor call and the deployment transaction. - let request = DeployRequest::with(abi, contract_bin, vec!["Hey".to_owned()]) - .from(zk_wallet.l2_address()); - - // Send the deployment transaction and wait until we receive the contract address. - let address = zk_wallet.deploy(&request).await.unwrap(); - - println!("Contract address: {:#?}", address); - - address - }; - - // Call the greet view method: - { - let era_provider = zk_wallet.get_era_provider().unwrap(); - let call_request = CallRequest::new(contract_address, "greet()(string)".to_owned()); - - let greet = ZKSProvider::call(era_provider.as_ref(), &call_request) - .await - .unwrap(); - - println!("greet: {}", greet[0]); - } - - // Perform a signed transaction calling the setGreeting method - { - let receipt = zk_wallet - .get_era_provider() - .unwrap() - .clone() - .send_eip712( - &zk_wallet.l2_wallet, - contract_address, - "setGreeting(string)", - Some(["Hello".into()].into()), - None, - ) - .await - .unwrap() - .await - .unwrap() - .unwrap(); - - println!( - "setGreeting transaction hash {:#?}", - receipt.transaction_hash - ); - }; - - { - let era_provider = zk_wallet.get_era_provider().unwrap(); - let call_request = CallRequest::new(contract_address, "greet()(string)".to_owned()); - - let greet = ZKSProvider::call(era_provider.as_ref(), &call_request) - .await - .unwrap(); - - println!("greet: {}", greet[0]); - } -}