Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

merge ZSL patch #6

Merged
merged 1 commit into from
Dec 20, 2018
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
21 changes: 14 additions & 7 deletions contracts/ZSLPrecompile.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,17 @@ contract ZSLPrecompileSHA256Compress {
/**
@title Abstract contract for built-in function
*/
contract ZSLPrecompileVerify {
contract ZSLPrecompileVerifyShielding {
function run(bytes, bytes32, bytes32, uint64) constant returns (bytes32);
}

/**
@title Abstract contract for built-in function
*/
contract ZSLPrecompileVerifyUnshielding {
function run(bytes, bytes32, bytes32, address, uint64) constant returns (bytes32);
}

/**
@title Abstract contract for built-in function
*/
Expand All @@ -42,15 +49,15 @@ contract ZSLPrecompile {

ZSLPrecompileSHA256Compress private compressContract;
ZSLPrecompileVerifyTransfer private verifyShieldedTransferContract;
ZSLPrecompileVerify private verifyShieldingContract;
ZSLPrecompileVerify private verifyUnshieldingContract;
ZSLPrecompileVerifyShielding private verifyShieldingContract;
ZSLPrecompileVerifyUnshielding private verifyUnshieldingContract;

// @dev Address of precompiles must match those in the Geth/Quorum client
function ZSLPrecompile() {
compressContract = ZSLPrecompileSHA256Compress(0x0000000000000000000000000000000000008801);
verifyShieldedTransferContract = ZSLPrecompileVerifyTransfer(0x0000000000000000000000000000000000008802);
verifyShieldingContract = ZSLPrecompileVerify(0x0000000000000000000000000000000000008803);
verifyUnshieldingContract = ZSLPrecompileVerify(0x0000000000000000000000000000000000008804);
verifyShieldingContract = ZSLPrecompileVerifyShielding(0x0000000000000000000000000000000000008803);
verifyUnshieldingContract = ZSLPrecompileVerifyUnshielding(0x0000000000000000000000000000000000008804);
}

// @param input Input data block must be 64 bytes (512 bits) in length
Expand Down Expand Up @@ -98,8 +105,8 @@ contract ZSLPrecompile {


// @param input The ZK Proof to verify
function verifyUnshielding(bytes proof, bytes32 spend_nf, bytes32 rt, uint64 value) constant external returns (bool) {
bytes32 buffer = verifyUnshieldingContract.run(proof, spend_nf, rt, value);
function verifyUnshielding(bytes proof, bytes32 spend_nf, bytes32 rt, address addr, uint64 value) constant external returns (bool) {
bytes32 buffer = verifyUnshieldingContract.run(proof, spend_nf, rt, addr, value);
byte b = buffer[0];
if (b == 0x00) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion contracts/ZTokenExample.sol
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ contract ZToken is owned, SafeMath, ZSLMerkleTree {
function unshield(bytes proof, bytes32 spend_nf, bytes32 cm, bytes32 rt, uint64 value) public {
require(mapNullifiers[spend_nf] == 0); // check if nullifier has been used before
require(commitmentExists(cm));
assert(zsl.verifyUnshielding(proof, spend_nf, rt, value)); // verfy proof
assert(zsl.verifyUnshielding(proof, spend_nf, rt, msg.sender, value)); // verfy proof
mapNullifiers[spend_nf] = 1;
balanceOf[msg.sender] = safeAdd(balanceOf[msg.sender], value); // check for overflow
LogUnshielding(msg.sender, value, sha3(cm));
Expand Down