From 79b9ff5411ac7026de3df6e45bfaa9d392055eb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Keszey=20D=C3=A1niel?= Date: Thu, 15 Aug 2024 11:48:49 +0200 Subject: [PATCH] supplementary mods for block proposing --- packages/protocol/Makefile | 8 +- ...ProposeBlock.s.sol => ProposeBlock1.s.sol} | 4 +- .../L2_txn_simulation/ProposeBlock2.s.sol | 76 +++++++++++++++++++ packages/protocol/scripts/propose_block.sh | 19 ++++- 4 files changed, 100 insertions(+), 7 deletions(-) rename packages/protocol/scripts/L2_txn_simulation/{ProposeBlock.s.sol => ProposeBlock1.s.sol} (98%) create mode 100644 packages/protocol/scripts/L2_txn_simulation/ProposeBlock2.s.sol diff --git a/packages/protocol/Makefile b/packages/protocol/Makefile index 4c267eea37eb..ff7d29957b78 100644 --- a/packages/protocol/Makefile +++ b/packages/protocol/Makefile @@ -1,9 +1,13 @@ # build/Makefile -.PHONY: install +.PHONY: install propose install: ./scripts/setup_deps.sh propose: - ./scripts/propose_block.sh \ No newline at end of file + @if [ -z "$(number)" ]; then \ + echo "Error: 'number' parameter is required. Usage: make propose number=1"; \ + exit 1; \ + fi + ./scripts/propose_block.sh $(number) \ No newline at end of file diff --git a/packages/protocol/scripts/L2_txn_simulation/ProposeBlock.s.sol b/packages/protocol/scripts/L2_txn_simulation/ProposeBlock1.s.sol similarity index 98% rename from packages/protocol/scripts/L2_txn_simulation/ProposeBlock.s.sol rename to packages/protocol/scripts/L2_txn_simulation/ProposeBlock1.s.sol index 61328c80c9fa..6b8d2d5f2422 100644 --- a/packages/protocol/scripts/L2_txn_simulation/ProposeBlock.s.sol +++ b/packages/protocol/scripts/L2_txn_simulation/ProposeBlock1.s.sol @@ -13,7 +13,7 @@ import "../../contracts/L1/TaikoL1.sol"; contract ProposeBlock is Script { address public taikoL1Address = 0x9fCF7D13d10dEdF17d0f24C62f0cf4ED462f65b7;//address(0);// TaikoL1 proxy address -> Get from the deployment - address sender = 0x8943545177806ED17B9F23F0a21ee5948eCaa776; // With pre-generated eth + address sender = 0x2c57d1CFC6d5f8E4182a56b4cf75421472eBAEa4; // With pre-generated eth function run() external { @@ -22,7 +22,7 @@ contract ProposeBlock is Script { vm.startBroadcast(); bytes[] memory txLists = new bytes[](1); - // The L2 chainId with which i encoded the TXNs were 167011 + // The L2 chainId with which i encoded the TXNs were 167010 // THe nonce was 0 bytes memory firstAddressSendingNonce0 = hex"02f87683028c6380843b9aca00847735940083030d4094f93ee4cf8c6c40b329b0c0626f28333c132cf24188016345785d8a000080c080a08f0f52d943504cecea0d6ce317c2fde8b0c27b1e449d85fcf98ccd2f50ac804ba04d5d56356518c1de0c1ece644a8a2fe64e6cc136cd8db0a21a21f72c167353c6"; bytes memory secondAddressSendingNonce0 = hex"02f87683028c6380843b9aca00847735940083030d4094f93ee4cf8c6c40b329b0c0626f28333c132cf24188016345785d8a000080c080a0622e7060e09afd2100784bdc88ebb838729128bb6eb40f8b7f458430d56dafd4a006fe5d1a466788f941020a2278860c3f2642e44108c666ecd25b30d1b2f7a420"; diff --git a/packages/protocol/scripts/L2_txn_simulation/ProposeBlock2.s.sol b/packages/protocol/scripts/L2_txn_simulation/ProposeBlock2.s.sol new file mode 100644 index 000000000000..1795f52094c4 --- /dev/null +++ b/packages/protocol/scripts/L2_txn_simulation/ProposeBlock2.s.sol @@ -0,0 +1,76 @@ +// SPDX-License-Identifier: MIT +// _____ _ _ _ _ +// |_ _|_ _(_) |_____ | | __ _| |__ ___ +// | |/ _` | | / / _ \ | |__/ _` | '_ (_-< +// |_|\__,_|_|_\_\___/ |____\__,_|_.__/__/ + +pragma solidity ^0.8.20; + +import "forge-std/Script.sol"; +import "forge-std/console2.sol"; + +import "../../contracts/L1/TaikoL1.sol"; + +contract ProposeBlock is Script { + address public taikoL1Address = 0x9fCF7D13d10dEdF17d0f24C62f0cf4ED462f65b7;//address(0);// TaikoL1 proxy address -> Get from the deployment + address sender = 0x2c57d1CFC6d5f8E4182a56b4cf75421472eBAEa4; // With pre-generated eth + + function run() external { + console2.log("Second batch"); + require(taikoL1Address != address(0), "based operator not set"); + + vm.startBroadcast(); + + bytes[] memory txLists = new bytes[](1); + // The L2 chainId with which i encoded the TXNs were 167010 + // THe nonce was 0 + bytes memory firstAddressSendingNonce0 = hex"02f87683028c6280843b9aca00847735940083030d4094f93ee4cf8c6c40b329b0c0626f28333c132cf241880de0b6b3a764000080c080a0d654805ce11de0ebc3882d0210f7d4df27cb65e8f1441f742814502c32fac90ca045902b6d5cd810b78ac4005d78b21ffa3fc02202f70af2b66acc2178357d5042"; + + // The outcome of the above is the rlp encoded list (not concatenated but RLP encoded with: https://toolkit.abdk.consulting/ethereum#key-to-address,rlp) + txLists[0] = hex"f87bb87902f87683028c6280843b9aca00847735940083030d4094f93ee4cf8c6c40b329b0c0626f28333c132cf241880de0b6b3a764000080c080a0d654805ce11de0ebc3882d0210f7d4df27cb65e8f1441f742814502c32fac90ca045902b6d5cd810b78ac4005d78b21ffa3fc02202f70af2b66acc2178357d5042"; + + bytes32 txListHash = keccak256(txLists[0]); //Since we not using Blobs, we need this + + // MetaData related + bytes[] memory metasEncoded = new bytes[](1); + TaikoData.BlockMetadata memory meta; + console2.log(txLists[0].length); + + meta = createBlockMetaDataForFirstBlockDebug(sender, 2, uint64(block.timestamp), uint24(txLists[0].length), txListHash); + + metasEncoded[0] = abi.encode(meta); + + TaikoL1(taikoL1Address).proposeBlock{value: 0.1 ether }(metasEncoded, txLists); + + vm.stopBroadcast(); + } + + function createBlockMetaDataForFirstBlockDebug( + address coinbase, + uint64 l2BlockNumber, + uint64 unixTimestamp, + uint24 txListByteSize, + bytes32 txListHash + ) + internal + returns (TaikoData.BlockMetadata memory meta) + { + meta.blockHash = 0xab80a9c4daa571aa308e967c9a6b4bf21ba8842d95d73d28be112b6fe0618e7c; // Randomly set it to smth + + //TaikoData.Block memory parentBlock = L1.getBlock(l2BlockNumber - 1); + meta.parentMetaHash = 0x0000000000000000000000000000000000000000000000000000000000000000; // This is the genesis block's metaHash + meta.parentBlockHash = 0xdf90a9c4daa571aa308e967c9a6b4bf21ba8842d95d73d28be112b6fe0618e8c; // This is the genesis block's blockhash + meta.l1Hash = blockhash(40); //L1 private network's L1 blockheight, submit this block between 40 and 40+128 blcok of L1. + meta.difficulty = block.prevrandao; + meta.blobHash = txListHash; + meta.coinbase = coinbase; + meta.l2BlockNumber = l2BlockNumber; + meta.gasLimit = 15_000_000; + meta.l1StateBlockNumber = uint32(40); // Submit this block between 40 and 40+128 block of L1. + meta.timestamp = unixTimestamp; + + meta.txListByteOffset = 0; + meta.txListByteSize = txListByteSize; // Corresponding txn list byte size + meta.blobUsed = false; + } +} diff --git a/packages/protocol/scripts/propose_block.sh b/packages/protocol/scripts/propose_block.sh index 1f27608c8579..0c10357076ff 100755 --- a/packages/protocol/scripts/propose_block.sh +++ b/packages/protocol/scripts/propose_block.sh @@ -3,6 +3,21 @@ # Run the setup_deps.sh script to ensure dependencies are set up #./scripts/setup_deps.sh +# Check if a number parameter was provided +if [ -z "$1" ]; then + echo "Error: No number parameter provided. Usage: ./propose_block.sh " + exit 1 +fi + +# Construct the script filename +SCRIPT_FILE="ProposeBlock$1.s.sol" + +# Check if the constructed filename exists +if [ ! -f "scripts/L2_txn_simulation/$SCRIPT_FILE" ]; then + echo "Error: File scripts/L2_txn_simulation/$SCRIPT_FILE does not exist." + exit 1 +fi + # Read the RPC port from temporary file RPC_PORT=$(cat /tmp/kurtosis_rpc_port) @@ -21,9 +36,7 @@ if [ -z "$PRIVATE_KEY" ]; then fi # Run the forge foundry script using the extracted RPC port and PRIVATE_KEY -FORGE_COMMAND="forge script --rpc-url http://127.0.0.1:$RPC_PORT scripts/L2_txn_simulation/ProposeBlock.s.sol -vvvv --broadcast --private-key $PRIVATE_KEY --legacy" - +FORGE_COMMAND="forge script --rpc-url http://127.0.0.1:$RPC_PORT scripts/L2_txn_simulation/$SCRIPT_FILE -vvvv --broadcast --private-key $PRIVATE_KEY --legacy" echo "Running forge foundry script..." eval $FORGE_COMMAND - echo "Forge script execution completed."