எழுத்து அளவு
Init code hash என்பது ஒப்பந்தத்தின் பைட்கோட்டின் keccak256 ஹாஷ் ஆகும்.
Init Code இன் பயன்பாடு
Init code hash தேவைப்படுகிறது "முகவரி கணக்கீடு init code-ஐ ஹாஷ் செய்வதைப் பொறுத்தது என்பதால். Init code என்பது இயக்கப்படும்போது, நிலையில் வைக்கப்படும் runtime bytecode-ஐ உருவாக்கும் குறியீடாகும், மேலும் இது பொதுவாக உயர்-நிலை மொழிகளால் 'constructor'-ஐ செயல்படுத்தப் பயன்படுகிறது."
"EIP-1014: Skinny CREATE2," Ethereum Improvement Proposals, no. 1014, April 2018. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-1014.
Init Code இன் பயன்பாடு
Init code இன் முதன்மை பயன்பாடு முகவரிகளை மைனிங் செய்வதற்காகும். CREATE2 மற்றும் ஒரு ஒப்பந்தத்தின் init code-ஐ எவ்வாறு பயன்படுத்தி ஒப்பந்த வரிசைப்படுத்தலுக்கு மிகவும் திறமையான முகவரிகளை 'மைன்' செய்யலாம் என்பதற்கான எடுத்துக்காட்டை https://github.com/0age/create2crunch இல் பார்க்கலாம்.
உங்களுக்காக code init hash-ஐ உருவாக்க forge-ஐப் பயன்படுத்தும் ஒரு எளிய bash ஸ்கிரிப்ட் இங்கே:
https://github.com/sambacha/foundry-scripts/tree/master/scripts/deploy
ஸ்கிரிப்ட்
#!/usr/bin/env bash
# Function to exit on error with a message
exit_on_error() {
echo "Error: $1"
exit 1
}
# Function to display usage information
usage() {
echo "Usage: $0 [-v]"
echo " : Path to the Solidity contract file"
echo " : Name of the Solidity contract"
echo " -v : Enable verbose output (optional)"
exit 1
}
# Check if foundry is installed
if ! command -v forge &> /dev/null; then
exit_on_error "Foundry is not installed. Please install it first."
fi
# Check if correct number of arguments is provided
if [ "$#" -lt 2 ] || [ "$#" -gt 3 ]; then
usage
fi
# Variables from arguments
CONTRACT_PATH=$1
CONTRACT_NAME=$2
VERBOSE=false
# Check if verbose option is enabled
if [ "$#" -eq 3 ] && [ "$3" == "-v" ]; then
VERBOSE=true
fi
# Validate contract path
if [ ! -f "$CONTRACT_PATH" ]; then
exit_on_error "Contract path '$CONTRACT_PATH' does not exist or is not a file."
fi
# Get the directory of the contract path
CONTRACT_DIR=$(dirname "$CONTRACT_PATH")
# shellcheck disable=SC2034
CONTRACT_FILE=$(basename "$CONTRACT_PATH")
# Change to the contract directory
cd "$CONTRACT_DIR" || exit_on_error "Failed to change directory to '$CONTRACT_DIR'."
# Step 1: Compile the contract
echo "Compiling the contract..."
if $VERBOSE; then
forge build --contracts . || exit_on_error "Failed to compile the contract."
else
forge build --contracts . > /dev/null 2>&1 || exit_on_error "Failed to compile the contract."
fi
# Step 2: Generate the init code
echo "Generating init code..."
INIT_CODE=$(forge inspect "$CONTRACT_NAME" bytecode) || exit_on_error "Failed to generate init code."
# Step 3: Calculate the init code hash
echo "Calculating init code hash..."
INIT_CODE_HASH=$(echo -n "$INIT_CODE" | keccak-256sum | cut -d' ' -f1) || exit_on_error "Failed to calculate init code hash."# படி 4: init குறியீடு ஹாஷை ஒரு கோப்பில் எழுதவும்
OUTPUT_FILE="${CONTRACT_NAME}_INIT_CODE_HASH.txt"
echo "$INIT_CODE_HASH" > "$OUTPUT_FILE" || exit_on_error "init குறியீடு ஹாஷை கோப்பில் எழுத முடியவில்லை."
# தற்காலிக கோப்புகளை சுத்தம் செய்யவும் (ஏதேனும் இருந்தால்)
# (சுத்தம் செய்ய வேண்டிய தற்காலிக கோப்புகள் ஏதேனும் இருந்தால் இங்கே கட்டளைகளைச் சேர்க்கவும்)
# படி 5: முடிவை வெளியிடவும்
echo "Init குறியீடு ஹாஷ் $OUTPUT_FILE இல் எழுதப்பட்டுள்ளது"
if $VERBOSE; then
echo "Init குறியீடு: $INIT_CODE"
echo "Init குறியீடு ஹாஷ்: $INIT_CODE_HASH"
fi
# அசல் கோப்பகத்திற்குத் திரும்பவும்
cd - > /dev/null || exit