Skip to content

Commit

Permalink
Old circuit, with new contract ABI.
Browse files Browse the repository at this point in the history
This reverts commit 6e2f649.
  • Loading branch information
dvush committed Jun 1, 2020
1 parent 63475ae commit eafc910
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 47 deletions.
1 change: 0 additions & 1 deletion contracts/contracts/Storage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ contract Storage {
bytes32 withdrawalsDataHash; /// can be restricted to 16 bytes to reduce number of required storage slots
bytes32 commitment;
bytes32 stateRoot;
bytes32 opTreeRootHash;
}

/// @notice Blocks by Franklin block id
Expand Down
15 changes: 5 additions & 10 deletions contracts/contracts/ZkSync.sol
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ contract ZkSync is UpgradeableMaster, Storage, Config, Events, ReentrancyGuard {
/// @notice Commit block - collect onchain operations, create its commitment, emit BlockCommit event
/// @param _blockNumber Block number
/// @param _feeAccount Account to collect fees
/// @param _newRoot New tree root
/// @param _newRoots New root hashes of block. (first element is account root hash, rest of the array is reserved for future)
/// @param _publicData Operations pubdata
/// @param _ethWitness Data passed to ethereum outside pubdata of the circuit.
/// @param _ethWitnessSizes Amount of eth witness bytes for the corresponding operation.
Expand All @@ -297,8 +297,7 @@ contract ZkSync is UpgradeableMaster, Storage, Config, Events, ReentrancyGuard {
function commitBlock(
uint32 _blockNumber,
uint32 _feeAccount,
bytes32 _newRoot,
bytes32 _opTreeRootHash,
bytes32[] calldata _newRoots,
bytes calldata _publicData,
bytes calldata _ethWitness,
uint32[] calldata _ethWitnessSizes
Expand All @@ -307,6 +306,7 @@ contract ZkSync is UpgradeableMaster, Storage, Config, Events, ReentrancyGuard {
require(_blockNumber == totalBlocksCommitted + 1, "fck11"); // only commit next block
governance.requireActiveValidator(msg.sender);
require(!isBlockCommitmentExpired(), "fck12"); // committed blocks had expired
require(_newRoots.length == 1, "fck13"); // This version of the contract expects only account tree root hash

bytes memory publicData = _publicData;

Expand All @@ -319,7 +319,7 @@ contract ZkSync is UpgradeableMaster, Storage, Config, Events, ReentrancyGuard {

uint64 nPriorityRequestProcessed = totalCommittedPriorityRequests - prevTotalCommittedPriorityRequests;

createCommittedBlock(_blockNumber, _feeAccount, _newRoot, _opTreeRootHash, publicData, withdrawalsDataHash, nPriorityRequestProcessed);
createCommittedBlock(_blockNumber, _feeAccount, _newRoots[0], publicData, withdrawalsDataHash, nPriorityRequestProcessed);
totalBlocksCommitted++;

emit BlockCommit(_blockNumber);
Expand All @@ -332,7 +332,6 @@ contract ZkSync is UpgradeableMaster, Storage, Config, Events, ReentrancyGuard {
uint32 _blockNumber,
uint32 _feeAccount,
bytes32 _newRoot,
bytes32 _opTreeRootHash,
bytes memory _publicData,
bytes32 _withdrawalDataHash,
uint64 _nCommittedPriorityRequests
Expand All @@ -348,7 +347,6 @@ contract ZkSync is UpgradeableMaster, Storage, Config, Events, ReentrancyGuard {
_feeAccount,
blocks[_blockNumber - 1].stateRoot,
_newRoot,
_opTreeRootHash,
_publicData
);

Expand All @@ -358,8 +356,7 @@ contract ZkSync is UpgradeableMaster, Storage, Config, Events, ReentrancyGuard {
blockChunks,
_withdrawalDataHash, // hash of onchain withdrawals data (will be used during checking block withdrawal data in verifyBlock function)
commitment, // blocks' commitment
_newRoot, // new root
_opTreeRootHash // operations tree root hash
_newRoot // new root
);
}

Expand Down Expand Up @@ -527,15 +524,13 @@ contract ZkSync is UpgradeableMaster, Storage, Config, Events, ReentrancyGuard {
uint32 _feeAccount,
bytes32 _oldRoot,
bytes32 _newRoot,
bytes32 _opTreeRootHash,
bytes memory _publicData
) internal view returns (bytes32 commitment) {
bytes32 hash = sha256(
abi.encodePacked(uint256(_blockNumber), uint256(_feeAccount))
);
hash = sha256(abi.encodePacked(hash, uint256(_oldRoot)));
hash = sha256(abi.encodePacked(hash, uint256(_newRoot)));
hash = sha256(abi.encodePacked(hash, uint256(_opTreeRootHash)));

/// The code below is equivalent to `commitment = sha256(abi.encodePacked(hash, _publicData))`

Expand Down
7 changes: 0 additions & 7 deletions core/circuit/src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,6 @@ impl<'a, E: RescueEngine + JubjubEngine> Circuit<E> for FranklinCircuit<'a, E> {

hash_block = sha256::sha256(cs.namespace(|| "hash with new_root"), &pack_bits)?;

let mut pack_bits = vec![];
pack_bits.extend(hash_block);
pack_bits.extend(vec![Boolean::Constant(false); 256]); // TODO: now equals to zero -> should be fixed in #570

hash_block =
sha256::sha256(cs.namespace(|| "hash with op_tree_root_hash"), &pack_bits)?;

let mut pack_bits = vec![];
pack_bits.extend(hash_block);
pack_bits.extend(block_pub_data_bits.into_iter());
Expand Down
14 changes: 0 additions & 14 deletions core/circuit/src/witness/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,20 +353,6 @@ pub fn public_data_commitment<E: JubjubEngine>(

debug!("hash with new root as hex {}", hex::encode(hash_result));

let mut packed_with_op_tree_root_hash = vec![];
packed_with_op_tree_root_hash.extend(hash_result.iter());
packed_with_op_tree_root_hash.extend(&[0u8; 32]); // TODO: now equals to zero -> should be fixed in #570

h = Sha256::new();
h.input(&packed_with_op_tree_root_hash);
hash_result = [0u8; 32];
h.result(&mut hash_result[..]);

debug!(
"hash with op tree root hash as hex {}",
hex::encode(hash_result)
);

let mut final_bytes = vec![];
let pubdata_bytes = be_bit_vector_into_bytes(&pubdata_bits.to_vec());
final_bytes.extend(hash_result.iter());
Expand Down
16 changes: 8 additions & 8 deletions core/data_restore/src/rollup_ops.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::eth_tx_helpers::{get_ethereum_transaction, get_input_data_from_ethereum_transaction};
use crate::events::BlockEvent;
use ethabi::ParamType;
use models::node::operations::FranklinOp;
use web3::{Transport, Web3};

Expand Down Expand Up @@ -30,16 +31,15 @@ impl RollupOpsBlock {
let input_data = get_input_data_from_ethereum_transaction(&transaction)?;

let fee_account_argument_id = 1;
let public_data_argument_id = 4;
let public_data_argument_id = 3;
let decoded_commitment_parameters = ethabi::decode(
vec![
ethabi::ParamType::Uint(32), // uint32 _blockNumber,
ethabi::ParamType::Uint(24), // uint24 _feeAccount,
ethabi::ParamType::FixedBytes(32), // bytes32 _newRoot,
ethabi::ParamType::FixedBytes(32), // bytes32 _opTreeRootHash,
ethabi::ParamType::Bytes, // bytes calldata _publicData,
ethabi::ParamType::Bytes, // bytes calldata _ethWitness,
ethabi::ParamType::Array(Box::new(ethabi::ParamType::Uint(32))), // uint32[] calldata _ethWitnessSizes
ParamType::Uint(32), // uint32 _blockNumber,
ParamType::Uint(32), // uint32 _feeAccount,
ParamType::Array(Box::new(ParamType::FixedBytes(32))), // bytes32[] _newRoots,
ParamType::Bytes, // bytes calldata _publicData,
ParamType::Bytes, // bytes calldata _ethWitness,
ParamType::Array(Box::new(ParamType::Uint(32))), // uint32[] calldata _ethWitnessSizes
]
.as_slice(),
input_data.as_slice(),
Expand Down
5 changes: 1 addition & 4 deletions core/server/src/eth_sender/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,22 +636,19 @@ impl<ETH: EthereumInterface, DB: DatabaseAccess> ETHSender<ETH, DB> {
&witness_data.1
);

// function commitBlock(uint32 _blockNumber, uint24 _feeAccount, bytes32 _newRoot, bytes calldata _publicData)
self.ethereum.encode_tx_data(
"commitBlock",
(
u64::from(op.block.block_number),
u64::from(op.block.fee_account),
root,
H256([0u8; 32]), // TODO: now equals to zero -> should be fixed in #570
vec![root],
public_data,
witness_data.0,
witness_data.1,
),
)
}
Action::Verify { proof } => {
// function verifyBlock(uint32 _blockNumber, uint256[8] calldata _proof, bytes calldata _withdrawalsData)
let block_number = op.block.block_number;
let withdrawals_data = op.block.get_withdrawals_data();
self.ethereum.encode_tx_data(
Expand Down
3 changes: 1 addition & 2 deletions core/testkit/src/eth_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,7 @@ impl<T: Transport> EthereumAccount<T> {
(
u64::from(block.block_number),
u64::from(block.fee_account),
block.get_eth_encoded_root(),
H256([0u8; 32]), // TODO: now equals to zero -> should be fixed in #570
vec![block.get_eth_encoded_root()],
block.get_eth_public_data(),
witness_data.0,
witness_data.1,
Expand Down
2 changes: 1 addition & 1 deletion etc/env/dev.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ KUBECONFIG=""
BELLMAN_VERBOSE=1

# key dir ending with latest version of circuit commit hash
KEY_DIR=keys/plonk-adc439
KEY_DIR=keys/plonk-13931

# actual supported block chunks sizes by verifier contract (determined by circuit size on setup boundaries)
# and setup powe needed to proof block of this size
Expand Down

0 comments on commit eafc910

Please sign in to comment.