add domain separator to redeem code

This commit is contained in:
Andrea Franz 2020-10-05 14:25:17 +02:00
parent 43c40a0618
commit ee9b14fc29
No known key found for this signature in database
GPG Key ID: 4F0D2F2D9DE7F29D
5 changed files with 14 additions and 10 deletions

View File

@ -13,7 +13,7 @@ abstract contract Bucket is OwnableUpgradeSafe {
bytes32 constant REDEEM_TYPEHASH = keccak256("Redeem(uint256 blockNumber,bytes32 blockHash,address receiver,bytes32 code)");
bytes32 constant EIP712DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
bytes32 DOMAIN_SEPARATOR;
bytes32 public DOMAIN_SEPARATOR;
string _relayerURI;
@ -86,7 +86,7 @@ abstract contract Bucket is OwnableUpgradeSafe {
require(redeemable.recipient == recipient, "not found");
// validate code
bytes32 codeHash = keccak256(abi.encodePacked(_redeem.code));
bytes32 codeHash = keccak256(abi.encodePacked(DOMAIN_SEPARATOR, redeemable.recipient, _redeem.code));
require(codeHash == redeemable.code, "invalid code");
uint256 data = redeemable.data;

View File

@ -9,7 +9,7 @@ module.exports = function(deployer, network) {
deployer.deploy(NFTBucketFactory);
deployer.deploy(ERC20BucketFactory);
if (network === "development") {
if (network === "development" || network === "test") {
deployer.deploy(TestToken, "Dev Test Token", "DTT", 18);
deployer.deploy(TestNFT);
}

View File

@ -86,6 +86,7 @@ function mineAt(timestamp) {
contract("ERC20Bucket", function () {
let bucketInstance,
domainSeparator,
factoryInstance,
tokenInstance,
shop,
@ -134,6 +135,7 @@ contract("ERC20Bucket", function () {
});
bucketInstance = new web3.eth.Contract(ERC20Bucket.abi, rec.options.address);
domainSeparator = await bucketInstance.methods.DOMAIN_SEPARATOR().call();
});
it("deploy bucket via factory", async () => {
@ -196,7 +198,7 @@ contract("ERC20Bucket", function () {
let initialSupply = await bucketInstance.methods.totalSupply().call();
let initialAvailableSupply = await bucketInstance.methods.availableSupply().call();
const redeemCodeHash = web3.utils.sha3(REDEEM_CODE);
const redeemCodeHash = web3.utils.soliditySha3(domainSeparator, keycard, REDEEM_CODE);
const createRedeemable = bucketInstance.methods.createRedeemable(keycard, amount, redeemCodeHash);
const createRedeemableGas = await createRedeemable.estimateGas();
await createRedeemable.send({

View File

@ -91,6 +91,7 @@ if (assert.match === undefined) {
contract("NFTBucket", function () {
let bucketInstance,
domainSeparator,
factoryInstance,
tokenInstance,
shop,
@ -141,6 +142,7 @@ contract("NFTBucket", function () {
});
bucketInstance = new web3.eth.Contract(NFTBucket.abi, rec.options.address);
domainSeparator = await bucketInstance.methods.DOMAIN_SEPARATOR().call();
});
it("deploy bucket via factory", async () => {
@ -159,7 +161,7 @@ contract("NFTBucket", function () {
function createRedeemableData(recipient) {
const redeemCodeHash = web3.utils.sha3(REDEEM_CODE);
const redeemCodeHash = web3.utils.soliditySha3(domainSeparator, recipient, REDEEM_CODE);
return recipient + redeemCodeHash.replace("0x", "");
}

View File

@ -45,11 +45,11 @@ module.exports = {
// tab if you use this network and you must also set the `host`, `port` and `network_id`
// options below to some value.
//
development: {
host: "127.0.0.1", // Localhost (default: none)
port: 7545, // Standard Ethereum port (default: none)
network_id: "*", // Any network (default: none)
},
// development: {
// host: "127.0.0.1", // Localhost (default: none)
// port: 7545, // Standard Ethereum port (default: none)
// network_id: "*", // Any network (default: none)
// },
// Another network with more advanced options...
// advanced: {