Skip to content

Commit

Permalink
feat: write phase 6 script timestamp to file
Browse files Browse the repository at this point in the history
  • Loading branch information
ypatil12 committed Feb 24, 2025
1 parent f041744 commit e30d0ca
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 6 deletions.
11 changes: 10 additions & 1 deletion script/releases/v1.2.0-slashing/6-script/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"fmt"
"net/http"
"os"
"path/filepath"
"strconv"
"strings"

"github.com/attestantio/go-eth2-client/api"
attestantio "github.com/attestantio/go-eth2-client/http"
Expand Down Expand Up @@ -94,8 +96,15 @@ func runScript(args TArgs) error {
return fmt.Errorf("failed to decode response: %v", err)
}

timestamp := blockResponse.Data.Message.Body.ExecutionPayload.Timestamp
timestamp := strings.TrimSpace(blockResponse.Data.Message.Body.ExecutionPayload.Timestamp)
fmt.Printf("Slot timestamp: %s\n", timestamp)

// Write timestamp to file in the parent directory (v1.2.0-slashing)
outputPath := filepath.Join("..", "forkTimestamp.txt")
err = os.WriteFile(outputPath, []byte(timestamp), 0644)
if err != nil {
return fmt.Errorf("failed to write timestamp to file: %v", err)
}

return nil
}
18 changes: 16 additions & 2 deletions script/releases/v1.2.0-slashing/6-script/script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"io"
"os"
"path/filepath"
"strings"
"testing"

Expand Down Expand Up @@ -50,14 +51,27 @@ func runTestWithForkSlot(t *testing.T, forkSlot uint64, expectedOutput string) {
if expectedOutput != "" && !strings.Contains(output, expectedOutput) {
t.Errorf("Expected output to contain:\n%s\nGot:\n%s", expectedOutput, output)
}

// Check the timestamp file
timestampPath := filepath.Join("..", "forkTimestamp.txt")
content, err := os.ReadFile(timestampPath)
if err != nil {
t.Errorf("Failed to read timestamp file: %v", err)
return
}

expectedTimestamp := "1739908284"
if string(content) != expectedTimestamp {
t.Errorf("Expected timestamp file to contain %s, got %s", expectedTimestamp, string(content))
}
}

// Test on a missed slot, should print out that it missed the first slot
func TestRunScript_ForkSlot3667156(t *testing.T) {
expectedOutputs := []string{
"Slot 3667156 was missed, checking next slot...",
"Found first non-missed slot at slot 3667157",
"Slot timestamp: 173990828",
"Slot timestamp: 1739908284",
}
runTestWithForkSlot(t, 3667156, strings.Join(expectedOutputs, "\n"))
}
Expand All @@ -66,7 +80,7 @@ func TestRunScript_ForkSlot3667156(t *testing.T) {
func TestRunScript_ForkSlot3667157(t *testing.T) {
expectedOutputs := []string{
"Found first non-missed slot at slot 3667157",
"Slot timestamp: 173990828",
"Slot timestamp: 1739908284",
}
runTestWithForkSlot(t, 3667157, strings.Join(expectedOutputs, "\n"))
}
15 changes: 13 additions & 2 deletions script/releases/v1.2.0-slashing/7-setProofTimestamp.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity ^0.8.12;

import "../Env.sol";
import "forge-std/console.sol";

import {ExecuteUpgradeAndSetTimestampSubmitter} from "./5-executeUpgradeAndSetTimestampSubmitter.s.sol";
import {QueueUnpause} from "./3-queueUnpause.s.sol";
Expand All @@ -15,11 +16,15 @@ import {TimelockController} from "@openzeppelin/contracts/governance/TimelockCon
*/
contract SetProofTimestamp is ExecuteUpgradeAndSetTimestampSubmitter {
using Env for *;
using ZEnvHelpers for *;

uint64 proofTimestamp;

function _runAsMultisig() prank(Env.opsMultisig()) internal virtual override {
require(proofTimestamp != 0, "proofTimestamp must be set");
proofTimestamp = _getProofTimestamp();
// Assert that timestamp from script is >= the actual fork timestamp
require(proofTimestamp >= ZEnvHelpers.state().envU64("PECTRA_FORK_TIMESTAMP"), "proofTimestamp invalid");

Env.proxy.eigenPodManager().setPectraForkTimestamp(proofTimestamp);
}

Expand All @@ -40,10 +45,16 @@ contract SetProofTimestamp is ExecuteUpgradeAndSetTimestampSubmitter {
_unsafeResetHasPranked();

// 6. Set the proof timestamp
proofTimestamp = 1740434112; // Using holesky pectra fork timestamp for testing
// This test uses the actual pectra fork timestamp, hence why `forkTimestamp.txt` already has a set timestamp
execute();

// Validate that the proof timestamp is set
assertEq(Env.proxy.eigenPodManager().pectraForkTimestamp(), proofTimestamp, "Proof timestamp is not set");
}

function _getProofTimestamp() internal view returns (uint64) {
string memory timestampPath = string.concat(vm.projectRoot(), "/script/releases/v1.2.0-slashing/forkTimestamp.txt");
string memory timestamp = vm.readFile(timestampPath);
return uint64(vm.parseUint(timestamp));
}
}
1 change: 0 additions & 1 deletion script/releases/v1.2.0-slashing/8-executeUnpause.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ contract ExecuteUnpause is SetProofTimestamp {
_unsafeResetHasPranked();

// 7. Set the proof timestamp
SetProofTimestamp.setTimestamp(1740434112); // Using holesky pectra fork timestamp for testing
SetProofTimestamp._runAsMultisig();
_unsafeResetHasPranked();

Expand Down
1 change: 1 addition & 0 deletions script/releases/v1.2.0-slashing/forkTimestamp.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1740434112

0 comments on commit e30d0ca

Please sign in to comment.