Skip to content
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

Remove root state hash, fix pub input hash variable #320

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions contract/src/MinaBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,24 @@ pragma solidity ^0.8.12;
import "aligned_layer/contracts/src/core/AlignedLayerServiceManager.sol";

error NewStateIsNotValid();
error TipStateIsWrong();
error TipStateIsWrong(bytes32 pubInputTipStateHash, bytes32 tipStatehash);

/// @title Mina to Ethereum Bridge's smart contract.
contract MinaBridge {
/// @notice The state hash of the last verified state as a Fp.
bytes32 tipStateHash;

/// @notice The state hash of the transition frontier's root.
bytes32 rootStateHash;

/// @notice Reference to the AlignedLayerServiceManager contract.
AlignedLayerServiceManager aligned;

constructor(address _alignedServiceAddr, bytes32 _rootStateHash) {
constructor(address _alignedServiceAddr, bytes32 _tipStateHash) {
aligned = AlignedLayerServiceManager(_alignedServiceAddr);
rootStateHash = _rootStateHash;
tipStateHash = _tipStateHash;
}

/// @notice Returns the last verified state hash, or the root state hash if none.
function getTipStateHash() external view returns (bytes32) {
if (tipStateHash != 0) {
return tipStateHash;
} else {
return rootStateHash;
}
return tipStateHash;
}

function updateTipState(
Expand All @@ -42,11 +35,11 @@ contract MinaBridge {
) external {
bytes32 pubInputTipStateHash;
assembly {
mstore(pubInputTipStateHash, mload(add(pubInput, 0x40)))
pubInputTipStateHash := mload(add(pubInput, 0x40))
}

if (pubInputTipStateHash != tipStateHash) {
revert TipStateIsWrong();
revert TipStateIsWrong(pubInputTipStateHash, tipStateHash);
}

bytes32 pubInputCommitment = keccak256(pubInput);
Expand Down
Loading