-
Notifications
You must be signed in to change notification settings - Fork 15
fix(node): fix startup machine hash validation #179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
machine-image | ||
.env |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require "setup_path" | ||
|
||
local env = require "sepolia.setup_env" | ||
local conversion = require "utils.conversion" | ||
|
||
local big_input = conversion.bin_from_hex_n("0x6228290203658fd4987e40cbb257cabf258f9c288cdee767eaba6b234a73a2f9") | ||
:rep((1 << 11) - 10) | ||
assert(big_input:len() == (1 << 16) - 320) | ||
|
||
env.sender:tx_add_inputs { conversion.hex_from_bin_n(big_input) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
require "setup_path" | ||
|
||
local PatchedCommitmentBuilder = require "runners.helpers.patched_commitment" | ||
local CommitmentBuilder = require "computation.commitment" | ||
local Hash = require "cryptography.hash" | ||
local Machine = require "computation.machine" | ||
local start_sybil = require "runners.sybil_runner" | ||
local time = require "utils.time" | ||
|
||
local env = require "sepolia.setup_env" | ||
|
||
local sealed_epochs = env.reader:read_epochs_sealed() | ||
local sealed_epoch = sealed_epochs[#sealed_epochs] | ||
|
||
-- get all inputs | ||
local all_inputs = env.reader:read_inputs_added(sealed_epoch.epoch_number) | ||
|
||
-- slice inputs into `sealed_epoch` inputs | ||
local inputs = {} | ||
for i = sealed_epoch.input_lower_bound + 1, sealed_epoch.input_upper_bound do | ||
table.insert(inputs, all_inputs[i].data) | ||
end | ||
|
||
-- Get `sealed_epoch` machine path. | ||
|
||
-- Compute honest commitment | ||
-- 44 is the initial log2_stride currently configured in the smart contracts. | ||
local initial_state, commitment = Machine.root_rollup_commitment(env.template_machine, 44, inputs) | ||
assert(sealed_epoch.initial_machine_state_hash, initial_state) | ||
|
||
local patches = { | ||
-- add input 2 + ustep | ||
{ hash = Hash.zero, meta_cycle = (1 << 44) }, | ||
{ hash = Hash.zero, meta_cycle = (1 << 27) }, | ||
{ hash = Hash.zero, meta_cycle = (1) }, | ||
} | ||
|
||
local honest_commitment_builder = CommitmentBuilder:new(env.template_machine, inputs, commitment) | ||
local patched_commitment_builder = PatchedCommitmentBuilder:new(patches, honest_commitment_builder) | ||
local player = start_sybil(patched_commitment_builder, env.template_machine, sealed_epoch.tournament, inputs, 1, {pk = env.pk, endpoint = env.gateway}) | ||
|
||
local function player_react(player_coroutine) | ||
local success, log = coroutine.resume(player_coroutine) | ||
assert(success, string.format("player fail to resume with error: %s", log)) | ||
return coroutine.status(player_coroutine), log | ||
end | ||
|
||
local function drive_player_until(player_coroutine, condition_f) | ||
local ret | ||
while true do | ||
ret = { condition_f(player_react(player_coroutine)) } | ||
|
||
if ret[1] then | ||
return table.unpack(ret) | ||
end | ||
|
||
time.sleep(15) | ||
end | ||
end | ||
|
||
local function drive_player(player_coroutine) | ||
return drive_player_until(player_coroutine, function(status, log) | ||
if log.has_lost then | ||
return "lost" | ||
elseif status == "dead" then | ||
return "dead" | ||
end | ||
end) | ||
end | ||
|
||
-- Run player till completion | ||
print("Run Sybil") | ||
assert(drive_player(player) == "lost") | ||
print "Sybil has lost" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
local Reader = require "dave.reader" | ||
local Sender = require "dave.sender" | ||
|
||
-- addresses | ||
local APP_ADDRESS = assert(os.getenv("APP_ADDRESS")) | ||
local CONSENSUS_ADDRESS = assert(os.getenv("CONSENSUS_ADDRESS")) | ||
local INPUT_BOX_ADDRESS = assert(os.getenv("INPUT_BOX_ADDRESS")) | ||
local PK_ADDRESS = assert(os.getenv("PK_ADDRESS")) | ||
|
||
print(string.format([[ | ||
APP_ADDRESS = %s | ||
CONSENSUS_ADDRESS = %s | ||
INPUT_BOX_ADDRESS = %s | ||
PK_ADDRESS = %s | ||
]], APP_ADDRESS, CONSENSUS_ADDRESS, INPUT_BOX_ADDRESS, PK_ADDRESS)) | ||
|
||
local GATEWAY = assert(os.getenv("GATEWAY")) | ||
local PK = assert(os.getenv("PK")) | ||
|
||
local reader = Reader:new(INPUT_BOX_ADDRESS, CONSENSUS_ADDRESS, GATEWAY, 8467207) | ||
local sender = Sender:new(INPUT_BOX_ADDRESS, APP_ADDRESS, PK, GATEWAY) | ||
|
||
print(string.format("BALANCE = %s", reader:balance(PK_ADDRESS))) | ||
|
||
return { | ||
app_address = APP_ADDRESS, | ||
consensus_address = CONSENSUS_ADDRESS, | ||
input_box_address = INPUT_BOX_ADDRESS, | ||
signer_address = PK_ADDRESS, | ||
gateway = GATEWAY, | ||
pk = PK, | ||
template_machine = "sepolia/machine-image", | ||
|
||
reader = reader, | ||
sender = sender, | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the relevant fix.