From e4b52cbc3c45f7a43ccd7da686e7105ef9f60b3d Mon Sep 17 00:00:00 2001 From: Andrew Richardson Date: Mon, 16 Sep 2024 09:35:06 -0400 Subject: [PATCH] noto: simplify delegate mapping Signed-off-by: Andrew Richardson --- solidity/contracts/domains/noto/Noto.sol | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/solidity/contracts/domains/noto/Noto.sol b/solidity/contracts/domains/noto/Noto.sol index b49831c24..6cf7455f5 100644 --- a/solidity/contracts/domains/noto/Noto.sol +++ b/solidity/contracts/domains/noto/Noto.sol @@ -23,9 +23,9 @@ import {INoto} from "../interfaces/INoto.sol"; /// be using any model programmable via EVM (not just C-UTXO) /// contract Noto is EIP712Upgradeable, UUPSUpgradeable, INoto { - mapping(bytes32 => bool) private _unspent; - mapping(bytes32 => ApprovalRecord) private _approvals; address _notary; + mapping(bytes32 => bool) private _unspent; + mapping(bytes32 => address) private _approvals; error NotoInvalidNotary(address signer, address notary); error NotoInvalidInput(bytes32 id); @@ -49,10 +49,6 @@ contract Noto is EIP712Upgradeable, UUPSUpgradeable, INoto { bytes32 private constant TRANSFER_TYPEHASH = keccak256("Transfer(bytes32[] inputs,bytes32[] outputs,bytes data)"); - struct ApprovalRecord { - address delegate; - } - function requireNotary(address addr) internal view { if (addr != _notary) { revert NotoNotNotary(addr); @@ -121,7 +117,7 @@ contract Noto is EIP712Upgradeable, UUPSUpgradeable, INoto { function getTransferApproval( bytes32 txhash ) public view returns (address delegate) { - return _approvals[txhash].delegate; + return _approvals[txhash]; } /** @@ -198,7 +194,7 @@ contract Noto is EIP712Upgradeable, UUPSUpgradeable, INoto { bytes32 txhash, bytes calldata signature ) internal { - _approvals[txhash].delegate = delegate; + _approvals[txhash] = delegate; emit UTXOApproved(delegate, txhash, signature); } @@ -218,12 +214,8 @@ contract Noto is EIP712Upgradeable, UUPSUpgradeable, INoto { bytes calldata data ) public { bytes32 txhash = _buildTXHash(inputs, outputs, data); - if (_approvals[txhash].delegate != msg.sender) { - revert NotoInvalidDelegate( - txhash, - _approvals[txhash].delegate, - msg.sender - ); + if (_approvals[txhash] != msg.sender) { + revert NotoInvalidDelegate(txhash, _approvals[txhash], msg.sender); } _transfer(inputs, outputs, signature, data);