Skip to content

Commit

Permalink
supplementary mods for block proposing
Browse files Browse the repository at this point in the history
  • Loading branch information
Keszey Dániel authored and Keszey Dániel committed Aug 15, 2024
1 parent 6451b5d commit 79b9ff5
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 7 deletions.
8 changes: 6 additions & 2 deletions packages/protocol/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# build/Makefile

.PHONY: install
.PHONY: install propose

install:
./scripts/setup_deps.sh

propose:
./scripts/propose_block.sh
@if [ -z "$(number)" ]; then \
echo "Error: 'number' parameter is required. Usage: make propose number=1"; \
exit 1; \
fi
./scripts/propose_block.sh $(number)
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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";
Expand Down
76 changes: 76 additions & 0 deletions packages/protocol/scripts/L2_txn_simulation/ProposeBlock2.s.sol
Original file line number Diff line number Diff line change
@@ -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;
}
}
19 changes: 16 additions & 3 deletions packages/protocol/scripts/propose_block.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <number>"
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)

Expand All @@ -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."

0 comments on commit 79b9ff5

Please sign in to comment.