Skip to content

Commit

Permalink
Remove root state hash, fix pub input hash variable (#320)
Browse files Browse the repository at this point in the history
  • Loading branch information
xqft authored Aug 14, 2024
1 parent cce6341 commit b0d252d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
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

0 comments on commit b0d252d

Please sign in to comment.