Skip to content
This repository has been archived by the owner on Mar 12, 2024. It is now read-only.

Commit

Permalink
chore: update copyright notice onchain
Browse files Browse the repository at this point in the history
  • Loading branch information
ZzzzHui committed Jul 26, 2023
1 parent 46a6cbd commit 7e8889c
Show file tree
Hide file tree
Showing 105 changed files with 1,243 additions and 6,605 deletions.
13 changes: 2 additions & 11 deletions onchain/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
# Copyright Cartesi Pte. Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
# (c) Cartesi and individual authors (see AUTHORS)
# SPDX-License-Identifier: Apache-2.0 (see LICENSE)

# syntax=docker.io/docker/dockerfile:1.4
FROM node:16.17.0-alpine3.15 as base
Expand Down
193 changes: 119 additions & 74 deletions onchain/rollups-arbitration/test/epoch-hash-split/EpochHashSplit.t.sol
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
// Copyright Cartesi Pte. Ltd.

// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
// this file except in compliance with the License. You may obtain a copy of the
// License at http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software distributed
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.
// (c) Cartesi and individual authors (see AUTHORS)
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)
pragma solidity ^0.8.13;

import "forge-std/Test.sol";
import "../../src/epoch-hash-split/EpochHashSplit.sol";
import "../../src/partition/Partition.sol";
import { Merkle } from "utils/Merkle.sol";
import {Merkle} from "utils/Merkle.sol";

contract TestEpochHashSplit is Test {
function setUp() public {
}
function setUp() public {}

function test_createSplit() public {
Merkle.Hash preAdvanceMachine_ = Merkle.Hash.wrap(INITIAL_HASH);
Merkle.Hash preAdvanceOutputs_ = Merkle.Hash.wrap(INITIAL_HASH);
Partition.Divergence memory divergence_ = createDivergence();
divergence_.beforeHash = bytes32(0xad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5);

EpochHashSplit.WaitingSubhashes memory waitingSubhashes_ =
EpochHashSplit.createSplit(
divergence_.beforeHash = bytes32(
0xad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5
);

EpochHashSplit.WaitingSubhashes
memory waitingSubhashes_ = EpochHashSplit.createSplit(
divergence_,
preAdvanceMachine_,
preAdvanceOutputs_
);

assertEq(Merkle.Hash.unwrap(waitingSubhashes_.preAdvanceMachine), Merkle.Hash.unwrap(preAdvanceMachine_));
assertEq(Merkle.Hash.unwrap(waitingSubhashes_.preAdvanceOutputs), Merkle.Hash.unwrap(preAdvanceOutputs_));
assertEq(waitingSubhashes_.postAdvanceEpochHashClaim, divergence_.afterHash);
assertEq(
Merkle.Hash.unwrap(waitingSubhashes_.preAdvanceMachine),
Merkle.Hash.unwrap(preAdvanceMachine_)
);
assertEq(
Merkle.Hash.unwrap(waitingSubhashes_.preAdvanceOutputs),
Merkle.Hash.unwrap(preAdvanceOutputs_)
);
assertEq(
waitingSubhashes_.postAdvanceEpochHashClaim,
divergence_.afterHash
);
assertEq(waitingSubhashes_.inputIndex, divergence_.divergencePoint);
}

Expand All @@ -44,16 +45,25 @@ contract TestEpochHashSplit is Test {
Merkle.Hash preAdvanceOutputs_ = Merkle.Hash.wrap(INITIAL_HASH);
Partition.Divergence memory divergence_ = createDivergence();

EpochHashSplit.WaitingSubhashes memory waitingSubhashes_ =
EpochHashSplit.createSplit(
EpochHashSplit.WaitingSubhashes
memory waitingSubhashes_ = EpochHashSplit.createSplit(
divergence_,
preAdvanceMachine_,
preAdvanceOutputs_
);

assertEq(Merkle.Hash.unwrap(waitingSubhashes_.preAdvanceMachine), Merkle.Hash.unwrap(preAdvanceMachine_));
assertEq(Merkle.Hash.unwrap(waitingSubhashes_.preAdvanceOutputs), Merkle.Hash.unwrap(preAdvanceOutputs_));
assertEq(waitingSubhashes_.postAdvanceEpochHashClaim, divergence_.afterHash);
assertEq(
Merkle.Hash.unwrap(waitingSubhashes_.preAdvanceMachine),
Merkle.Hash.unwrap(preAdvanceMachine_)
);
assertEq(
Merkle.Hash.unwrap(waitingSubhashes_.preAdvanceOutputs),
Merkle.Hash.unwrap(preAdvanceOutputs_)
);
assertEq(
waitingSubhashes_.postAdvanceEpochHashClaim,
divergence_.afterHash
);
assertEq(waitingSubhashes_.inputIndex, divergence_.divergencePoint);
}

Expand All @@ -64,56 +74,83 @@ contract TestEpochHashSplit is Test {
Merkle.Hash postAdvanceOutputsClaim_ = Merkle.Hash.wrap(INITIAL_HASH);
Partition.Divergence memory divergence_ = createDivergence();
/* modify the afterHash to match the expected value */
divergence_.beforeHash = bytes32(0xad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5);
divergence_.afterHash = bytes32(0xad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5);

EpochHashSplit.WaitingSubhashes memory waitingSubhashes_ =
EpochHashSplit.createSplit(
divergence_.beforeHash = bytes32(
0xad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5
);
divergence_.afterHash = bytes32(
0xad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5
);

EpochHashSplit.WaitingSubhashes
memory waitingSubhashes_ = EpochHashSplit.createSplit(
divergence_,
preAdvanceMachine_,
preAdvanceOutputs_
);

EpochHashSplit.WaitingDivergence memory waitingDivergence_ =
EpochHashSplit.supplySubhashes(
EpochHashSplit.WaitingDivergence
memory waitingDivergence_ = EpochHashSplit.supplySubhashes(
waitingSubhashes_,
postAdvanceMachineClaim_,
postAdvanceOutputsClaim_
);

assertEq(Merkle.Hash.unwrap(waitingSubhashes_.preAdvanceMachine), Merkle.Hash.unwrap(waitingDivergence_.preAdvanceMachine));
assertEq(Merkle.Hash.unwrap(waitingSubhashes_.preAdvanceOutputs), Merkle.Hash.unwrap(waitingDivergence_.preAdvanceOutputs));
assertEq(Merkle.Hash.unwrap(postAdvanceMachineClaim_), Merkle.Hash.unwrap(waitingDivergence_.postAdvanceMachineClaim));
assertEq(Merkle.Hash.unwrap(postAdvanceOutputsClaim_), Merkle.Hash.unwrap(waitingDivergence_.postAdvanceOutputsClaim));

assertEq(
Merkle.Hash.unwrap(waitingSubhashes_.preAdvanceMachine),
Merkle.Hash.unwrap(waitingDivergence_.preAdvanceMachine)
);
assertEq(
Merkle.Hash.unwrap(waitingSubhashes_.preAdvanceOutputs),
Merkle.Hash.unwrap(waitingDivergence_.preAdvanceOutputs)
);
assertEq(
Merkle.Hash.unwrap(postAdvanceMachineClaim_),
Merkle.Hash.unwrap(waitingDivergence_.postAdvanceMachineClaim)
);
assertEq(
Merkle.Hash.unwrap(postAdvanceOutputsClaim_),
Merkle.Hash.unwrap(waitingDivergence_.postAdvanceOutputsClaim)
);
assertEq(waitingSubhashes_.inputIndex, waitingDivergence_.inputIndex);
}

function test_machineDisagree() public {
EpochHashSplit.WaitingDivergence memory waitingDivergence_ =
createWaitingDivergence();
EpochHashSplit.WaitingDivergence
memory waitingDivergence_ = createWaitingDivergence();

EpochHashSplit.MachineDisagree memory machineDisagree_ =
EpochHashSplit.machineDisagree(
waitingDivergence_
);

assertEq(Merkle.Hash.unwrap(machineDisagree_.preAdvanceMachine), Merkle.Hash.unwrap(waitingDivergence_.preAdvanceMachine));
assertEq(Merkle.Hash.unwrap(machineDisagree_.postAdvanceMachineClaim), Merkle.Hash.unwrap(waitingDivergence_.postAdvanceMachineClaim));
EpochHashSplit.MachineDisagree memory machineDisagree_ = EpochHashSplit
.machineDisagree(waitingDivergence_);

assertEq(
Merkle.Hash.unwrap(machineDisagree_.preAdvanceMachine),
Merkle.Hash.unwrap(waitingDivergence_.preAdvanceMachine)
);
assertEq(
Merkle.Hash.unwrap(machineDisagree_.postAdvanceMachineClaim),
Merkle.Hash.unwrap(waitingDivergence_.postAdvanceMachineClaim)
);
assertEq(machineDisagree_.inputIndex, waitingDivergence_.inputIndex);
}

function test_outputsDisagree() public {
EpochHashSplit.WaitingDivergence memory waitingDivergence_ =
createWaitingDivergence();

EpochHashSplit.OutputsDisagree memory outputsDisagree_ =
EpochHashSplit.outputsDisagree(
waitingDivergence_
);

assertEq(Merkle.Hash.unwrap(outputsDisagree_.preAdvanceOutputs), Merkle.Hash.unwrap(waitingDivergence_.preAdvanceOutputs));
assertEq(Merkle.Hash.unwrap(outputsDisagree_.postAdvanceMachine), Merkle.Hash.unwrap(waitingDivergence_.postAdvanceMachineClaim));
assertEq(Merkle.Hash.unwrap(outputsDisagree_.postAdvanceOutputsClaim), Merkle.Hash.unwrap(waitingDivergence_.postAdvanceOutputsClaim));
EpochHashSplit.WaitingDivergence
memory waitingDivergence_ = createWaitingDivergence();

EpochHashSplit.OutputsDisagree memory outputsDisagree_ = EpochHashSplit
.outputsDisagree(waitingDivergence_);

assertEq(
Merkle.Hash.unwrap(outputsDisagree_.preAdvanceOutputs),
Merkle.Hash.unwrap(waitingDivergence_.preAdvanceOutputs)
);
assertEq(
Merkle.Hash.unwrap(outputsDisagree_.postAdvanceMachine),
Merkle.Hash.unwrap(waitingDivergence_.postAdvanceMachineClaim)
);
assertEq(
Merkle.Hash.unwrap(outputsDisagree_.postAdvanceOutputsClaim),
Merkle.Hash.unwrap(waitingDivergence_.postAdvanceOutputsClaim)
);
assertEq(outputsDisagree_.inputIndex, waitingDivergence_.inputIndex);
}

Expand All @@ -124,23 +161,31 @@ contract TestEpochHashSplit is Test {
bytes32 constant INITIAL_HASH =
0x0000000000000000000000000000000000000000000000000000000000000000;

function createDivergence() internal pure returns (Partition.Divergence memory){
return Partition.Divergence(
0,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000001
);
function createDivergence()
internal
pure
returns (Partition.Divergence memory)
{
return
Partition.Divergence(
0,
0x0000000000000000000000000000000000000000000000000000000000000000,
0x0000000000000000000000000000000000000000000000000000000000000001
);
}

function createWaitingDivergence() internal pure returns(EpochHashSplit.WaitingDivergence memory){
return EpochHashSplit.WaitingDivergence(
Merkle.Hash.wrap(INITIAL_HASH),
Merkle.Hash.wrap(INITIAL_HASH),
Merkle.Hash.wrap(INITIAL_HASH),
Merkle.Hash.wrap(INITIAL_HASH),
0
);
function createWaitingDivergence()
internal
pure
returns (EpochHashSplit.WaitingDivergence memory)
{
return
EpochHashSplit.WaitingDivergence(
Merkle.Hash.wrap(INITIAL_HASH),
Merkle.Hash.wrap(INITIAL_HASH),
Merkle.Hash.wrap(INITIAL_HASH),
Merkle.Hash.wrap(INITIAL_HASH),
0
);
}
}


Loading

0 comments on commit 7e8889c

Please sign in to comment.