Skip to content

Commit

Permalink
Merge branch 'metahash' into conditional_proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
dantaik authored Nov 12, 2023
2 parents c3dc319 + b9abd61 commit 01317f5
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 15 deletions.
1 change: 1 addition & 0 deletions packages/protocol/contracts/L1/TaikoData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ library TaikoData {
address feeToken;
TierFee[] tierFees;
uint64 expiry;
uint64 maxBlockId;
bytes signature;
}

Expand Down
14 changes: 14 additions & 0 deletions packages/protocol/contracts/L1/TaikoToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ contract TaikoToken is
_mint(_recipient, 1_000_000_000 ether);
}

/// @notice Mints new tokens to the specified address.
/// @param to The address to receive the minted tokens.
/// @param amount The amount of tokens to mint.
function mint(address to, uint256 amount) public onlyOwner {
_mint(to, amount);
}

/// @notice Burns tokens from the specified address.
/// @param from The address to burn tokens from.
/// @param amount The amount of tokens to burn.
function burn(address from, uint256 amount) public onlyOwner {
_burn(from, amount);
}

/// @notice Creates a new token snapshot.
function snapshot() public onlyOwner {
_snapshot();
Expand Down
11 changes: 9 additions & 2 deletions packages/protocol/contracts/L1/libs/LibProposing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,9 @@ library LibProposing {
// Validate the prover assignment, then charge Ether or ERC20 as the
// prover fee based on the block's minTier.
uint256 proverFee =
_payProverFeeAndTip(meta.minTier, meta.blobHash, params.assignment);
_payProverFeeAndTip(
meta.minTier, meta.blobHash, blk.blockId, params.assignment
);

emit BlockProposed({
blockId: blk.blockId,
Expand Down Expand Up @@ -301,6 +303,7 @@ library LibProposing {
blobHash,
assignment.feeToken,
assignment.expiry,
assignment.maxBlockId,
assignment.tierFees
)
);
Expand All @@ -309,13 +312,17 @@ library LibProposing {
function _payProverFeeAndTip(
uint16 minTier,
bytes32 blobHash,
uint64 blockId,
TaikoData.ProverAssignment memory assignment
)
private
returns (uint256 proverFee)
{
// Check assignment not expired
if (block.timestamp >= assignment.expiry) {
if (
block.timestamp > assignment.expiry
|| blockId > assignment.maxBlockId
) {
revert L1_ASSIGNMENT_EXPIRED();
}

Expand Down
24 changes: 17 additions & 7 deletions packages/protocol/contracts/bridge/Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ contract Bridge is EssentialContract, IBridge {
_message.from = msg.sender;
_message.srcChainId = uint64(block.chainid);

msgHash = keccak256(abi.encode(_message));
msgHash = hashMessage(_message);

ISignalService(resolve("signal_service", false)).sendSignal(msgHash);
emit MessageSent(msgHash, _message);
Expand All @@ -123,7 +123,7 @@ contract Bridge is EssentialContract, IBridge {
whenNotPaused
sameChain(message.srcChainId)
{
bytes32 msgHash = keccak256(abi.encode(message));
bytes32 msgHash = hashMessage(message);
if (isMessageRecalled[msgHash]) revert B_RECALLED_ALREADY();

bool received = _proveSignalReceived(
Expand Down Expand Up @@ -185,7 +185,8 @@ contract Bridge is EssentialContract, IBridge {
revert B_PERMISSION_DENIED();
}

bytes32 msgHash = keccak256(abi.encode(message));
bytes32 msgHash = hashMessage(message);

if (messageStatus[msgHash] != Status.NEW) revert B_STATUS_MISMATCH();

bool received = _proveSignalReceived(msgHash, message.srcChainId, proof);
Expand Down Expand Up @@ -254,7 +255,7 @@ contract Bridge is EssentialContract, IBridge {
if (msg.sender != message.user) revert B_PERMISSION_DENIED();
}

bytes32 msgHash = keccak256(abi.encode(message));
bytes32 msgHash = hashMessage(message);
if (messageStatus[msgHash] != Status.RETRIABLE) {
revert B_NON_RETRIABLE();
}
Expand All @@ -280,7 +281,7 @@ contract Bridge is EssentialContract, IBridge {
if (message.srcChainId != block.chainid) return false;
return ISignalService(resolve("signal_service", false)).isSignalSent({
app: address(this),
signal: keccak256(abi.encode(message))
signal: hashMessage(message)
});
}

Expand All @@ -298,7 +299,7 @@ contract Bridge is EssentialContract, IBridge {
{
if (message.srcChainId != block.chainid) return false;
return _proveSignalReceived(
_signalForFailedMessage(keccak256(abi.encode(message))),
_signalForFailedMessage(hashMessage(message)),
message.destChainId,
proof
);
Expand All @@ -318,7 +319,7 @@ contract Bridge is EssentialContract, IBridge {
{
if (message.destChainId != block.chainid) return false;
return _proveSignalReceived(
keccak256(abi.encode(message)), message.srcChainId, proof
hashMessage(message), message.srcChainId, proof
);
}

Expand All @@ -344,6 +345,15 @@ contract Bridge is EssentialContract, IBridge {
return _ctx;
}

/// @notice Hash the message
function hashMessage(Message memory message)
public
pure
returns (bytes32)
{
return keccak256(abi.encode("TAIKO_MESSAGE", message));
}

/// @notice Invokes a call message on the Bridge.
/// @param message The call message to be invoked.
/// @param msgHash The hash of the message.
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"lint:sol": "forge fmt && pnpm solhint 'contracts/**/*.sol' --fix",
"sizer": "pnpm hardhat size-contracts",
"snapshot": "forge snapshot --match-path 'test/**/*.t.sol'",
"test": "forge test -vvv --gas-report --match-path test/*.t.sol",
"test": "forge test -vvv --match-path test/*.t.sol",
"test:coverage": "mkdir -p coverage && forge coverage --report lcov && lcov --remove ./lcov.info -o ./coverage/lcov.info 'test/' 'script/' 'contracts/thirdparty/' && genhtml coverage/lcov.info --branch-coverage --output-dir coverage --ignore-errors category && open coverage/index.html",
"test:genesis": "pnpm compile && pnpm compile:hardhat && FOUNDRY_PROFILE=genesis ./genesis/generate_genesis.test.sh",
"export:simconf": "forge test --match-test 'test_simulation' -vv > simulation/out/simconf_$(date +%s).txt",
Expand Down
27 changes: 27 additions & 0 deletions packages/protocol/script/merge_contracts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os
import argparse

def merge_solidity_files(root_dir, output_file='../out/taiko_protocol.md'):
with open(output_file, 'w') as outfile:
for subdir, dirs, files in os.walk(root_dir):
for file in files:
if file.endswith('.sol') and not file.endswith('.t.sol'):
file_path = os.path.join(subdir, file)
if "/test/" in file_path:
continue
print("merging ", file_path)
relative_path = os.path.relpath(file_path, root_dir)
outfile.write(f"## {relative_path}\n")
outfile.write("```solidity\n")
with open(file_path, 'r') as infile:
outfile.write(infile.read())
outfile.write("\n```\n\n")


if __name__ == "__main__":
# parser = argparse.ArgumentParser(description="Merge Solidity files into a Markdown file.")
# parser.add_argument("root_dir", type=str, help="Root directory containing Solidity files")
# args = parser.parse_args()
# merge_solidity_files(args.root_dir)
merge_solidity_files("../contracts")
print("merged into ../out/taiko_protocol.md")
1 change: 1 addition & 0 deletions packages/protocol/test/L1/TaikoL1TestBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ abstract contract TaikoL1TestBase is TestBase {
feeToken: address(0),
tierFees: tierFees,
expiry: uint64(block.timestamp + 60 minutes),
maxBlockId: 1_000_000,
signature: new bytes(0)
});

Expand Down
10 changes: 5 additions & 5 deletions packages/protocol/test/bridge/Bridge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ contract BridgeTest is TestBase {
// coresponding to the message
bytes memory proof = hex"00";

bytes32 msgHash = keccak256(abi.encode(message));
bytes32 msgHash = destChainBridge.hashMessage(message);

vm.chainId(destChainId);
vm.prank(Bob, Bob);
Expand Down Expand Up @@ -146,7 +146,7 @@ contract BridgeTest is TestBase {
// coresponding to the message
bytes memory proof = hex"00";

bytes32 msgHash = keccak256(abi.encode(message));
bytes32 msgHash = destChainBridge.hashMessage(message);

vm.chainId(destChainId);

Expand Down Expand Up @@ -185,7 +185,7 @@ contract BridgeTest is TestBase {
// coresponding to the message
bytes memory proof = hex"00";

bytes32 msgHash = keccak256(abi.encode(message));
bytes32 msgHash = destChainBridge.hashMessage(message);

vm.chainId(destChainId);

Expand Down Expand Up @@ -396,7 +396,7 @@ contract BridgeTest is TestBase {
(IBridge.Message memory message, bytes memory proof) =
setUpPredefinedSuccessfulProcessMessageCall();

bytes32 msgHash = keccak256(abi.encode(message));
bytes32 msgHash = destChainBridge.hashMessage(message);

destChainBridge.processMessage(message, proof);

Expand All @@ -419,7 +419,7 @@ contract BridgeTest is TestBase {
// etch bad receiver at the to address, so it fails.
vm.etch(message.to, address(badReceiver).code);

bytes32 msgHash = keccak256(abi.encode(message));
bytes32 msgHash = destChainBridge.hashMessage(message);

destChainBridge.processMessage(message, proof);

Expand Down

0 comments on commit 01317f5

Please sign in to comment.