-
Notifications
You must be signed in to change notification settings - Fork 17
Pass inputs and root commitment to dispute client #78
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
Changes from all commits
d61dd25
82f7252
22990ad
2c98b8d
6178645
a986f29
b20475f
dc6f7eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| .vscode | ||
| **/target/ | ||
| **/snapshots/ | ||
| Cargo.lock |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,8 +34,12 @@ local function run_uarch_span(machine) | |
| return builder:build() | ||
| end | ||
|
|
||
| local function build_small_machine_commitment(base_cycle, log2_stride_count, machine) | ||
| local function build_small_machine_commitment(base_cycle, log2_stride_count, machine, snapshot_dir) | ||
| local machine_state = machine:run(base_cycle) | ||
| if save_snapshot then | ||
| -- taking snapshot for leafs to save time in next level | ||
| machine:snapshot(snapshot_dir, base_cycle) | ||
| end | ||
| local initial_state = machine_state.root_hash | ||
|
|
||
| local builder = MerkleBuilder:new() | ||
|
|
@@ -55,24 +59,21 @@ local function build_small_machine_commitment(base_cycle, log2_stride_count, mac | |
| return initial_state, builder:build(initial_state) | ||
| end | ||
|
|
||
| local function build_big_machine_commitment(base_cycle, log2_stride, log2_stride_count, machine) | ||
| local function build_big_machine_commitment(base_cycle, log2_stride, log2_stride_count, machine, snapshot_dir) | ||
| local machine_state = machine:run(base_cycle) | ||
| if save_snapshot then | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It could change occasionally because it's |
||
| -- taking snapshot for leafs to save time in next level | ||
| machine:snapshot(snapshot_dir, base_cycle) | ||
| end | ||
| local initial_state = machine_state.root_hash | ||
|
|
||
| local builder = MerkleBuilder:new() | ||
| local instruction_count = arithmetic.max_uint(log2_stride_count) | ||
| local instruction = 0 | ||
|
|
||
| local snapshot_frequency = 1024 | ||
| while ulte(instruction, instruction_count) do | ||
| local cycle = ((instruction + 1) << (log2_stride - consts.log2_uarch_span)) | ||
| machine_state = machine:run(base_cycle + cycle) | ||
| if save_snapshot then | ||
| -- taking snapshot for leafs to save time in next level | ||
| if ((instruction + 1) % snapshot_frequency) == 0 then | ||
| machine:snapshot(base_cycle + cycle) | ||
| end | ||
| end | ||
|
|
||
| if not machine_state.halted then | ||
| builder:add(machine_state.root_hash) | ||
|
|
@@ -87,29 +88,33 @@ local function build_big_machine_commitment(base_cycle, log2_stride, log2_stride | |
| return initial_state, builder:build(initial_state) | ||
| end | ||
|
|
||
| local function build_commitment(base_cycle, log2_stride, log2_stride_count, machine_path) | ||
| local function build_commitment(base_cycle, log2_stride, log2_stride_count, machine_path, snapshot_dir) | ||
| local machine = Machine:new_from_path(machine_path) | ||
| machine:load_snapshot(base_cycle) | ||
| machine:load_snapshot(snapshot_dir, base_cycle) | ||
|
|
||
| if log2_stride >= consts.log2_uarch_span then | ||
| assert( | ||
| log2_stride + log2_stride_count <= | ||
| consts.log2_emulator_span + consts.log2_uarch_span | ||
| ) | ||
| return build_big_machine_commitment(base_cycle, log2_stride, log2_stride_count, machine) | ||
| return build_big_machine_commitment(base_cycle, log2_stride, log2_stride_count, machine, snapshot_dir) | ||
| else | ||
| assert(log2_stride == 0) | ||
| return build_small_machine_commitment(base_cycle, log2_stride_count, machine) | ||
| return build_small_machine_commitment(base_cycle, log2_stride_count, machine, snapshot_dir) | ||
| end | ||
| end | ||
|
|
||
| local CommitmentBuilder = {} | ||
| CommitmentBuilder.__index = CommitmentBuilder | ||
|
|
||
| function CommitmentBuilder:new(machine_path) | ||
| function CommitmentBuilder:new(machine_path, snapshot_dir, root_commitment) | ||
| -- receive honest root commitment from main process | ||
| local commitments = { [0] = { [0] = root_commitment } } | ||
|
|
||
| local c = { | ||
| commitments = commitments, | ||
| machine_path = machine_path, | ||
| commitments = {} | ||
| snapshot_dir = snapshot_dir | ||
| } | ||
| setmetatable(c, self) | ||
| return c | ||
|
|
@@ -122,7 +127,8 @@ function CommitmentBuilder:build(base_cycle, level, log2_stride, log2_stride_cou | |
| return self.commitments[level][base_cycle] | ||
| end | ||
|
|
||
| local _, commitment = build_commitment(base_cycle, log2_stride, log2_stride_count, self.machine_path) | ||
| local _, commitment = build_commitment(base_cycle, log2_stride, log2_stride_count, self.machine_path, | ||
| self.snapshot_dir) | ||
| self.commitments[level][base_cycle] = commitment | ||
| return commitment | ||
| end | ||
|
|
||
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.
What is
snapshot?Uh oh!
There was an error while loading. Please reload this page.
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.
It is to get the path of machine snapshot of given
(epoch_number, input_index_in_epoch). The node would passsnapshot(epoch_number, 0)to be the initial machine path for the dispute client.