Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

112 bit transaction value to enable full 18 decimal place range with large integer part #608

Merged
merged 13 commits into from
Apr 21, 2022
Merged
6 changes: 2 additions & 4 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
node_modules/*
cd node_modules/*
**/node_modules/*
**/migrations/*
**/doc/*
cli/build/*
wallet/src/index.js
wallet/cli/*
test/adversary/nightfall-adversary/*
wallet/build
wallet/**
/**/*.d.ts
2 changes: 1 addition & 1 deletion common-files/classes/transaction.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function keccak(preimage) {
const web3 = Web3.connection();
// compute the solidity hash, using suitable type conversions
return web3.utils.soliditySha3(
{ t: 'uint64', v: preimage.value },
{ t: 'uint112', v: preimage.value },
...preimage.historicRootBlockNumberL2.map(hi => ({ t: 'uint256', v: hi })),
{ t: 'uint8', v: preimage.transactionType },
{ t: 'uint8', v: preimage.tokenType },
Expand Down
4 changes: 2 additions & 2 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ module.exports = {
TRANSACTIONS_PER_BLOCK: Number(process.env.TRANSACTIONS_PER_BLOCK) || 2,
PROPOSE_BLOCK_TYPES: [
'(uint48,address,bytes32,uint256,bytes32)',
'(uint64,uint64[2],uint8,uint8,bytes32,bytes32,bytes32,bytes32[2],bytes32[2],bytes32[8],uint[4])[]',
'(uint112,uint64[2],uint8,uint8,bytes32,bytes32,bytes32,bytes32[2],bytes32[2],bytes32[8],uint[4])[]',
], // used to encode/decode proposeBlock signature
SUBMIT_TRANSACTION_TYPES:
'(uint64,uint64[2],uint8,uint8,bytes32,bytes32,bytes32,bytes32[2],bytes32[2],bytes32[8],uint[4])',
'(uint112,uint64[2],uint8,uint8,bytes32,bytes32,bytes32,bytes32[2],bytes32[2],bytes32[8],uint[4])',
RETRIES: Number(process.env.AUTOSTART_RETRIES) || 50,
NODE_HASHLENGTH: 32,
ZERO: '0x0000000000000000000000000000000000000000000000000000000000000000',
Expand Down
2 changes: 1 addition & 1 deletion nightfall-deployer/contracts/Structures.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ contract Structures {
// will hold default values for any specific tranaction, e.g. there are no
// nullifiers for a Deposit transaction.
struct Transaction {
uint64 value;
uint112 value;
uint64[2] historicRootBlockNumberL2; // number of L2 block containing historic root
TransactionTypes transactionType;
TokenType tokenType;
Expand Down
12 changes: 5 additions & 7 deletions nightfall-optimist/src/routes/proposer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -358,20 +358,18 @@ router.post('/offchain-transaction', async (req, res) => {
// When a transaction is built by client, they are generalised into hex(32) interfacing with web3
// The response from on-chain events converts them to saner string values (e.g. uint64 etc).
// Since we do the transfer off-chain, we do the conversation manually here.
const { transactionType, tokenType, value, historicRootBlockNumberL2, fee, ...tx } = transaction;
const { transactionType, fee } = transaction;
try {
switch (Number(transactionType)) {
case 1:
case 2:
case 3: {
// When comparing this with getTransactionSubmittedCalldata,
// note we dont need to decompressProof as proofs are only compressed if they go on-chain.
await transactionSubmittedEventHandler({
offchain: true,
transactionType: Number(transactionType).toString(),
tokenType: Number(tokenType).toString(),
value: Number(value).toString(),
fee: Number(fee).toString(),
historicRootBlockNumberL2: historicRootBlockNumberL2.map(h => Number(h).toString()),
...tx,
...transaction,
fee: Number(fee),
});
res.sendStatus(200);
break;
Expand Down
8 changes: 4 additions & 4 deletions nightfall-optimist/src/services/transaction-checker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async function checkTransactionType(transaction) {
if (
(Number(transaction.tokenType) !== 0 &&
transaction.tokenId === ZERO &&
Number(transaction.value) === 0) ||
BigInt(transaction.value) === 0n) ||
transaction.ercAddress === ZERO ||
transaction.recipientAddress !== ZERO ||
transaction.commitments[0] === ZERO ||
Expand All @@ -58,7 +58,7 @@ async function checkTransactionType(transaction) {
case 1: // single token transaction
if (
transaction.tokenId !== ZERO ||
Number(transaction.value) !== 0 ||
BigInt(transaction.value) !== 0n ||
transaction.ercAddress !== ZERO ||
transaction.recipientAddress !== ZERO ||
transaction.commitments[0] === ZERO ||
Expand All @@ -79,7 +79,7 @@ async function checkTransactionType(transaction) {
case 2: // double token transaction
if (
transaction.tokenId !== ZERO ||
Number(transaction.value) !== 0 ||
BigInt(transaction.value) !== 0n ||
transaction.ercAddress !== ZERO ||
transaction.recipientAddress !== ZERO ||
transaction.commitments.some(c => c === ZERO) ||
Expand All @@ -100,7 +100,7 @@ async function checkTransactionType(transaction) {
if (
(Number(transaction.tokenType) !== 0 &&
transaction.tokenId === ZERO &&
Number(transaction.value) === 0) ||
BigInt(transaction.value) === 0n) ||
transaction.ercAddress === ZERO ||
transaction.recipientAddress === ZERO ||
transaction.commitments.some(c => c !== ZERO) ||
Expand Down
Loading