Skip to content

Commit

Permalink
Correctly transform uint to uint256 and int to int256 for signatures.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Jun 7, 2018
1 parent 884593a commit 6a8ca9c
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 27 deletions.
26 changes: 23 additions & 3 deletions dist/ethers-contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -4892,6 +4892,18 @@ var regexIdentifier = new RegExp("^[A-Za-z_][A-Za-z0-9_]*$");

var close = { "(": ")", "[": "]" };

function verifyType(type) {

// These need to be transformed to their full description
if (type.match(/^uint($|[^1-9])/)) {
type = 'uint256' + type.substring(4);
} else if (type.match(/^int($|[^1-9])/)) {
type = 'int256' + type.substring(3);
}

return type;
}

function parseParam(param, allowIndexed) {
function throwError(i) {
throw new Error('unexpected character "' + param[i] + '" at position ' + i + ' in "' + param + '"');
Expand All @@ -4906,12 +4918,15 @@ function parseParam(param, allowIndexed) {
case '(':
if (!node.state.allowParams) { throwError(i); }
delete node.state.allowType;
node.type = verifyType(node.type);
node.components = [ { type: '', name: '', parent: node, state: { allowType: true } } ];
node = node.components[0];
break;

case ')':
delete node.state;
node.type = verifyType(node.type);

var child = node;
node = node.parent;
if (!node) { throwError(i); }
Expand All @@ -4923,6 +4938,7 @@ function parseParam(param, allowIndexed) {

case ',':
delete node.state;
node.type = verifyType(node.type);

var sibling = { type: '', name: '', parent: node.parent, state: { allowType: true } };
node.parent.components.push(sibling);
Expand All @@ -4936,6 +4952,7 @@ function parseParam(param, allowIndexed) {
// If reading type, the type is done and may read a param or name
if (node.state.allowType) {
if (node.type !== '') {
node.type = verifyType(node.type);
delete node.state.allowType;
node.state.allowName = true;
node.state.allowParams = true;
Expand Down Expand Up @@ -4999,6 +5016,9 @@ function parseParam(param, allowIndexed) {
if (node.parent) { throw new Error("unexpected eof"); }

delete parent.state;
parent.type = verifyType(parent.type);

//verifyType(parent);

return parent;
}
Expand Down Expand Up @@ -5197,8 +5217,8 @@ var uint256Coder = coderNumber(function(type, value) { return value; }, 32, fals
var coderBoolean = function(coerceFunc, localName) {
return {
localName: localName,
name: 'boolean',
type: 'boolean',
name: 'bool',
type: 'bool',
encode: function(value) {
return uint256Coder.encode(!!value ? 1: 0);
},
Expand Down Expand Up @@ -5658,6 +5678,7 @@ var paramTypeSimple = {
};

function getTupleParamCoder(coerceFunc, components, localName) {
if (!components) { components = []; }
var coders = [];
components.forEach(function(component) {
coders.push(getParamCoder(coerceFunc, component));
Expand All @@ -5667,7 +5688,6 @@ function getTupleParamCoder(coerceFunc, components, localName) {
}

function getParamCoder(coerceFunc, param) {

var coder = paramTypeSimple[param.type];
if (coder) { return coder(coerceFunc, param.name); }

Expand Down
4 changes: 2 additions & 2 deletions dist/ethers-contracts.min.js

Large diffs are not rendered by default.

26 changes: 23 additions & 3 deletions dist/ethers-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5103,6 +5103,18 @@ var regexIdentifier = new RegExp("^[A-Za-z_][A-Za-z0-9_]*$");

var close = { "(": ")", "[": "]" };

function verifyType(type) {

// These need to be transformed to their full description
if (type.match(/^uint($|[^1-9])/)) {
type = 'uint256' + type.substring(4);
} else if (type.match(/^int($|[^1-9])/)) {
type = 'int256' + type.substring(3);
}

return type;
}

function parseParam(param, allowIndexed) {
function throwError(i) {
throw new Error('unexpected character "' + param[i] + '" at position ' + i + ' in "' + param + '"');
Expand All @@ -5117,12 +5129,15 @@ function parseParam(param, allowIndexed) {
case '(':
if (!node.state.allowParams) { throwError(i); }
delete node.state.allowType;
node.type = verifyType(node.type);
node.components = [ { type: '', name: '', parent: node, state: { allowType: true } } ];
node = node.components[0];
break;

case ')':
delete node.state;
node.type = verifyType(node.type);

var child = node;
node = node.parent;
if (!node) { throwError(i); }
Expand All @@ -5134,6 +5149,7 @@ function parseParam(param, allowIndexed) {

case ',':
delete node.state;
node.type = verifyType(node.type);

var sibling = { type: '', name: '', parent: node.parent, state: { allowType: true } };
node.parent.components.push(sibling);
Expand All @@ -5147,6 +5163,7 @@ function parseParam(param, allowIndexed) {
// If reading type, the type is done and may read a param or name
if (node.state.allowType) {
if (node.type !== '') {
node.type = verifyType(node.type);
delete node.state.allowType;
node.state.allowName = true;
node.state.allowParams = true;
Expand Down Expand Up @@ -5210,6 +5227,9 @@ function parseParam(param, allowIndexed) {
if (node.parent) { throw new Error("unexpected eof"); }

delete parent.state;
parent.type = verifyType(parent.type);

//verifyType(parent);

return parent;
}
Expand Down Expand Up @@ -5408,8 +5428,8 @@ var uint256Coder = coderNumber(function(type, value) { return value; }, 32, fals
var coderBoolean = function(coerceFunc, localName) {
return {
localName: localName,
name: 'boolean',
type: 'boolean',
name: 'bool',
type: 'bool',
encode: function(value) {
return uint256Coder.encode(!!value ? 1: 0);
},
Expand Down Expand Up @@ -5869,6 +5889,7 @@ var paramTypeSimple = {
};

function getTupleParamCoder(coerceFunc, components, localName) {
if (!components) { components = []; }
var coders = [];
components.forEach(function(component) {
coders.push(getParamCoder(coerceFunc, component));
Expand All @@ -5878,7 +5899,6 @@ function getTupleParamCoder(coerceFunc, components, localName) {
}

function getParamCoder(coerceFunc, param) {

var coder = paramTypeSimple[param.type];
if (coder) { return coder(coerceFunc, param.name); }

Expand Down
2 changes: 1 addition & 1 deletion dist/ethers-utils.min.js

Large diffs are not rendered by default.

26 changes: 23 additions & 3 deletions dist/ethers-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -9107,6 +9107,18 @@ var regexIdentifier = new RegExp("^[A-Za-z_][A-Za-z0-9_]*$");

var close = { "(": ")", "[": "]" };

function verifyType(type) {

// These need to be transformed to their full description
if (type.match(/^uint($|[^1-9])/)) {
type = 'uint256' + type.substring(4);
} else if (type.match(/^int($|[^1-9])/)) {
type = 'int256' + type.substring(3);
}

return type;
}

function parseParam(param, allowIndexed) {
function throwError(i) {
throw new Error('unexpected character "' + param[i] + '" at position ' + i + ' in "' + param + '"');
Expand All @@ -9121,12 +9133,15 @@ function parseParam(param, allowIndexed) {
case '(':
if (!node.state.allowParams) { throwError(i); }
delete node.state.allowType;
node.type = verifyType(node.type);
node.components = [ { type: '', name: '', parent: node, state: { allowType: true } } ];
node = node.components[0];
break;

case ')':
delete node.state;
node.type = verifyType(node.type);

var child = node;
node = node.parent;
if (!node) { throwError(i); }
Expand All @@ -9138,6 +9153,7 @@ function parseParam(param, allowIndexed) {

case ',':
delete node.state;
node.type = verifyType(node.type);

var sibling = { type: '', name: '', parent: node.parent, state: { allowType: true } };
node.parent.components.push(sibling);
Expand All @@ -9151,6 +9167,7 @@ function parseParam(param, allowIndexed) {
// If reading type, the type is done and may read a param or name
if (node.state.allowType) {
if (node.type !== '') {
node.type = verifyType(node.type);
delete node.state.allowType;
node.state.allowName = true;
node.state.allowParams = true;
Expand Down Expand Up @@ -9214,6 +9231,9 @@ function parseParam(param, allowIndexed) {
if (node.parent) { throw new Error("unexpected eof"); }

delete parent.state;
parent.type = verifyType(parent.type);

//verifyType(parent);

return parent;
}
Expand Down Expand Up @@ -9412,8 +9432,8 @@ var uint256Coder = coderNumber(function(type, value) { return value; }, 32, fals
var coderBoolean = function(coerceFunc, localName) {
return {
localName: localName,
name: 'boolean',
type: 'boolean',
name: 'bool',
type: 'bool',
encode: function(value) {
return uint256Coder.encode(!!value ? 1: 0);
},
Expand Down Expand Up @@ -9873,6 +9893,7 @@ var paramTypeSimple = {
};

function getTupleParamCoder(coerceFunc, components, localName) {
if (!components) { components = []; }
var coders = [];
components.forEach(function(component) {
coders.push(getParamCoder(coerceFunc, component));
Expand All @@ -9882,7 +9903,6 @@ function getTupleParamCoder(coerceFunc, components, localName) {
}

function getParamCoder(coerceFunc, param) {

var coder = paramTypeSimple[param.type];
if (coder) { return coder(coerceFunc, param.name); }

Expand Down
6 changes: 3 additions & 3 deletions dist/ethers-wallet.min.js

Large diffs are not rendered by default.

28 changes: 24 additions & 4 deletions dist/ethers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9837,7 +9837,7 @@ uuid.unparse = unparse;
module.exports = uuid;

},{"./rng":43}],45:[function(require,module,exports){
module.exports={"version":"3.0.20"}
module.exports={"version":"3.0.21"}
},{}],46:[function(require,module,exports){
'use strict';

Expand Down Expand Up @@ -11967,6 +11967,18 @@ var regexIdentifier = new RegExp("^[A-Za-z_][A-Za-z0-9_]*$");

var close = { "(": ")", "[": "]" };

function verifyType(type) {

// These need to be transformed to their full description
if (type.match(/^uint($|[^1-9])/)) {
type = 'uint256' + type.substring(4);
} else if (type.match(/^int($|[^1-9])/)) {
type = 'int256' + type.substring(3);
}

return type;
}

function parseParam(param, allowIndexed) {
function throwError(i) {
throw new Error('unexpected character "' + param[i] + '" at position ' + i + ' in "' + param + '"');
Expand All @@ -11981,12 +11993,15 @@ function parseParam(param, allowIndexed) {
case '(':
if (!node.state.allowParams) { throwError(i); }
delete node.state.allowType;
node.type = verifyType(node.type);
node.components = [ { type: '', name: '', parent: node, state: { allowType: true } } ];
node = node.components[0];
break;

case ')':
delete node.state;
node.type = verifyType(node.type);

var child = node;
node = node.parent;
if (!node) { throwError(i); }
Expand All @@ -11998,6 +12013,7 @@ function parseParam(param, allowIndexed) {

case ',':
delete node.state;
node.type = verifyType(node.type);

var sibling = { type: '', name: '', parent: node.parent, state: { allowType: true } };
node.parent.components.push(sibling);
Expand All @@ -12011,6 +12027,7 @@ function parseParam(param, allowIndexed) {
// If reading type, the type is done and may read a param or name
if (node.state.allowType) {
if (node.type !== '') {
node.type = verifyType(node.type);
delete node.state.allowType;
node.state.allowName = true;
node.state.allowParams = true;
Expand Down Expand Up @@ -12074,6 +12091,9 @@ function parseParam(param, allowIndexed) {
if (node.parent) { throw new Error("unexpected eof"); }

delete parent.state;
parent.type = verifyType(parent.type);

//verifyType(parent);

return parent;
}
Expand Down Expand Up @@ -12272,8 +12292,8 @@ var uint256Coder = coderNumber(function(type, value) { return value; }, 32, fals
var coderBoolean = function(coerceFunc, localName) {
return {
localName: localName,
name: 'boolean',
type: 'boolean',
name: 'bool',
type: 'bool',
encode: function(value) {
return uint256Coder.encode(!!value ? 1: 0);
},
Expand Down Expand Up @@ -12733,6 +12753,7 @@ var paramTypeSimple = {
};

function getTupleParamCoder(coerceFunc, components, localName) {
if (!components) { components = []; }
var coders = [];
components.forEach(function(component) {
coders.push(getParamCoder(coerceFunc, component));
Expand All @@ -12742,7 +12763,6 @@ function getTupleParamCoder(coerceFunc, components, localName) {
}

function getParamCoder(coerceFunc, param) {

var coder = paramTypeSimple[param.type];
if (coder) { return coder(coerceFunc, param.name); }

Expand Down
8 changes: 4 additions & 4 deletions dist/ethers.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ethers",
"version": "3.0.20",
"version": "3.0.21",
"description": "Ethereum wallet library.",
"main": "index.js",
"scripts": {
Expand Down
Loading

0 comments on commit 6a8ca9c

Please sign in to comment.