From e30d0ca9dc46fc4af79b555e3fcc3d700b209bad Mon Sep 17 00:00:00 2001 From: Yash Patil <40046473+ypatil12@users.noreply.github.com> Date: Mon, 24 Feb 2025 12:28:29 -0800 Subject: [PATCH] feat: write phase 6 script timestamp to file --- .../v1.2.0-slashing/6-script/script.go | 11 ++++++++++- .../v1.2.0-slashing/6-script/script_test.go | 18 ++++++++++++++++-- .../v1.2.0-slashing/7-setProofTimestamp.s.sol | 15 +++++++++++++-- .../v1.2.0-slashing/8-executeUnpause.s.sol | 1 - .../releases/v1.2.0-slashing/forkTimestamp.txt | 1 + 5 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 script/releases/v1.2.0-slashing/forkTimestamp.txt diff --git a/script/releases/v1.2.0-slashing/6-script/script.go b/script/releases/v1.2.0-slashing/6-script/script.go index 2bae3627d..7c350f67e 100644 --- a/script/releases/v1.2.0-slashing/6-script/script.go +++ b/script/releases/v1.2.0-slashing/6-script/script.go @@ -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" @@ -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 } diff --git a/script/releases/v1.2.0-slashing/6-script/script_test.go b/script/releases/v1.2.0-slashing/6-script/script_test.go index 7da665d1f..648cccc82 100644 --- a/script/releases/v1.2.0-slashing/6-script/script_test.go +++ b/script/releases/v1.2.0-slashing/6-script/script_test.go @@ -4,6 +4,7 @@ import ( "bytes" "io" "os" + "path/filepath" "strings" "testing" @@ -50,6 +51,19 @@ 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 @@ -57,7 +71,7 @@ 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")) } @@ -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")) } diff --git a/script/releases/v1.2.0-slashing/7-setProofTimestamp.s.sol b/script/releases/v1.2.0-slashing/7-setProofTimestamp.s.sol index cb0b9e78b..92f9555b6 100644 --- a/script/releases/v1.2.0-slashing/7-setProofTimestamp.s.sol +++ b/script/releases/v1.2.0-slashing/7-setProofTimestamp.s.sol @@ -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"; @@ -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); } @@ -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)); + } } \ No newline at end of file diff --git a/script/releases/v1.2.0-slashing/8-executeUnpause.s.sol b/script/releases/v1.2.0-slashing/8-executeUnpause.s.sol index c007efdcc..b6477c21c 100644 --- a/script/releases/v1.2.0-slashing/8-executeUnpause.s.sol +++ b/script/releases/v1.2.0-slashing/8-executeUnpause.s.sol @@ -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(); diff --git a/script/releases/v1.2.0-slashing/forkTimestamp.txt b/script/releases/v1.2.0-slashing/forkTimestamp.txt new file mode 100644 index 000000000..09a3d4a3a --- /dev/null +++ b/script/releases/v1.2.0-slashing/forkTimestamp.txt @@ -0,0 +1 @@ +1740434112 \ No newline at end of file