From 0ef979a17b46b386e49d877dde7a07ef6b4ca8d8 Mon Sep 17 00:00:00 2001 From: Richard Holland Date: Tue, 20 Dec 2022 10:55:28 +0000 Subject: [PATCH] change HookOn to uint256 --- src/ripple/app/hook/Enum.h | 262 +++++++++++++++++++++++++ src/ripple/app/hook/applyHook.h | 2 +- src/ripple/app/hook/impl/applyHook.cpp | 11 +- src/ripple/app/tx/impl/SetHook.cpp | 22 +-- src/ripple/app/tx/impl/Transactor.cpp | 12 +- src/ripple/protocol/SField.h | 2 +- src/ripple/protocol/impl/SField.cpp | 4 +- src/test/app/SetHook_test.cpp | 23 +-- src/test/jtx/hook.h | 2 - src/test/jtx/impl/hook.cpp | 23 +-- 10 files changed, 303 insertions(+), 60 deletions(-) diff --git a/src/ripple/app/hook/Enum.h b/src/ripple/app/hook/Enum.h index 7232a8ed0..718639add 100644 --- a/src/ripple/app/hook/Enum.h +++ b/src/ripple/app/hook/Enum.h @@ -240,6 +240,268 @@ namespace hook_api const double fee_base_multiplier = 1.1f; + // RH TODO: there's definitely a mucher nicer way to do this, but it involves modifying the base_uint + // class and we don't want to do that yet. + static const std::array UINT256_BIT = + { + ripple::uint256("0000000000000000000000000000000000000000000000000000000000000001"), + ripple::uint256("0000000000000000000000000000000000000000000000000000000000000002"), + ripple::uint256("0000000000000000000000000000000000000000000000000000000000000004"), + ripple::uint256("0000000000000000000000000000000000000000000000000000000000000008"), + ripple::uint256("0000000000000000000000000000000000000000000000000000000000000010"), + ripple::uint256("0000000000000000000000000000000000000000000000000000000000000020"), + ripple::uint256("0000000000000000000000000000000000000000000000000000000000000040"), + ripple::uint256("0000000000000000000000000000000000000000000000000000000000000080"), + ripple::uint256("0000000000000000000000000000000000000000000000000000000000000100"), + ripple::uint256("0000000000000000000000000000000000000000000000000000000000000200"), + ripple::uint256("0000000000000000000000000000000000000000000000000000000000000400"), + ripple::uint256("0000000000000000000000000000000000000000000000000000000000000800"), + ripple::uint256("0000000000000000000000000000000000000000000000000000000000001000"), + ripple::uint256("0000000000000000000000000000000000000000000000000000000000002000"), + ripple::uint256("0000000000000000000000000000000000000000000000000000000000004000"), + ripple::uint256("0000000000000000000000000000000000000000000000000000000000008000"), + ripple::uint256("0000000000000000000000000000000000000000000000000000000000010000"), + ripple::uint256("0000000000000000000000000000000000000000000000000000000000020000"), + ripple::uint256("0000000000000000000000000000000000000000000000000000000000040000"), + ripple::uint256("0000000000000000000000000000000000000000000000000000000000080000"), + ripple::uint256("0000000000000000000000000000000000000000000000000000000000100000"), + ripple::uint256("0000000000000000000000000000000000000000000000000000000000200000"), + ripple::uint256("0000000000000000000000000000000000000000000000000000000000400000"), + ripple::uint256("0000000000000000000000000000000000000000000000000000000000800000"), + ripple::uint256("0000000000000000000000000000000000000000000000000000000001000000"), + ripple::uint256("0000000000000000000000000000000000000000000000000000000002000000"), + ripple::uint256("0000000000000000000000000000000000000000000000000000000004000000"), + ripple::uint256("0000000000000000000000000000000000000000000000000000000008000000"), + ripple::uint256("0000000000000000000000000000000000000000000000000000000010000000"), + ripple::uint256("0000000000000000000000000000000000000000000000000000000020000000"), + ripple::uint256("0000000000000000000000000000000000000000000000000000000040000000"), + ripple::uint256("0000000000000000000000000000000000000000000000000000000080000000"), + ripple::uint256("0000000000000000000000000000000000000000000000000000000100000000"), + ripple::uint256("0000000000000000000000000000000000000000000000000000000200000000"), + ripple::uint256("0000000000000000000000000000000000000000000000000000000400000000"), + ripple::uint256("0000000000000000000000000000000000000000000000000000000800000000"), + ripple::uint256("0000000000000000000000000000000000000000000000000000001000000000"), + ripple::uint256("0000000000000000000000000000000000000000000000000000002000000000"), + ripple::uint256("0000000000000000000000000000000000000000000000000000004000000000"), + ripple::uint256("0000000000000000000000000000000000000000000000000000008000000000"), + ripple::uint256("0000000000000000000000000000000000000000000000000000010000000000"), + ripple::uint256("0000000000000000000000000000000000000000000000000000020000000000"), + ripple::uint256("0000000000000000000000000000000000000000000000000000040000000000"), + ripple::uint256("0000000000000000000000000000000000000000000000000000080000000000"), + ripple::uint256("0000000000000000000000000000000000000000000000000000100000000000"), + ripple::uint256("0000000000000000000000000000000000000000000000000000200000000000"), + ripple::uint256("0000000000000000000000000000000000000000000000000000400000000000"), + ripple::uint256("0000000000000000000000000000000000000000000000000000800000000000"), + ripple::uint256("0000000000000000000000000000000000000000000000000001000000000000"), + ripple::uint256("0000000000000000000000000000000000000000000000000002000000000000"), + ripple::uint256("0000000000000000000000000000000000000000000000000004000000000000"), + ripple::uint256("0000000000000000000000000000000000000000000000000008000000000000"), + ripple::uint256("0000000000000000000000000000000000000000000000000010000000000000"), + ripple::uint256("0000000000000000000000000000000000000000000000000020000000000000"), + ripple::uint256("0000000000000000000000000000000000000000000000000040000000000000"), + ripple::uint256("0000000000000000000000000000000000000000000000000080000000000000"), + ripple::uint256("0000000000000000000000000000000000000000000000000100000000000000"), + ripple::uint256("0000000000000000000000000000000000000000000000000200000000000000"), + ripple::uint256("0000000000000000000000000000000000000000000000000400000000000000"), + ripple::uint256("0000000000000000000000000000000000000000000000000800000000000000"), + ripple::uint256("0000000000000000000000000000000000000000000000001000000000000000"), + ripple::uint256("0000000000000000000000000000000000000000000000002000000000000000"), + ripple::uint256("0000000000000000000000000000000000000000000000004000000000000000"), + ripple::uint256("0000000000000000000000000000000000000000000000008000000000000000"), + ripple::uint256("0000000000000000000000000000000000000000000000010000000000000000"), + ripple::uint256("0000000000000000000000000000000000000000000000020000000000000000"), + ripple::uint256("0000000000000000000000000000000000000000000000040000000000000000"), + ripple::uint256("0000000000000000000000000000000000000000000000080000000000000000"), + ripple::uint256("0000000000000000000000000000000000000000000000100000000000000000"), + ripple::uint256("0000000000000000000000000000000000000000000000200000000000000000"), + ripple::uint256("0000000000000000000000000000000000000000000000400000000000000000"), + ripple::uint256("0000000000000000000000000000000000000000000000800000000000000000"), + ripple::uint256("0000000000000000000000000000000000000000000001000000000000000000"), + ripple::uint256("0000000000000000000000000000000000000000000002000000000000000000"), + ripple::uint256("0000000000000000000000000000000000000000000004000000000000000000"), + ripple::uint256("0000000000000000000000000000000000000000000008000000000000000000"), + ripple::uint256("0000000000000000000000000000000000000000000010000000000000000000"), + ripple::uint256("0000000000000000000000000000000000000000000020000000000000000000"), + ripple::uint256("0000000000000000000000000000000000000000000040000000000000000000"), + ripple::uint256("0000000000000000000000000000000000000000000080000000000000000000"), + ripple::uint256("0000000000000000000000000000000000000000000100000000000000000000"), + ripple::uint256("0000000000000000000000000000000000000000000200000000000000000000"), + ripple::uint256("0000000000000000000000000000000000000000000400000000000000000000"), + ripple::uint256("0000000000000000000000000000000000000000000800000000000000000000"), + ripple::uint256("0000000000000000000000000000000000000000001000000000000000000000"), + ripple::uint256("0000000000000000000000000000000000000000002000000000000000000000"), + ripple::uint256("0000000000000000000000000000000000000000004000000000000000000000"), + ripple::uint256("0000000000000000000000000000000000000000008000000000000000000000"), + ripple::uint256("0000000000000000000000000000000000000000010000000000000000000000"), + ripple::uint256("0000000000000000000000000000000000000000020000000000000000000000"), + ripple::uint256("0000000000000000000000000000000000000000040000000000000000000000"), + ripple::uint256("0000000000000000000000000000000000000000080000000000000000000000"), + ripple::uint256("0000000000000000000000000000000000000000100000000000000000000000"), + ripple::uint256("0000000000000000000000000000000000000000200000000000000000000000"), + ripple::uint256("0000000000000000000000000000000000000000400000000000000000000000"), + ripple::uint256("0000000000000000000000000000000000000000800000000000000000000000"), + ripple::uint256("0000000000000000000000000000000000000001000000000000000000000000"), + ripple::uint256("0000000000000000000000000000000000000002000000000000000000000000"), + ripple::uint256("0000000000000000000000000000000000000004000000000000000000000000"), + ripple::uint256("0000000000000000000000000000000000000008000000000000000000000000"), + ripple::uint256("0000000000000000000000000000000000000010000000000000000000000000"), + ripple::uint256("0000000000000000000000000000000000000020000000000000000000000000"), + ripple::uint256("0000000000000000000000000000000000000040000000000000000000000000"), + ripple::uint256("0000000000000000000000000000000000000080000000000000000000000000"), + ripple::uint256("0000000000000000000000000000000000000100000000000000000000000000"), + ripple::uint256("0000000000000000000000000000000000000200000000000000000000000000"), + ripple::uint256("0000000000000000000000000000000000000400000000000000000000000000"), + ripple::uint256("0000000000000000000000000000000000000800000000000000000000000000"), + ripple::uint256("0000000000000000000000000000000000001000000000000000000000000000"), + ripple::uint256("0000000000000000000000000000000000002000000000000000000000000000"), + ripple::uint256("0000000000000000000000000000000000004000000000000000000000000000"), + ripple::uint256("0000000000000000000000000000000000008000000000000000000000000000"), + ripple::uint256("0000000000000000000000000000000000010000000000000000000000000000"), + ripple::uint256("0000000000000000000000000000000000020000000000000000000000000000"), + ripple::uint256("0000000000000000000000000000000000040000000000000000000000000000"), + ripple::uint256("0000000000000000000000000000000000080000000000000000000000000000"), + ripple::uint256("0000000000000000000000000000000000100000000000000000000000000000"), + ripple::uint256("0000000000000000000000000000000000200000000000000000000000000000"), + ripple::uint256("0000000000000000000000000000000000400000000000000000000000000000"), + ripple::uint256("0000000000000000000000000000000000800000000000000000000000000000"), + ripple::uint256("0000000000000000000000000000000001000000000000000000000000000000"), + ripple::uint256("0000000000000000000000000000000002000000000000000000000000000000"), + ripple::uint256("0000000000000000000000000000000004000000000000000000000000000000"), + ripple::uint256("0000000000000000000000000000000008000000000000000000000000000000"), + ripple::uint256("0000000000000000000000000000000010000000000000000000000000000000"), + ripple::uint256("0000000000000000000000000000000020000000000000000000000000000000"), + ripple::uint256("0000000000000000000000000000000040000000000000000000000000000000"), + ripple::uint256("0000000000000000000000000000000080000000000000000000000000000000"), + ripple::uint256("0000000000000000000000000000000100000000000000000000000000000000"), + ripple::uint256("0000000000000000000000000000000200000000000000000000000000000000"), + ripple::uint256("0000000000000000000000000000000400000000000000000000000000000000"), + ripple::uint256("0000000000000000000000000000000800000000000000000000000000000000"), + ripple::uint256("0000000000000000000000000000001000000000000000000000000000000000"), + ripple::uint256("0000000000000000000000000000002000000000000000000000000000000000"), + ripple::uint256("0000000000000000000000000000004000000000000000000000000000000000"), + ripple::uint256("0000000000000000000000000000008000000000000000000000000000000000"), + ripple::uint256("0000000000000000000000000000010000000000000000000000000000000000"), + ripple::uint256("0000000000000000000000000000020000000000000000000000000000000000"), + ripple::uint256("0000000000000000000000000000040000000000000000000000000000000000"), + ripple::uint256("0000000000000000000000000000080000000000000000000000000000000000"), + ripple::uint256("0000000000000000000000000000100000000000000000000000000000000000"), + ripple::uint256("0000000000000000000000000000200000000000000000000000000000000000"), + ripple::uint256("0000000000000000000000000000400000000000000000000000000000000000"), + ripple::uint256("0000000000000000000000000000800000000000000000000000000000000000"), + ripple::uint256("0000000000000000000000000001000000000000000000000000000000000000"), + ripple::uint256("0000000000000000000000000002000000000000000000000000000000000000"), + ripple::uint256("0000000000000000000000000004000000000000000000000000000000000000"), + ripple::uint256("0000000000000000000000000008000000000000000000000000000000000000"), + ripple::uint256("0000000000000000000000000010000000000000000000000000000000000000"), + ripple::uint256("0000000000000000000000000020000000000000000000000000000000000000"), + ripple::uint256("0000000000000000000000000040000000000000000000000000000000000000"), + ripple::uint256("0000000000000000000000000080000000000000000000000000000000000000"), + ripple::uint256("0000000000000000000000000100000000000000000000000000000000000000"), + ripple::uint256("0000000000000000000000000200000000000000000000000000000000000000"), + ripple::uint256("0000000000000000000000000400000000000000000000000000000000000000"), + ripple::uint256("0000000000000000000000000800000000000000000000000000000000000000"), + ripple::uint256("0000000000000000000000001000000000000000000000000000000000000000"), + ripple::uint256("0000000000000000000000002000000000000000000000000000000000000000"), + ripple::uint256("0000000000000000000000004000000000000000000000000000000000000000"), + ripple::uint256("0000000000000000000000008000000000000000000000000000000000000000"), + ripple::uint256("0000000000000000000000010000000000000000000000000000000000000000"), + ripple::uint256("0000000000000000000000020000000000000000000000000000000000000000"), + ripple::uint256("0000000000000000000000040000000000000000000000000000000000000000"), + ripple::uint256("0000000000000000000000080000000000000000000000000000000000000000"), + ripple::uint256("0000000000000000000000100000000000000000000000000000000000000000"), + ripple::uint256("0000000000000000000000200000000000000000000000000000000000000000"), + ripple::uint256("0000000000000000000000400000000000000000000000000000000000000000"), + ripple::uint256("0000000000000000000000800000000000000000000000000000000000000000"), + ripple::uint256("0000000000000000000001000000000000000000000000000000000000000000"), + ripple::uint256("0000000000000000000002000000000000000000000000000000000000000000"), + ripple::uint256("0000000000000000000004000000000000000000000000000000000000000000"), + ripple::uint256("0000000000000000000008000000000000000000000000000000000000000000"), + ripple::uint256("0000000000000000000010000000000000000000000000000000000000000000"), + ripple::uint256("0000000000000000000020000000000000000000000000000000000000000000"), + ripple::uint256("0000000000000000000040000000000000000000000000000000000000000000"), + ripple::uint256("0000000000000000000080000000000000000000000000000000000000000000"), + ripple::uint256("0000000000000000000100000000000000000000000000000000000000000000"), + ripple::uint256("0000000000000000000200000000000000000000000000000000000000000000"), + ripple::uint256("0000000000000000000400000000000000000000000000000000000000000000"), + ripple::uint256("0000000000000000000800000000000000000000000000000000000000000000"), + ripple::uint256("0000000000000000001000000000000000000000000000000000000000000000"), + ripple::uint256("0000000000000000002000000000000000000000000000000000000000000000"), + ripple::uint256("0000000000000000004000000000000000000000000000000000000000000000"), + ripple::uint256("0000000000000000008000000000000000000000000000000000000000000000"), + ripple::uint256("0000000000000000010000000000000000000000000000000000000000000000"), + ripple::uint256("0000000000000000020000000000000000000000000000000000000000000000"), + ripple::uint256("0000000000000000040000000000000000000000000000000000000000000000"), + ripple::uint256("0000000000000000080000000000000000000000000000000000000000000000"), + ripple::uint256("0000000000000000100000000000000000000000000000000000000000000000"), + ripple::uint256("0000000000000000200000000000000000000000000000000000000000000000"), + ripple::uint256("0000000000000000400000000000000000000000000000000000000000000000"), + ripple::uint256("0000000000000000800000000000000000000000000000000000000000000000"), + ripple::uint256("0000000000000001000000000000000000000000000000000000000000000000"), + ripple::uint256("0000000000000002000000000000000000000000000000000000000000000000"), + ripple::uint256("0000000000000004000000000000000000000000000000000000000000000000"), + ripple::uint256("0000000000000008000000000000000000000000000000000000000000000000"), + ripple::uint256("0000000000000010000000000000000000000000000000000000000000000000"), + ripple::uint256("0000000000000020000000000000000000000000000000000000000000000000"), + ripple::uint256("0000000000000040000000000000000000000000000000000000000000000000"), + ripple::uint256("0000000000000080000000000000000000000000000000000000000000000000"), + ripple::uint256("0000000000000100000000000000000000000000000000000000000000000000"), + ripple::uint256("0000000000000200000000000000000000000000000000000000000000000000"), + ripple::uint256("0000000000000400000000000000000000000000000000000000000000000000"), + ripple::uint256("0000000000000800000000000000000000000000000000000000000000000000"), + ripple::uint256("0000000000001000000000000000000000000000000000000000000000000000"), + ripple::uint256("0000000000002000000000000000000000000000000000000000000000000000"), + ripple::uint256("0000000000004000000000000000000000000000000000000000000000000000"), + ripple::uint256("0000000000008000000000000000000000000000000000000000000000000000"), + ripple::uint256("0000000000010000000000000000000000000000000000000000000000000000"), + ripple::uint256("0000000000020000000000000000000000000000000000000000000000000000"), + ripple::uint256("0000000000040000000000000000000000000000000000000000000000000000"), + ripple::uint256("0000000000080000000000000000000000000000000000000000000000000000"), + ripple::uint256("0000000000100000000000000000000000000000000000000000000000000000"), + ripple::uint256("0000000000200000000000000000000000000000000000000000000000000000"), + ripple::uint256("0000000000400000000000000000000000000000000000000000000000000000"), + ripple::uint256("0000000000800000000000000000000000000000000000000000000000000000"), + ripple::uint256("0000000001000000000000000000000000000000000000000000000000000000"), + ripple::uint256("0000000002000000000000000000000000000000000000000000000000000000"), + ripple::uint256("0000000004000000000000000000000000000000000000000000000000000000"), + ripple::uint256("0000000008000000000000000000000000000000000000000000000000000000"), + ripple::uint256("0000000010000000000000000000000000000000000000000000000000000000"), + ripple::uint256("0000000020000000000000000000000000000000000000000000000000000000"), + ripple::uint256("0000000040000000000000000000000000000000000000000000000000000000"), + ripple::uint256("0000000080000000000000000000000000000000000000000000000000000000"), + ripple::uint256("0000000100000000000000000000000000000000000000000000000000000000"), + ripple::uint256("0000000200000000000000000000000000000000000000000000000000000000"), + ripple::uint256("0000000400000000000000000000000000000000000000000000000000000000"), + ripple::uint256("0000000800000000000000000000000000000000000000000000000000000000"), + ripple::uint256("0000001000000000000000000000000000000000000000000000000000000000"), + ripple::uint256("0000002000000000000000000000000000000000000000000000000000000000"), + ripple::uint256("0000004000000000000000000000000000000000000000000000000000000000"), + ripple::uint256("0000008000000000000000000000000000000000000000000000000000000000"), + ripple::uint256("0000010000000000000000000000000000000000000000000000000000000000"), + ripple::uint256("0000020000000000000000000000000000000000000000000000000000000000"), + ripple::uint256("0000040000000000000000000000000000000000000000000000000000000000"), + ripple::uint256("0000080000000000000000000000000000000000000000000000000000000000"), + ripple::uint256("0000100000000000000000000000000000000000000000000000000000000000"), + ripple::uint256("0000200000000000000000000000000000000000000000000000000000000000"), + ripple::uint256("0000400000000000000000000000000000000000000000000000000000000000"), + ripple::uint256("0000800000000000000000000000000000000000000000000000000000000000"), + ripple::uint256("0001000000000000000000000000000000000000000000000000000000000000"), + ripple::uint256("0002000000000000000000000000000000000000000000000000000000000000"), + ripple::uint256("0004000000000000000000000000000000000000000000000000000000000000"), + ripple::uint256("0008000000000000000000000000000000000000000000000000000000000000"), + ripple::uint256("0010000000000000000000000000000000000000000000000000000000000000"), + ripple::uint256("0020000000000000000000000000000000000000000000000000000000000000"), + ripple::uint256("0040000000000000000000000000000000000000000000000000000000000000"), + ripple::uint256("0080000000000000000000000000000000000000000000000000000000000000"), + ripple::uint256("0100000000000000000000000000000000000000000000000000000000000000"), + ripple::uint256("0200000000000000000000000000000000000000000000000000000000000000"), + ripple::uint256("0400000000000000000000000000000000000000000000000000000000000000"), + ripple::uint256("0800000000000000000000000000000000000000000000000000000000000000"), + ripple::uint256("1000000000000000000000000000000000000000000000000000000000000000"), + ripple::uint256("2000000000000000000000000000000000000000000000000000000000000000"), + ripple::uint256("4000000000000000000000000000000000000000000000000000000000000000"), + ripple::uint256("8000000000000000000000000000000000000000000000000000000000000000") + }; + // RH NOTE: Find descriptions of api functions in ./impl/applyHook.cpp and hookapi.h (include for hooks) static const std::set import_whitelist { diff --git a/src/ripple/app/hook/applyHook.h b/src/ripple/app/hook/applyHook.h index c8ea5b478..5ae1086c3 100644 --- a/src/ripple/app/hook/applyHook.h +++ b/src/ripple/app/hook/applyHook.h @@ -223,7 +223,7 @@ namespace hook_api namespace hook { - bool canHook(ripple::TxType txType, uint64_t hookOn); + bool canHook(ripple::TxType txType, ripple::uint256 hookOn); struct HookResult; diff --git a/src/ripple/app/hook/impl/applyHook.cpp b/src/ripple/app/hook/impl/applyHook.cpp index fc92b2ba9..106308cb3 100644 --- a/src/ripple/app/hook/impl/applyHook.cpp +++ b/src/ripple/app/hook/impl/applyHook.cpp @@ -748,12 +748,15 @@ hook::removeHookNamespaceEntry( // from the right is 0 then the hook will trigger on ESCROW_FINISH. If it is 1 then ESCROW_FINISH will not trigger // the hook. However ttHOOK_SET = 22 is active high, so by default (HookOn == 0) ttHOOK_SET is not triggered by // transactions. If you wish to set a hook that has control over ttHOOK_SET then set bit 1U<<22. -bool hook::canHook(ripple::TxType txType, uint64_t hookOn) { +bool hook::canHook(ripple::TxType txType, ripple::uint256 hookOn) { + // invert ttHOOK_SET bit - hookOn ^= (1ULL << ttHOOK_SET); + hookOn ^= UINT256_BIT[ttHOOK_SET]; + // invert entire field - hookOn ^= 0xFFFFFFFFFFFFFFFFULL; - return (hookOn >> txType) & 1; + hookOn = ~hookOn; + + return (hookOn & UINT256_BIT[txType]) != beast::zero; } diff --git a/src/ripple/app/tx/impl/SetHook.cpp b/src/ripple/app/tx/impl/SetHook.cpp index ff76a177c..497ef468d 100644 --- a/src/ripple/app/tx/impl/SetHook.cpp +++ b/src/ripple/app/tx/impl/SetHook.cpp @@ -1150,9 +1150,9 @@ SetHook::setHook() std::optional newNamespace; std::optional newDirKeylet; - std::optional oldHookOn; - std::optional newHookOn; - std::optional defHookOn; + std::optional oldHookOn; + std::optional newHookOn; + std::optional defHookOn; // when hsoCREATE is invoked it populates this variable in case the hook definition already exists // and the operation falls through into a hsoINSTALL operation instead @@ -1205,10 +1205,10 @@ SetHook::setHook() oldDirKeylet = keylet::hookStateDir(account_, *oldNamespace); oldDirSLE = view().peek(*oldDirKeylet); if (oldDefSLE) - defHookOn = oldDefSLE->getFieldU64(sfHookOn); + defHookOn = oldDefSLE->getFieldH256(sfHookOn); if (oldHook->get().isFieldPresent(sfHookOn)) - oldHookOn = oldHook->get().getFieldU64(sfHookOn); + oldHookOn = oldHook->get().getFieldH256(sfHookOn); else if (defHookOn) oldHookOn = *defHookOn; } @@ -1223,7 +1223,7 @@ SetHook::setHook() } if (hookSetObj->get().isFieldPresent(sfHookOn)) - newHookOn = hookSetObj->get().getFieldU64(sfHookOn); + newHookOn = hookSetObj->get().getFieldH256(sfHookOn); if (hookSetObj->get().isFieldPresent(sfHookNamespace)) { @@ -1322,7 +1322,7 @@ SetHook::setHook() // initially carry over the prior non-array values, whatever those were newHook.setFieldH256(sfHookHash, oldHook->get().getFieldH256(sfHookHash)); if (oldHook->get().isFieldPresent(sfHookOn)) - newHook.setFieldU64(sfHookOn, oldHook->get().getFieldU64(sfHookOn)); + newHook.setFieldH256(sfHookOn, oldHook->get().getFieldH256(sfHookOn)); if (oldHook->get().isFieldPresent(sfHookNamespace)) newHook.setFieldH256(sfHookNamespace, oldHook->get().getFieldH256(sfHookNamespace)); @@ -1347,7 +1347,7 @@ SetHook::setHook() newHook.makeFieldAbsent(sfHookOn); } else - newHook.setFieldU64(sfHookOn, *newHookOn); + newHook.setFieldH256(sfHookOn, *newHookOn); } // parameters @@ -1488,7 +1488,7 @@ SetHook::setHook() auto newHookDef = std::make_shared( keylet ); newHookDef->setFieldH256(sfHookHash, *createHookHash); - newHookDef->setFieldU64( sfHookOn, *newHookOn); + newHookDef->setFieldH256( sfHookOn, *newHookOn); newHookDef->setFieldH256( sfHookNamespace, *newNamespace); newHookDef->setFieldArray( sfHookParameters, hookSetObj->get().isFieldPresent(sfHookParameters) @@ -1566,7 +1566,7 @@ SetHook::setHook() // change which definition we're using to the new target defNamespace = newDefSLE->getFieldH256(sfHookNamespace); - defHookOn = newDefSLE->getFieldU64(sfHookOn); + defHookOn = newDefSLE->getFieldH256(sfHookOn); // set the namespace if it differs from the definition namespace if (newNamespace && *defNamespace != *newNamespace) @@ -1574,7 +1574,7 @@ SetHook::setHook() // set the hookon field if it differs from definition if (newHookOn && *defHookOn != *newHookOn) - newHook.setFieldU64(sfHookOn, *newHookOn); + newHook.setFieldH256(sfHookOn, *newHookOn); // parameters TER result = diff --git a/src/ripple/app/tx/impl/Transactor.cpp b/src/ripple/app/tx/impl/Transactor.cpp index 88474bc58..973b8cce0 100644 --- a/src/ripple/app/tx/impl/Transactor.cpp +++ b/src/ripple/app/tx/impl/Transactor.cpp @@ -211,9 +211,9 @@ calculateHookChainFee( } // check if the hook can fire - uint64_t hookOn = (hookObj->isFieldPresent(sfHookOn) - ? hookObj->getFieldU64(sfHookOn) - : hookDef->getFieldU64(sfHookOn)); + uint256 hookOn = (hookObj->isFieldPresent(sfHookOn) + ? hookObj->getFieldH256(sfHookOn) + : hookDef->getFieldH256(sfHookOn)); uint32_t flags = 0; if (hookObj->isFieldPresent(sfFlags)) @@ -990,9 +990,9 @@ executeHookChain( } // check if the hook can fire - uint64_t hookOn = (hookObj->isFieldPresent(sfHookOn) - ? hookObj->getFieldU64(sfHookOn) - : hookDef->getFieldU64(sfHookOn)); + uint256 hookOn = (hookObj->isFieldPresent(sfHookOn) + ? hookObj->getFieldH256(sfHookOn) + : hookDef->getFieldH256(sfHookOn)); if (!hook::canHook(ctx_.tx.getTxnType(), hookOn)) continue; // skip if it can't diff --git a/src/ripple/protocol/SField.h b/src/ripple/protocol/SField.h index 5e35c8b0f..79b81382c 100644 --- a/src/ripple/protocol/SField.h +++ b/src/ripple/protocol/SField.h @@ -422,7 +422,6 @@ extern SF_UINT64 const sfEmitBurden; extern SF_UINT64 const sfNFTokenOfferNode; // 64-bit integers (uncommon) -extern SF_UINT64 const sfHookOn; extern SF_UINT64 const sfHookInstructionCount; extern SF_UINT64 const sfHookReturnCode; extern SF_UINT64 const sfReferenceCount; @@ -442,6 +441,7 @@ extern SF_UINT256 const sfLedgerHash; extern SF_UINT256 const sfParentHash; extern SF_UINT256 const sfTransactionHash; extern SF_UINT256 const sfAccountHash; +extern SF_UINT256 const sfHookOn; extern SF_UINT256 const sfPreviousTxnID; extern SF_UINT256 const sfLedgerIndex; extern SF_UINT256 const sfWalletLocator; diff --git a/src/ripple/protocol/impl/SField.cpp b/src/ripple/protocol/impl/SField.cpp index 88d68a253..fcbe37d81 100644 --- a/src/ripple/protocol/impl/SField.cpp +++ b/src/ripple/protocol/impl/SField.cpp @@ -173,7 +173,7 @@ CONSTRUCT_TYPED_SFIELD(sfNFTokenOfferNode, "NFTokenOfferNode", UINT64, CONSTRUCT_TYPED_SFIELD(sfEmitBurden, "EmitBurden", UINT64, 13); // 64-bit integers (uncommon) -CONSTRUCT_TYPED_SFIELD(sfHookOn, "HookOn", UINT64, 16); +// 16 used to be HookOn until it was expanded to UINT256 CONSTRUCT_TYPED_SFIELD(sfHookInstructionCount, "HookInstructionCount", UINT64, 17); CONSTRUCT_TYPED_SFIELD(sfHookReturnCode, "HookReturnCode", UINT64, 18); CONSTRUCT_TYPED_SFIELD(sfReferenceCount, "ReferenceCount", UINT64, 19); @@ -208,7 +208,7 @@ CONSTRUCT_TYPED_SFIELD(sfBookDirectory, "BookDirectory", UINT256, CONSTRUCT_TYPED_SFIELD(sfInvoiceID, "InvoiceID", UINT256, 17); CONSTRUCT_TYPED_SFIELD(sfNickname, "Nickname", UINT256, 18); CONSTRUCT_TYPED_SFIELD(sfAmendment, "Amendment", UINT256, 19); -// 20 is currently unused +CONSTRUCT_TYPED_SFIELD(sfHookOn, "HookOn", UINT256, 20); CONSTRUCT_TYPED_SFIELD(sfDigest, "Digest", UINT256, 21); CONSTRUCT_TYPED_SFIELD(sfChannel, "Channel", UINT256, 22); CONSTRUCT_TYPED_SFIELD(sfConsensusHash, "ConsensusHash", UINT256, 23); diff --git a/src/test/app/SetHook_test.cpp b/src/test/app/SetHook_test.cpp index ea1b85ae5..d0a60bb90 100644 --- a/src/test/app/SetHook_test.cpp +++ b/src/test/app/SetHook_test.cpp @@ -16,6 +16,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ //============================================================================== +#include #include #include #include @@ -470,7 +471,7 @@ public: for (auto const& [key, value] : JSSMap{ {jss::HookGrants, Json::arrayValue}, {jss::HookParameters, Json::arrayValue}, - {jss::HookOn, "0"}, + {jss::HookOn, "0000000000000000000000000000000000000000000000000000000000000000"}, {jss::HookApiVersion, "0"}, {jss::HookNamespace, to_string(uint256{beast::zero})}}) { @@ -631,7 +632,7 @@ public: for (auto const& [key, value] : JSSMap{ {jss::HookGrants, Json::arrayValue}, {jss::HookParameters, Json::arrayValue}, - {jss::HookOn, "0"}, + {jss::HookOn, "0000000000000000000000000000000000000000000000000000000000000000"}, {jss::HookApiVersion, "0"}, }) { @@ -773,7 +774,7 @@ public: Json::Value iv; iv[jss::CreateCode] = strHex(accept_wasm); iv[jss::HookApiVersion] = 0U; - iv[jss::HookOn] = uint64_hex(0); + iv[jss::HookOn] = "0000000000000000000000000000000000000000000000000000000000000000"; jv[jss::Hooks][0U] = Json::Value{}; jv[jss::Hooks][0U][jss::Hook] = iv; @@ -789,7 +790,7 @@ public: Json::Value iv; iv[jss::CreateCode] = strHex(accept_wasm); iv[jss::HookNamespace] = to_string(uint256{beast::zero}); - iv[jss::HookOn] = uint64_hex(0); + iv[jss::HookOn] = "0000000000000000000000000000000000000000000000000000000000000000"; jv[jss::Hooks][0U] = Json::Value{}; jv[jss::Hooks][0U][jss::Hook] = iv; @@ -806,7 +807,7 @@ public: iv[jss::CreateCode] = strHex(accept_wasm); iv[jss::HookNamespace] = to_string(uint256{beast::zero}); iv[jss::HookApiVersion] = 1U; - iv[jss::HookOn] = uint64_hex(0); + iv[jss::HookOn] = "0000000000000000000000000000000000000000000000000000000000000000"; jv[jss::Hooks][0U] = Json::Value{}; jv[jss::Hooks][0U][jss::Hook] = iv; @@ -987,7 +988,7 @@ public: iv[jss::CreateCode] = strHex(accept_wasm); iv[jss::HookNamespace] = to_string(uint256{beast::zero}); iv[jss::HookApiVersion] = 0U; - iv[jss::HookOn] = uint64_hex(0); + iv[jss::HookOn] = "0000000000000000000000000000000000000000000000000000000000000000"; iv[jss::HookParameters] = Json::Value{Json::arrayValue}; iv[jss::HookParameters][0U] = Json::Value{}; iv[jss::HookParameters][0U][jss::HookParameter] = Json::Value{}; @@ -1066,7 +1067,7 @@ public: grants[0U][jss::HookGrant][jss::HookHash] = accept_hash_str; for (auto const& [key, value] : JSSMap{ - {jss::HookOn, "1"}, + {jss::HookOn, "0000000000000000000000000000000000000000000000000000000000000001"}, {jss::HookNamespace, "CAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFE" "CAFECAFE"}, @@ -1093,7 +1094,7 @@ public: // check all fields were updated to correct values BEAST_REQUIRE(hooks[0].isFieldPresent(sfHookOn)); - BEAST_EXPECT(hooks[0].getFieldU64(sfHookOn) == 1ULL); + BEAST_EXPECT(hooks[0].getFieldH256(sfHookOn) == hook_api::UINT256_BIT[0]); auto const ns = uint256::fromVoid( (std::array{ @@ -1129,7 +1130,7 @@ public: // reset hookon and namespace to defaults { for (auto const& [key, value] : JSSMap{ - {jss::HookOn, "0"}, + {jss::HookOn, "0000000000000000000000000000000000000000000000000000000000000000"}, {jss::HookNamespace, to_string(uint256{beast::zero})}}) { Json::Value iv; @@ -1369,7 +1370,7 @@ public: grants[0U][jss::HookGrant][jss::HookHash] = accept_hash_str; for (auto const& [key, value] : JSSMap{ - {jss::HookOn, "1"}, + {jss::HookOn, "0000000000000000000000000000000000000000000000000000000000000001"}, {jss::HookNamespace, "CAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFE" "CAFECAFE"}, @@ -1571,7 +1572,7 @@ public: // hsoUPDATE { STObject hso{sfHook}; - hso.setFieldU64(sfHookOn, 1LLU); + hso.setFieldH256(sfHookOn, hook_api::UINT256_BIT[0]); BEAST_EXPECT(SetHook::inferOperation(hso) == hsoUPDATE); } diff --git a/src/test/jtx/hook.h b/src/test/jtx/hook.h index f83713f30..62e454f36 100644 --- a/src/test/jtx/hook.h +++ b/src/test/jtx/hook.h @@ -37,8 +37,6 @@ hso(std::vector const& wasmBytes, void (*f)(Json::Value& jv) = 0); Json::Value hso_delete(void (*f)(Json::Value& jv) = 0); -std::string uint64_hex(uint64_t x); - } // namespace jtx } // namespace test } // namespace ripple diff --git a/src/test/jtx/impl/hook.cpp b/src/test/jtx/impl/hook.cpp index 51fb2260c..2807cf5dc 100644 --- a/src/test/jtx/impl/hook.cpp +++ b/src/test/jtx/impl/hook.cpp @@ -45,27 +45,6 @@ hook(Account const& account, std::optional> hooks, std: return jv; } - -std::string uint64_hex(uint64_t x) -{ - auto const nibble = [](uint64_t n) -> char - { - n &= 0x0FU; - return - n <= 9 ? '0' + n : - 'A' + (n - 10); - }; - return std::string("") + - nibble(x >> 60U) + nibble(x >> 56U) + - nibble(x >> 52U) + nibble(x >> 48U) + - nibble(x >> 44U) + nibble(x >> 40U) + - nibble(x >> 36U) + nibble(x >> 32U) + - nibble(x >> 28U) + nibble(x >> 24U) + - nibble(x >> 20U) + nibble(x >> 16U) + - nibble(x >> 12U) + nibble(x >> 8U) + - nibble(x >> 4U) + nibble(x >> 0U); -} - Json::Value hso_delete(void (*f)(Json::Value& jv)) { @@ -89,7 +68,7 @@ hso(std::vector const& wasmBytes, void (*f)(Json::Value& jv)) Json::Value jv; jv[jss::CreateCode] = strHex(wasmBytes); { - jv[jss::HookOn] = uint64_hex(0); + jv[jss::HookOn] = "0000000000000000000000000000000000000000000000000000000000000000"; jv[jss::HookNamespace] = to_string(uint256{beast::zero}); jv[jss::HookApiVersion] = Json::Value{0}; }