Skip to content

Commit

Permalink
push state to the calldata for easy reconstruction
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhooketh committed Nov 15, 2024
1 parent dca170a commit 6b6ef53
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ jobs:
with:
submodules: recursive

- name: Download foundryup-zksync
run: curl -L https://raw.githubusercontent.com/matter-labs/foundry-zksync/main/install-foundry-zksync | bash

- name: Install Foundry
run: foundryup-zksync
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Run tests
run: cd contracts && forge test -vvv --zksync
run: forge test -vvv
10 changes: 6 additions & 4 deletions contracts/src/UntronCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,8 @@ contract UntronCore is Initializable, OwnableUpgradeable, UntronTransfers, Untro
}
}

/// @notice Closes the orders and sends the funds to the providers or order creators, if not fulfilled.
/// @param proof The ZK proof.
/// @param publicValues The public values for the proof and order closure.
function closeOrders(bytes calldata proof, bytes calldata publicValues) external {
/// @inheritdoc IUntronCore
function closeOrders(bytes calldata proof, bytes calldata publicValues, bytes calldata newState) external {
// verify the ZK proof with the public values
// verifying logic is defined in the UntronZK contract.
// currently it wraps SP1 zkVM verifier.
Expand All @@ -339,6 +337,10 @@ contract UntronCore is Initializable, OwnableUpgradeable, UntronTransfers, Untro
// check that the old state hash is equal to the current state hash
// this is needed to prevent the relayer from modifying the state in the ZK program.
require(oldStateHash == stateHash, "Old state hash is invalid");
// check that the new state is valid
// we need to pass the new state in the calldata for easy state reconstruction by the relayers.
// on ZKsync Era (our deployment chain), the calldata is not published to the L1, so it's cheap to pass.
require(newStateHash == sha256(newState), "New state is invalid");

// update the state hash
stateHash = newStateHash;
Expand Down
3 changes: 2 additions & 1 deletion contracts/src/interfaces/IUntronCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ interface IUntronCore is IUntronTransfers, IUntronFees, IUntronZK {
/// @notice Closes the orders and sends the funds to the providers or order creators, if not fulfilled.
/// @param proof The ZK proof.
/// @param publicValues The public values for the proof and order closure.
function closeOrders(bytes calldata proof, bytes calldata publicValues) external;
/// @param newState The new state of the ZK engine.
function closeOrders(bytes calldata proof, bytes calldata publicValues, bytes calldata newState) external;

/// @notice Sets the liquidity provider details.
/// @param liquidity The liquidity of the provider in USDT L2.
Expand Down

0 comments on commit 6b6ef53

Please sign in to comment.