Correctly transform uint to uint256 and int to int256 for signatures.

This commit is contained in:
Richard Moore 2018-06-06 20:48:45 -04:00
parent 884593ab76
commit 6a8ca9c318
No known key found for this signature in database
GPG Key ID: 525F70A6FCABC295
10 changed files with 127 additions and 27 deletions

@ -4892,6 +4892,18 @@ var regexIdentifier = new RegExp("^[A-Za-z_][A-Za-z0-9_]*$");
var close = { "(": ")", "[": "]" }; 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 parseParam(param, allowIndexed) {
function throwError(i) { function throwError(i) {
throw new Error('unexpected character "' + param[i] + '" at position ' + i + ' in "' + param + '"'); throw new Error('unexpected character "' + param[i] + '" at position ' + i + ' in "' + param + '"');
@ -4906,12 +4918,15 @@ function parseParam(param, allowIndexed) {
case '(': case '(':
if (!node.state.allowParams) { throwError(i); } if (!node.state.allowParams) { throwError(i); }
delete node.state.allowType; delete node.state.allowType;
node.type = verifyType(node.type);
node.components = [ { type: '', name: '', parent: node, state: { allowType: true } } ]; node.components = [ { type: '', name: '', parent: node, state: { allowType: true } } ];
node = node.components[0]; node = node.components[0];
break; break;
case ')': case ')':
delete node.state; delete node.state;
node.type = verifyType(node.type);
var child = node; var child = node;
node = node.parent; node = node.parent;
if (!node) { throwError(i); } if (!node) { throwError(i); }
@ -4923,6 +4938,7 @@ function parseParam(param, allowIndexed) {
case ',': case ',':
delete node.state; delete node.state;
node.type = verifyType(node.type);
var sibling = { type: '', name: '', parent: node.parent, state: { allowType: true } }; var sibling = { type: '', name: '', parent: node.parent, state: { allowType: true } };
node.parent.components.push(sibling); node.parent.components.push(sibling);
@ -4936,6 +4952,7 @@ function parseParam(param, allowIndexed) {
// If reading type, the type is done and may read a param or name // If reading type, the type is done and may read a param or name
if (node.state.allowType) { if (node.state.allowType) {
if (node.type !== '') { if (node.type !== '') {
node.type = verifyType(node.type);
delete node.state.allowType; delete node.state.allowType;
node.state.allowName = true; node.state.allowName = true;
node.state.allowParams = true; node.state.allowParams = true;
@ -4999,6 +5016,9 @@ function parseParam(param, allowIndexed) {
if (node.parent) { throw new Error("unexpected eof"); } if (node.parent) { throw new Error("unexpected eof"); }
delete parent.state; delete parent.state;
parent.type = verifyType(parent.type);
//verifyType(parent);
return parent; return parent;
} }
@ -5197,8 +5217,8 @@ var uint256Coder = coderNumber(function(type, value) { return value; }, 32, fals
var coderBoolean = function(coerceFunc, localName) { var coderBoolean = function(coerceFunc, localName) {
return { return {
localName: localName, localName: localName,
name: 'boolean', name: 'bool',
type: 'boolean', type: 'bool',
encode: function(value) { encode: function(value) {
return uint256Coder.encode(!!value ? 1: 0); return uint256Coder.encode(!!value ? 1: 0);
}, },
@ -5658,6 +5678,7 @@ var paramTypeSimple = {
}; };
function getTupleParamCoder(coerceFunc, components, localName) { function getTupleParamCoder(coerceFunc, components, localName) {
if (!components) { components = []; }
var coders = []; var coders = [];
components.forEach(function(component) { components.forEach(function(component) {
coders.push(getParamCoder(coerceFunc, component)); coders.push(getParamCoder(coerceFunc, component));
@ -5667,7 +5688,6 @@ function getTupleParamCoder(coerceFunc, components, localName) {
} }
function getParamCoder(coerceFunc, param) { function getParamCoder(coerceFunc, param) {
var coder = paramTypeSimple[param.type]; var coder = paramTypeSimple[param.type];
if (coder) { return coder(coerceFunc, param.name); } if (coder) { return coder(coerceFunc, param.name); }

File diff suppressed because one or more lines are too long

26
dist/ethers-utils.js vendored

@ -5103,6 +5103,18 @@ var regexIdentifier = new RegExp("^[A-Za-z_][A-Za-z0-9_]*$");
var close = { "(": ")", "[": "]" }; 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 parseParam(param, allowIndexed) {
function throwError(i) { function throwError(i) {
throw new Error('unexpected character "' + param[i] + '" at position ' + i + ' in "' + param + '"'); throw new Error('unexpected character "' + param[i] + '" at position ' + i + ' in "' + param + '"');
@ -5117,12 +5129,15 @@ function parseParam(param, allowIndexed) {
case '(': case '(':
if (!node.state.allowParams) { throwError(i); } if (!node.state.allowParams) { throwError(i); }
delete node.state.allowType; delete node.state.allowType;
node.type = verifyType(node.type);
node.components = [ { type: '', name: '', parent: node, state: { allowType: true } } ]; node.components = [ { type: '', name: '', parent: node, state: { allowType: true } } ];
node = node.components[0]; node = node.components[0];
break; break;
case ')': case ')':
delete node.state; delete node.state;
node.type = verifyType(node.type);
var child = node; var child = node;
node = node.parent; node = node.parent;
if (!node) { throwError(i); } if (!node) { throwError(i); }
@ -5134,6 +5149,7 @@ function parseParam(param, allowIndexed) {
case ',': case ',':
delete node.state; delete node.state;
node.type = verifyType(node.type);
var sibling = { type: '', name: '', parent: node.parent, state: { allowType: true } }; var sibling = { type: '', name: '', parent: node.parent, state: { allowType: true } };
node.parent.components.push(sibling); node.parent.components.push(sibling);
@ -5147,6 +5163,7 @@ function parseParam(param, allowIndexed) {
// If reading type, the type is done and may read a param or name // If reading type, the type is done and may read a param or name
if (node.state.allowType) { if (node.state.allowType) {
if (node.type !== '') { if (node.type !== '') {
node.type = verifyType(node.type);
delete node.state.allowType; delete node.state.allowType;
node.state.allowName = true; node.state.allowName = true;
node.state.allowParams = true; node.state.allowParams = true;
@ -5210,6 +5227,9 @@ function parseParam(param, allowIndexed) {
if (node.parent) { throw new Error("unexpected eof"); } if (node.parent) { throw new Error("unexpected eof"); }
delete parent.state; delete parent.state;
parent.type = verifyType(parent.type);
//verifyType(parent);
return parent; return parent;
} }
@ -5408,8 +5428,8 @@ var uint256Coder = coderNumber(function(type, value) { return value; }, 32, fals
var coderBoolean = function(coerceFunc, localName) { var coderBoolean = function(coerceFunc, localName) {
return { return {
localName: localName, localName: localName,
name: 'boolean', name: 'bool',
type: 'boolean', type: 'bool',
encode: function(value) { encode: function(value) {
return uint256Coder.encode(!!value ? 1: 0); return uint256Coder.encode(!!value ? 1: 0);
}, },
@ -5869,6 +5889,7 @@ var paramTypeSimple = {
}; };
function getTupleParamCoder(coerceFunc, components, localName) { function getTupleParamCoder(coerceFunc, components, localName) {
if (!components) { components = []; }
var coders = []; var coders = [];
components.forEach(function(component) { components.forEach(function(component) {
coders.push(getParamCoder(coerceFunc, component)); coders.push(getParamCoder(coerceFunc, component));
@ -5878,7 +5899,6 @@ function getTupleParamCoder(coerceFunc, components, localName) {
} }
function getParamCoder(coerceFunc, param) { function getParamCoder(coerceFunc, param) {
var coder = paramTypeSimple[param.type]; var coder = paramTypeSimple[param.type];
if (coder) { return coder(coerceFunc, param.name); } if (coder) { return coder(coerceFunc, param.name); }

File diff suppressed because one or more lines are too long

26
dist/ethers-wallet.js vendored

@ -9107,6 +9107,18 @@ var regexIdentifier = new RegExp("^[A-Za-z_][A-Za-z0-9_]*$");
var close = { "(": ")", "[": "]" }; 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 parseParam(param, allowIndexed) {
function throwError(i) { function throwError(i) {
throw new Error('unexpected character "' + param[i] + '" at position ' + i + ' in "' + param + '"'); throw new Error('unexpected character "' + param[i] + '" at position ' + i + ' in "' + param + '"');
@ -9121,12 +9133,15 @@ function parseParam(param, allowIndexed) {
case '(': case '(':
if (!node.state.allowParams) { throwError(i); } if (!node.state.allowParams) { throwError(i); }
delete node.state.allowType; delete node.state.allowType;
node.type = verifyType(node.type);
node.components = [ { type: '', name: '', parent: node, state: { allowType: true } } ]; node.components = [ { type: '', name: '', parent: node, state: { allowType: true } } ];
node = node.components[0]; node = node.components[0];
break; break;
case ')': case ')':
delete node.state; delete node.state;
node.type = verifyType(node.type);
var child = node; var child = node;
node = node.parent; node = node.parent;
if (!node) { throwError(i); } if (!node) { throwError(i); }
@ -9138,6 +9153,7 @@ function parseParam(param, allowIndexed) {
case ',': case ',':
delete node.state; delete node.state;
node.type = verifyType(node.type);
var sibling = { type: '', name: '', parent: node.parent, state: { allowType: true } }; var sibling = { type: '', name: '', parent: node.parent, state: { allowType: true } };
node.parent.components.push(sibling); node.parent.components.push(sibling);
@ -9151,6 +9167,7 @@ function parseParam(param, allowIndexed) {
// If reading type, the type is done and may read a param or name // If reading type, the type is done and may read a param or name
if (node.state.allowType) { if (node.state.allowType) {
if (node.type !== '') { if (node.type !== '') {
node.type = verifyType(node.type);
delete node.state.allowType; delete node.state.allowType;
node.state.allowName = true; node.state.allowName = true;
node.state.allowParams = true; node.state.allowParams = true;
@ -9214,6 +9231,9 @@ function parseParam(param, allowIndexed) {
if (node.parent) { throw new Error("unexpected eof"); } if (node.parent) { throw new Error("unexpected eof"); }
delete parent.state; delete parent.state;
parent.type = verifyType(parent.type);
//verifyType(parent);
return parent; return parent;
} }
@ -9412,8 +9432,8 @@ var uint256Coder = coderNumber(function(type, value) { return value; }, 32, fals
var coderBoolean = function(coerceFunc, localName) { var coderBoolean = function(coerceFunc, localName) {
return { return {
localName: localName, localName: localName,
name: 'boolean', name: 'bool',
type: 'boolean', type: 'bool',
encode: function(value) { encode: function(value) {
return uint256Coder.encode(!!value ? 1: 0); return uint256Coder.encode(!!value ? 1: 0);
}, },
@ -9873,6 +9893,7 @@ var paramTypeSimple = {
}; };
function getTupleParamCoder(coerceFunc, components, localName) { function getTupleParamCoder(coerceFunc, components, localName) {
if (!components) { components = []; }
var coders = []; var coders = [];
components.forEach(function(component) { components.forEach(function(component) {
coders.push(getParamCoder(coerceFunc, component)); coders.push(getParamCoder(coerceFunc, component));
@ -9882,7 +9903,6 @@ function getTupleParamCoder(coerceFunc, components, localName) {
} }
function getParamCoder(coerceFunc, param) { function getParamCoder(coerceFunc, param) {
var coder = paramTypeSimple[param.type]; var coder = paramTypeSimple[param.type];
if (coder) { return coder(coerceFunc, param.name); } if (coder) { return coder(coerceFunc, param.name); }

File diff suppressed because one or more lines are too long

28
dist/ethers.js vendored

@ -9837,7 +9837,7 @@ uuid.unparse = unparse;
module.exports = uuid; module.exports = uuid;
},{"./rng":43}],45:[function(require,module,exports){ },{"./rng":43}],45:[function(require,module,exports){
module.exports={"version":"3.0.20"} module.exports={"version":"3.0.21"}
},{}],46:[function(require,module,exports){ },{}],46:[function(require,module,exports){
'use strict'; 'use strict';
@ -11967,6 +11967,18 @@ var regexIdentifier = new RegExp("^[A-Za-z_][A-Za-z0-9_]*$");
var close = { "(": ")", "[": "]" }; 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 parseParam(param, allowIndexed) {
function throwError(i) { function throwError(i) {
throw new Error('unexpected character "' + param[i] + '" at position ' + i + ' in "' + param + '"'); throw new Error('unexpected character "' + param[i] + '" at position ' + i + ' in "' + param + '"');
@ -11981,12 +11993,15 @@ function parseParam(param, allowIndexed) {
case '(': case '(':
if (!node.state.allowParams) { throwError(i); } if (!node.state.allowParams) { throwError(i); }
delete node.state.allowType; delete node.state.allowType;
node.type = verifyType(node.type);
node.components = [ { type: '', name: '', parent: node, state: { allowType: true } } ]; node.components = [ { type: '', name: '', parent: node, state: { allowType: true } } ];
node = node.components[0]; node = node.components[0];
break; break;
case ')': case ')':
delete node.state; delete node.state;
node.type = verifyType(node.type);
var child = node; var child = node;
node = node.parent; node = node.parent;
if (!node) { throwError(i); } if (!node) { throwError(i); }
@ -11998,6 +12013,7 @@ function parseParam(param, allowIndexed) {
case ',': case ',':
delete node.state; delete node.state;
node.type = verifyType(node.type);
var sibling = { type: '', name: '', parent: node.parent, state: { allowType: true } }; var sibling = { type: '', name: '', parent: node.parent, state: { allowType: true } };
node.parent.components.push(sibling); node.parent.components.push(sibling);
@ -12011,6 +12027,7 @@ function parseParam(param, allowIndexed) {
// If reading type, the type is done and may read a param or name // If reading type, the type is done and may read a param or name
if (node.state.allowType) { if (node.state.allowType) {
if (node.type !== '') { if (node.type !== '') {
node.type = verifyType(node.type);
delete node.state.allowType; delete node.state.allowType;
node.state.allowName = true; node.state.allowName = true;
node.state.allowParams = true; node.state.allowParams = true;
@ -12074,6 +12091,9 @@ function parseParam(param, allowIndexed) {
if (node.parent) { throw new Error("unexpected eof"); } if (node.parent) { throw new Error("unexpected eof"); }
delete parent.state; delete parent.state;
parent.type = verifyType(parent.type);
//verifyType(parent);
return parent; return parent;
} }
@ -12272,8 +12292,8 @@ var uint256Coder = coderNumber(function(type, value) { return value; }, 32, fals
var coderBoolean = function(coerceFunc, localName) { var coderBoolean = function(coerceFunc, localName) {
return { return {
localName: localName, localName: localName,
name: 'boolean', name: 'bool',
type: 'boolean', type: 'bool',
encode: function(value) { encode: function(value) {
return uint256Coder.encode(!!value ? 1: 0); return uint256Coder.encode(!!value ? 1: 0);
}, },
@ -12733,6 +12753,7 @@ var paramTypeSimple = {
}; };
function getTupleParamCoder(coerceFunc, components, localName) { function getTupleParamCoder(coerceFunc, components, localName) {
if (!components) { components = []; }
var coders = []; var coders = [];
components.forEach(function(component) { components.forEach(function(component) {
coders.push(getParamCoder(coerceFunc, component)); coders.push(getParamCoder(coerceFunc, component));
@ -12742,7 +12763,6 @@ function getTupleParamCoder(coerceFunc, components, localName) {
} }
function getParamCoder(coerceFunc, param) { function getParamCoder(coerceFunc, param) {
var coder = paramTypeSimple[param.type]; var coder = paramTypeSimple[param.type];
if (coder) { return coder(coerceFunc, param.name); } if (coder) { return coder(coerceFunc, param.name); }

8
dist/ethers.min.js vendored

File diff suppressed because one or more lines are too long

@ -1,6 +1,6 @@
{ {
"name": "ethers", "name": "ethers",
"version": "3.0.20", "version": "3.0.21",
"description": "Ethereum wallet library.", "description": "Ethereum wallet library.",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {

@ -46,6 +46,18 @@ var regexIdentifier = new RegExp("^[A-Za-z_][A-Za-z0-9_]*$");
var close = { "(": ")", "[": "]" }; 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 parseParam(param, allowIndexed) {
function throwError(i) { function throwError(i) {
throw new Error('unexpected character "' + param[i] + '" at position ' + i + ' in "' + param + '"'); throw new Error('unexpected character "' + param[i] + '" at position ' + i + ' in "' + param + '"');
@ -60,12 +72,15 @@ function parseParam(param, allowIndexed) {
case '(': case '(':
if (!node.state.allowParams) { throwError(i); } if (!node.state.allowParams) { throwError(i); }
delete node.state.allowType; delete node.state.allowType;
node.type = verifyType(node.type);
node.components = [ { type: '', name: '', parent: node, state: { allowType: true } } ]; node.components = [ { type: '', name: '', parent: node, state: { allowType: true } } ];
node = node.components[0]; node = node.components[0];
break; break;
case ')': case ')':
delete node.state; delete node.state;
node.type = verifyType(node.type);
var child = node; var child = node;
node = node.parent; node = node.parent;
if (!node) { throwError(i); } if (!node) { throwError(i); }
@ -77,6 +92,7 @@ function parseParam(param, allowIndexed) {
case ',': case ',':
delete node.state; delete node.state;
node.type = verifyType(node.type);
var sibling = { type: '', name: '', parent: node.parent, state: { allowType: true } }; var sibling = { type: '', name: '', parent: node.parent, state: { allowType: true } };
node.parent.components.push(sibling); node.parent.components.push(sibling);
@ -90,6 +106,7 @@ function parseParam(param, allowIndexed) {
// If reading type, the type is done and may read a param or name // If reading type, the type is done and may read a param or name
if (node.state.allowType) { if (node.state.allowType) {
if (node.type !== '') { if (node.type !== '') {
node.type = verifyType(node.type);
delete node.state.allowType; delete node.state.allowType;
node.state.allowName = true; node.state.allowName = true;
node.state.allowParams = true; node.state.allowParams = true;
@ -153,6 +170,9 @@ function parseParam(param, allowIndexed) {
if (node.parent) { throw new Error("unexpected eof"); } if (node.parent) { throw new Error("unexpected eof"); }
delete parent.state; delete parent.state;
parent.type = verifyType(parent.type);
//verifyType(parent);
return parent; return parent;
} }
@ -351,8 +371,8 @@ var uint256Coder = coderNumber(function(type, value) { return value; }, 32, fals
var coderBoolean = function(coerceFunc, localName) { var coderBoolean = function(coerceFunc, localName) {
return { return {
localName: localName, localName: localName,
name: 'boolean', name: 'bool',
type: 'boolean', type: 'bool',
encode: function(value) { encode: function(value) {
return uint256Coder.encode(!!value ? 1: 0); return uint256Coder.encode(!!value ? 1: 0);
}, },
@ -812,6 +832,7 @@ var paramTypeSimple = {
}; };
function getTupleParamCoder(coerceFunc, components, localName) { function getTupleParamCoder(coerceFunc, components, localName) {
if (!components) { components = []; }
var coders = []; var coders = [];
components.forEach(function(component) { components.forEach(function(component) {
coders.push(getParamCoder(coerceFunc, component)); coders.push(getParamCoder(coerceFunc, component));
@ -821,7 +842,6 @@ function getTupleParamCoder(coerceFunc, components, localName) {
} }
function getParamCoder(coerceFunc, param) { function getParamCoder(coerceFunc, param) {
var coder = paramTypeSimple[param.type]; var coder = paramTypeSimple[param.type];
if (coder) { return coder(coerceFunc, param.name); } if (coder) { return coder(coerceFunc, param.name); }